Class Query


  • public class Query
    extends java.lang.Object
    Represents an InfluxDB SELECT query to be periodically executed by the InfluxdbMetricStreamer to fetch new metrics values. A query should avoid filtering on time in the WHERE clause, as selecting the approriate interval for which to fetch metrics will be handled by the InfluxdbMetricStreamer.

    The author of InfluxdbMetricStreamer queries need to be aware of the following:

    • Only select a single field/column in the SELECT statement. Any additional fields are ignored in the result processing.
    • The selected field/column must be a numeric value. If not, errors will be raised during result processing.
    • Semi-colons are disallowed. This protects against injecting additional modifying queries/statements.
    • It is entirely possible to put together queries that don't make sense. These won't be caught until runtime (when an attmept is made to execute the query against InfluxDB).
    See Also:
    MetricStreamDefinition
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Query.Builder  
    • Constructor Summary

      Constructors 
      Constructor Description
      Query​(java.lang.String select, java.lang.String from, java.lang.String where, java.lang.String groupBy)
      Creates a Query.
    • Constructor Detail

      • Query

        public Query​(java.lang.String select,
                     java.lang.String from,
                     java.lang.String where,
                     java.lang.String groupBy)
        Creates a Query.
        Parameters:
        select - SELECT clause. For example, mean('request_rate') or non_negative_derivative(max('value'), 1s). The select statement should select one single field/column (only the first field is handled in result processing). The selected field/column must be a numeric value. If not, errors will be raised during result processing. Surround identifiers with double quotes to support a richer character set for identifiers.
        from - FROM clause. Specifies the measurement to query for. For example, cpu/system. Surround identifiers with double quotes to support a richer character set for identifiers.
        where - WHERE clause. Used to filter data based on tags/field values. Avoid filtering on time in the WHERE clause, as selecting the approriate interval for which to fetch metrics will be handled by the InfluxdbMetricStreamer. Behavior is undefined if time filters are inclued. Surround identifiers with double quotes to support a richer character set for identifiers.
        groupBy - GROUP BY clause. Can be used to downsample data (if combined with an aggregation function in the SELECT clause), for example by specifying something like time(10s) fill(none).

        Note: do not group on tags, since that will create different series in the result (one per group) and the result handler will only process the first series (the order may not be deterministic). Use a WHERE clause to query for a particular combination of tags.

    • Method Detail

      • getSelect

        public java.lang.String getSelect()
        SELECT clause. For example, mean('request_rate') or non_negative_derivative(max('value'), 1s). The select statement should select one single field/column (only the first field is handled in result processing). The selected field/column must be a numeric value. If not, errors will be raised during result processing.
        Returns:
      • getFrom

        public java.lang.String getFrom()
        FROM clause. Specifies the measurement to query for. For example, cpu/system.
        Returns:
      • getWhere

        public java.lang.String getWhere()
        WHERE clause. Used to filter data based on tags/field values. Avoid filtering on time in the WHERE clause, as selecting the approriate interval for which to fetch metrics will be handled by the InfluxdbMetricStreamer. Behavior is undefined if time filters are inclued.
        Returns:
      • getGroupBy

        public java.lang.String getGroupBy()
        GROUP BY clause. Can be used to downsample data (if combined with an aggregation function in the SELECT clause), for example by specifying something like time(10s) fill(none).

        Note: do not group on tags, since that will create different series in the result (one per group) and the result handler will only process the first series (the order may not be deterministic). Use a WHERE clause to query for a particular combination of tags.

        Returns:
      • withGroupBy

        public Query withGroupBy​(java.lang.String groupBy)
        Creates a field-by-field copy of this Query with the groupBy clause replaced in the returned copy.
        Parameters:
        groupBy -
        Returns:
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • validate

        public Query validate()
                       throws java.lang.IllegalArgumentException
        * Checks the validity of field values. Throws an IllegalArgumentException if necessary conditions are not satisfied.
        Returns:
        Throws:
        java.lang.IllegalArgumentException