Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfluxDB: Query builder produces invalid SQL query when using wildcard column name #88008

Open
NWRichmond opened this issue May 16, 2024 · 2 comments
Assignees
Labels
datasource/InfluxDB good first issue Good for newcomers internal for issues made by grafanistas prio/medium Important over the long term, but may not be staffed and/or may need multiple releases to complete. type/bug

Comments

@NWRichmond
Copy link
Contributor

Problem

When using the InfluxDB data source in SQL mode, the query builder can't run queries with a wildcard column name (SELECT *). Choosing * in the Column select leads to an error:

flightsql: rpc error: code = InvalidArgument desc = Error while planning query: Schema error: No field named "*".

Example query on main demo influxdb sql error when using wildcard column

This happens because we are wrapping all column names in double-quotes and not considering * as a special case:

// wrapping the column name with quotes
const sc = sql.columns.map((c) => ({ ...c, parameters: c.parameters?.map((p) => ({ ...p, name: `"${p.name}"` })) }));

Proposed solution

When the column name is *, do not wrap the column name in double-quotes.

I made this change locally, and everything worked as expected:

function formatTableName(parameter: string | undefined): string {
  if (parameter === '*') {
    return parameter;
  }

  return `"${parameter}"`;
}


export function toRawSql({ sql, table }: SQLQuery): string {
  // ...
  const sc = sql.columns.map((c) => ({
    ...c,
    parameters: c.parameters?.map((p) => ({ ...p, name: formatColumnName(p.name) })),
  }));
  // ...
}
Example query with code change demo solution to influxdb sql error when using wildcard column
@NWRichmond NWRichmond added type/bug datasource/InfluxDB internal for issues made by grafanistas labels May 16, 2024
@itsmylife itsmylife added prio/medium Important over the long term, but may not be staffed and/or may need multiple releases to complete. good first issue Good for newcomers labels May 21, 2024
@itsmylife itsmylife assigned itsmylife and NWRichmond and unassigned itsmylife May 21, 2024
@wasim-nihal
Copy link
Contributor

Is this open for contribution?

@itsmylife
Copy link
Contributor

@wasim-nihal Yes it is. Feel free to contribute and add us as reviewers to your PR. Thank you very much for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datasource/InfluxDB good first issue Good for newcomers internal for issues made by grafanistas prio/medium Important over the long term, but may not be staffed and/or may need multiple releases to complete. type/bug
Projects
None yet
Development

No branches or pull requests

3 participants