Package com.influxdb.client
Interface InfluxQLQueryApi
- All Known Implementing Classes:
InfluxQLQueryApiImpl
@ThreadSafe
public interface InfluxQLQueryApi
The
For more information, see:
InfluxQL
API can be used with the /query compatibility
endpoint which uses the
database
and
retention policy
specified in the query request to
map the request to an InfluxDB bucket.
Note that as of release 7.2 queries using the legacy InfluxQL
compatible endpoint can specify
the Accept
header MIME type. Two MIME types are supported.
application/csv
- client default and legacy value.application/json
The selected Accept
header mime type impacts the timestamp format returned from the server.
application/csv
returns timestamps in the POSIX epoch format.application/json
returns timestamps as RFC3339 strings.- Caveat. If
InfluxQLQuery.setPrecision()
is called before the query is sent, then the timestamp will be returned as a POSIX epoch reflecting the desired precision, even when using theapplication/json
MIME type.
- Caveat. If
To explicitly choose one or the other MIME type new convenience methods are povided: queryCSV
and queryJSON
. Note that the Accept
header MIME type can now also be specified
when instantiating the InfluxQLQuery
class.
For more information, see:
-
Method Summary
Modifier and TypeMethodDescriptionquery
(InfluxQLQuery influxQlQuery) Executes an InfluxQL query against the legacy endpoint.query
(InfluxQLQuery influxQlQuery, InfluxQLQueryResult.Series.ValueExtractor valueExtractor) Executes an InfluxQL query against the legacy endpoint.queryCSV
(InfluxQLQuery influxQLQuery) Convenience method to specify use of the mime typeapplication/csv
in theAccept
header.queryCSV
(InfluxQLQuery influxQLQuery, InfluxQLQueryResult.Series.ValueExtractor valueExtractor) Convenience method to specify use of the mime typeapplication/csv
in theAccept
header.queryJSON
(InfluxQLQuery influxQLQuery) Convenience method to specify use of the mime typeapplication/json
in theAccept
header.queryJSON
(InfluxQLQuery influxQLQuery, InfluxQLQueryResult.Series.ValueExtractor valueExtractor) Convenience method to specify use of the mime typeapplication/json
in theAccept
header.
-
Method Details
-
query
Executes an InfluxQL query against the legacy endpoint.- Parameters:
influxQlQuery
- the query- Returns:
- the result
-
query
@Nonnull InfluxQLQueryResult query(@Nonnull InfluxQLQuery influxQlQuery, @Nullable InfluxQLQueryResult.Series.ValueExtractor valueExtractor) Executes an InfluxQL query against the legacy endpoint. The value extractor is called for each resulting column to convert the string value returned by query into a custom type.Example:
InfluxQLQueryResult result = influxQLQueryApi.query( new InfluxQLQuery("SELECT FIRST(\"free\") FROM \"influxql\"", DATABASE_NAME) .setPrecision(InfluxQLQuery.InfluxQLPrecision.SECONDS), (columnName, rawValue, resultIndex, seriesName) -> { switch (columnName) { case "time": return Instant.ofEpochSecond(Long.parseLong(rawValue)); case "first": return new BigDecimal(rawValue); default: throw new IllegalArgumentException("unexpected column " + columnName); } } );
- Parameters:
influxQlQuery
- the queryvalueExtractor
- a callback, to convert column values- Returns:
- the result
-
queryCSV
Convenience method to specify use of the mime typeapplication/csv
in theAccept
header. Result timestamps will be in the Epoch format.- Parameters:
influxQLQuery
- the query- Returns:
- the result
-
queryCSV
InfluxQLQueryResult queryCSV(@Nonnull InfluxQLQuery influxQLQuery, @Nullable InfluxQLQueryResult.Series.ValueExtractor valueExtractor) Convenience method to specify use of the mime typeapplication/csv
in theAccept
header. Result timestamps will be in the Epoch format.- Parameters:
influxQLQuery
- the queryvalueExtractor
- a callback, to convert column values- Returns:
- the result
-
queryJSON
Convenience method to specify use of the mime typeapplication/json
in theAccept
header. Result timestamps will be in the RFC3339 format.- Parameters:
influxQLQuery
- the query- Returns:
- the result
-
queryJSON
@Nonnull InfluxQLQueryResult queryJSON(@Nonnull InfluxQLQuery influxQLQuery, @Nullable InfluxQLQueryResult.Series.ValueExtractor valueExtractor) Convenience method to specify use of the mime typeapplication/json
in theAccept
header. Result timestamps will be in the RFC3339 format.- Parameters:
influxQLQuery
- the queryvalueExtractor
- a callback, to convert column values- Returns:
- the result
-