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

GROUP BY in InfluxQL should produce a different response structure #25751

Open
hiltontj opened this issue Jan 6, 2025 · 1 comment
Open

GROUP BY in InfluxQL should produce a different response structure #25751

hiltontj opened this issue Jan 6, 2025 · 1 comment
Assignees
Labels

Comments

@hiltontj
Copy link
Contributor

hiltontj commented Jan 6, 2025

Problem statement

The v1 /query API returns a different response structure when a GROUP BY is used in the query and our implementation of the /query API is not adhering to that.

Steps to reproduce

Running a v1.x InfluxDB instance, perform the following write:

curl "localhost:8086/write?db=mydb" -d "cpu,host=a usage=33"

Perform the following query:

curl "localhost:8086/query?db=mydb&q=SELECT+*+FROM+cpu+GROUP+BY+host"

This gives a response like:

{"results":[{"statement_id":0,"series":[{"name":"cpu","tags":{"host":"a"},"columns":["time","usage"],"values":[["2025-01-06T15:06:41.787035Z",33]]}]}]}

Note the tags attribute in the response.

Proposed solution

  • Update the /query API handler to adhere to this response structure.
  • Provide support to the InfluxQL parser to determine if the query is using a GROUP BY aggregation, and which tag is being used so we can inform the code that composes the API response (see http/v1.rs)
    • This may require upstream changes in IOx/core to expose the query syntax tree, but we are already doing some handling of that in the rewriter, so we may be able to hash out a solution here (this would need to be ported back to IOx/core at some point though)

Alternatives considered

N/A

Additional context

Slack thread.

@hiltontj hiltontj added the v3 label Jan 6, 2025
@hiltontj hiltontj self-assigned this Jan 6, 2025
@helenosheaa
Copy link
Member

This may or may not be helpful but I can link you to where we are building that in our go implementation thats used in dedicated (influxqlbridge) and serverless (influxqld)

https://github.com/influxdata/idpe/blob/837a193964f591dc6a76bb8cc03f54b070c50377/influxql/ioxflight/cursor.go#L173

You can see we use the INFLUXQL_METADATA_KEY or group by key to then parse the schema to build that kind of tags, columns, values v1 response

@mhilton and I worked on this a long while back and I cant find documentation on the fact that this is the expected format but backwards compatibility. Oh I found this on the dedicated docs which sheds a bit of light

@stuartcarnie is a great resource for all things InfluxQL (he helped us out a lot when we were doing the bridge work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants