Interface InfluxQLQueryApi

All Known Implementing Classes:
InfluxQLQueryApiImpl

@ThreadSafe public interface InfluxQLQueryApi
The 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 the application/json MIME type.

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 Details

    • query

      @Nonnull InfluxQLQueryResult query(@Nonnull InfluxQLQuery influxQlQuery)
      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 query
      valueExtractor - a callback, to convert column values
      Returns:
      the result
    • queryCSV

      @Nonnull InfluxQLQueryResult queryCSV(@Nonnull InfluxQLQuery influxQLQuery)
      Convenience method to specify use of the mime type application/csv in the Accept 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 type application/csv in the Accept header. Result timestamps will be in the Epoch format.
      Parameters:
      influxQLQuery - the query
      valueExtractor - a callback, to convert column values
      Returns:
      the result
    • queryJSON

      @Nonnull InfluxQLQueryResult queryJSON(@Nonnull InfluxQLQuery influxQLQuery)
      Convenience method to specify use of the mime type application/json in the Accept 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 type application/json in the Accept header. Result timestamps will be in the RFC3339 format.
      Parameters:
      influxQLQuery - the query
      valueExtractor - a callback, to convert column values
      Returns:
      the result