Skip to content

Support for InfluxQL (1.X style queries) #138

@mattv8

Description

@mattv8

Proposal:
Would it be possible to add support for the "old-style" InfluxQL queries?

Current behavior:
I am testing the following query:

SELECT count/518400 from (SELECT count("status") FROM "system" WHERE status = \'running\' ) WHERE time > now()-60d AND count > 129600 GROUP BY "host"'

In PHP, my code looks something like the following:

// Load the InfluxDB library
use InfluxDB2\Client;
use InfluxDB2\Model\WritePrecision;
use InfluxDB2\Query\Builder;

$client = new Client([
    "url" => "my_URL:8086",
    "token" => "my_token",
    "bucket" => "my_bucket",
    "org" => "my_org",
    "precision" => WritePrecision::NS,
]);
$queryApi = $client->createQueryApi();

$queryQL = 'SELECT count/518400 from (SELECT count("status") FROM "system" WHERE status = \'running\' ) WHERE time > now()-60d AND count > 129600 GROUP BY "host"';

// Execute the query
$result = $queryApi->query($queryQL);

Desired behavior:
I would expect an output array. Instead, this throws the following error
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught InfluxDB2\\ApiException: [400] Error connecting to the API (http://my_url:8086/api/v2/query?org=my_org)(: compilation failed: error @1:21-1:90: expected comma in property list, got IDENT\n\nerror @1:21-1:90: expected comma in property list, got LPAREN\n\nerror @1:39-1:89: invalid expression @1:87-1:88: '\n\nerror @1:39-1:89: unexpected token for property key: LPAREN (()) in /public_html/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php:157\nStack trace:\n#0 /public_html/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(214): InfluxDB2\\DefaultApi->sendRequest()\n#1 /public_html/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(79): InfluxDB2\\DefaultApi->request()\n#2 /public_html/vendor/influxdata/influxdb-client-php/src/InfluxDB2/QueryApi.php(115): InfluxDB2\\DefaultApi->post()\n#3 /public_html/vendor...'

Alternatives considered:
I tried "converting" the query to Flux as best as I could, but it returns an empty array:

$queryFlux = 'from(bucket: "my_bucket")
|> range(start: -60d)
|> filter(fn: (r) => r["status"] == "running")
|> count(column: "status")
|> filter(fn: (r) => r["_value"] > 129600)
|> map(fn: (r) => ({r with _value: r["_value"] / 518400}))
|> group(columns: ["host"])';

// Execute the query
$result = $queryApi->query($queryFlux);

Use case:
I have a lot of queries that I've built in Grafana that would be nice to more easily copy over, rather than re-formulate to the Flux queries. Plus would make it a lot easer to debug with a graphical UI such as Grafana that I can plug the queries into.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions