query_sql HTTP API
The v3 query API should be a GET or POST to /api/v3/query_sql. There is a shell of this already in https://github.com/influxdata/influxdb/pull/24552. The parameters it should take are db, q, and format. A bearer token can be provided via the Authorization header.
The format parameter is optional and defaults to jsonl for JSON Lines. Other valid options are pretty for pretty print output, csv for CSV output, and parquet for Parquet output. The format option should also be settable via the Accept header.
The query API should combine data from the Buffer and from Persisted parquet files in segments that the server has loaded up. By default the server will only load most recent segments on startup, so a query may not extend back in time to all data ever persisted by the server.
I used the following command to write a new entry into cpu table in foo
curl -v "http://127.0.0.1:8181/api/v3/write_lp?db=foo" --data-binary "cpu,host=a val=1i 123"
The logs indicate that the data has been writen successfully.
2024-01-15T17:17:53.006844Z INFO influxdb3_server::http: write_lp to foo
2024-01-15T17:17:53.006910Z INFO influxdb3_write::catalog: return new db foo
2024-01-15T17:17:53.007167Z INFO influxdb3_write::catalog: inserted foo
However, when I try to query the data using the following command
curl -v "http://127.0.0.1:8181/api/v3/query_sql?db=foo&q=select * from cpu"
I received 400 error code, and there is no response data provided.
* Trying 127.0.0.1:8181...
* Connected to 127.0.0.1 (127.0.0.1) port 8181 (#0)
> GET /api/v3/query_sql?db=foo&q=select * from cpu HTTP/1.1
> Host: 127.0.0.1:8181
> User-Agent: curl/7.74.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< content-length: 0
< date: Mon, 15 Jan 2024 17:19:18 GMT
<
* Connection #0 to host 127.0.0.1 left intact
Please tell me which step I did wrong.
Hey @dlgs5100 you need to url encode your query. We decode the request in this step here. If we do that then your query works:
❯ curl -v "http://127.0.0.1:8181/api/v3/query_sql?db=foo&q=select+*+from+cpu"
* processing: http://127.0.0.1:8181/api/v3/query_sql?db=foo&q=select+*+from+cpu
* Trying 127.0.0.1:8181...
* Connected to 127.0.0.1 (127.0.0.1) port 8181
> GET /api/v3/query_sql?db=foo&q=select+*+from+cpu HTTP/1.1
> Host: 127.0.0.1:8181
> User-Agent: curl/8.2.1
> Accept: */*
>
< HTTP/1.1 200 OK
< content-type: text/plain; charset=utf-8
< content-length: 234
< date: Tue, 16 Jan 2024 17:58:45 GMT
<
+------+-------------------------------+-----+
| host | time | val |
+------+-------------------------------+-----+
| a | 1970-01-01T00:00:00.000000123 | 1 |
* Connection #0 to host 127.0.0.1 left intact
+------+-------------------------------+-----+%
Just want to note that this issue is meant to track progress on the query_sql API for the MVP. If you open a separate issue in the future we can help you out better and contain the conversation of what went wrong there. Hopefully this helps!
It works, thanks @mgattozzi. Also apologize for my inappropriate behavior.
Since we landed the parquet query aspect in https://github.com/influxdata/influxdb/pull/24749 we can close this issue.