influxdata / influxdb-client-php

InfluxDB (v2+) Client Library for PHP
https://influxdata.github.io/influxdb-client-php/
MIT License
150 stars 47 forks source link

New query return format #77

Closed fredmef closed 3 years ago

fredmef commented 3 years ago

Proposal: Add the following new format for query result: Array with the following columns:

time | tag_1 .... | tag_x | field_1 ... | field_y

Current behavior: Currently output formats are only unprocessed string and FluxRecord. These formats are not easy to exploit directly and need some extra treatments to be used.

Desired behavior: A query result as an array with columns corresponding to the desired ones.

Alternatives considered: None.

Use case: It helps users (simplify and accelerate development) coming from others databases and from previous InfluxDB php clients.

bednar commented 3 years ago

Hi @fredmef,

thanks for using our client.

Array with the following columns:

time | tag_1 .... | tag_x | field_1 ... | field_y

If you would like to have result as a tabular data, then use pivot() function in your query. Something like:

from(bucket:"test")
  |> range(start: 1970-01-01T00:00:00.000000000Z)
  |> pivot(
    rowKey:["_time"],
    columnKey: ["_field"],
    valueColumn: "_value"
  )

Regards

fredmef commented 3 years ago

Hi @bednar,

the pivot() function do the right job for me. Thanks a lot for this information.

Regards