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

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

Open
mattv8 opened this issue Jan 9, 2023 · 2 comments
Open

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

mattv8 opened this issue Jan 9, 2023 · 2 comments

Comments

@mattv8
Copy link

mattv8 commented Jan 9, 2023

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.

@blieb
Copy link

blieb commented Mar 1, 2024

Since there is no future for flux I think it would be nice if this was added. Think this will be added if this library updates to influxdb3 ?

https://www.influxdata.com/blog/the-plan-for-influxdb-3-0-open-source/#heading4

@Dhaarinigovindaraj
Copy link

Its working with influxql .. Im querying influxdb V2.7 data in php8.1, I have created influx v1 auth influx v1 auth create | InfluxDB OSS v2 Documentation and dbrp mapping for the bucket https://docs.influxdata.com/influxdb/v2/reference/cli/influx/v1/dbrp/list/

I have installed [InfluxDB v1 PHP client], using below php code connected to influxdbV2

``<?php
$host = 'localhost';
$port = 8086;
$dbname = 'Test';
$username = 'xxxxx';
$password = 'xxxxx';
require DIR . '/vendor/autoload.php';
$client = new InfluxDB\Client($host, $port, $username, $password);
print_r($client);
$database = $client->selectDB($dbname);
$result = $database->query('select co from airSensors WHERE time > now()-4d');
$points = $result->getPoints();
print_r($points);
//header('Content-type:application/json;charset=utf-8');
//echo json_encode( $result, JSON_PRETTY_PRINT ) ;

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

No branches or pull requests

3 participants