Class QueryConfig

java.lang.Object
com.streambase.liveview.client.QueryConfig

public final class QueryConfig extends Object
QueryConfig is the builder object used to configure a query.

The client must call one or more of the set* methods or setQueryString(String) to properly set the query.

A query can return snapshot only or snapshot and continuous updates by calling setQueryType(LiveViewQueryType). The default is LiveViewQueryType.SNAPSHOT.

  • Field Details

    • DEFAULT_LIMIT

      public static final int DEFAULT_LIMIT
      The default number of rows to return in a query value. The default value is 10000.
    • NO_LIMIT

      public static final int NO_LIMIT
      The value for row limit that means no limit (-1)
      See Also:
    • DEFAULT_TIME_PREDICATE_IN_MILLISECONDS

      public static final int DEFAULT_TIME_PREDICATE_IN_MILLISECONDS
      The default delay in propagating a row that satisfies a queries predicate. The default is no delay.
      See Also:
  • Constructor Details

    • QueryConfig

      public QueryConfig()
      A new query configuration, initially configured for LiveViewQueryType.SNAPSHOT
    • QueryConfig

      public QueryConfig(LiveViewQueryType type)
      A new query configuration of the given type
      Parameters:
      type - the type of query as a LiveViewQueryType
      Since:
      1.5.4
      See Also:
    • QueryConfig

      public QueryConfig(com.streambase.liveview.internal.protocol.jaxb.Query jaxbQuery)
  • Method Details

    • getJaxbQuery

      public static com.streambase.liveview.internal.protocol.jaxb.Query getJaxbQuery(QueryConfig config, boolean convertSnapOnlyToContinuousOnly)
    • getQuery

      public String getQuery()
      Retrieves the string representation of the query.
      Returns:
      string representation of the query
    • setTable

      public QueryConfig setTable(String table)
      Configure the table to query
      Parameters:
      table - the target table for this query
      Returns:
      this object
    • setPredicate

      public QueryConfig setPredicate(String predicate)
      Configure the predicate
      Parameters:
      predicate - the predicate to filter on, may be null to request all rows
      Returns:
      this object
    • setTimeWindow

      public QueryConfig setTimeWindow(String startTimeExpr, String endTimeExpr, String timestampField)
      Configures this query as a time-windowed query, using the given start and end time expressions, against the given timestamp field from the target table.
      Parameters:
      startTimeExpr - the expression representing the start of the window, for example NOW-seconds(5). You may also use the word begin.
      endTimeExpr - the expression representing the end of the window, for example NOW-seconds(2) You may also use the word end.
      timestampField - the name of a timestamp field at the target table, for example ArrivalTime
      Returns:
      this object
      Since:
      1.4
    • getWindowStartTimeExpr

      public String getWindowStartTimeExpr()
      Get the value set in setTimeWindow
      Returns:
      the windowStartTimeExpr
      Since:
      2.0.1
    • getWindowEndTimeExpr

      public String getWindowEndTimeExpr()
      Get the value set in setTimeWindow
      Returns:
      the windowEndTimeExpr
      Since:
      2.0.1
    • getTimestampField

      public String getTimestampField()
      Get the value set in setTimeWindow
      Returns:
      the timestampField
      Since:
      2.0.1
    • getPivotAggExpr

      public String getPivotAggExpr()
      Get the pivot aggregate expressions, 'PIVOT' clause
      Returns:
      the comma separated pivot aggregate expression list
      Since:
      2.2.1
    • setPivotAggExpr

      public QueryConfig setPivotAggExpr(String pivotAggExpr)
      Set the pivot aggregate expressions, 'PIVOT' clause
      Returns:
      configured QueryConfig
      Since:
      2.2.1
    • setHaving

      public QueryConfig setHaving(String having)
      Set the having filter, 'HAVING' clause
      Returns:
      configured QueryConfig
      Since:
      2.2.3
    • getHaving

      public String getHaving()
      Get the 'HAVING' clause
      Returns:
      the having field
      Since:
      2.2.3
    • getPivotField

      public String getPivotField()
      Get the pivot 'FOR' clause
      Returns:
      the pivot field
      Since:
      2.2.1
    • setPivotField

      public QueryConfig setPivotField(String pivotField)
      Set the pivot 'FOR' clause
      Returns:
      configured QueryConfig
      Since:
      2.2.1
    • getPivotValues

      public String getPivotValues()
      Get the pivot 'VALUES' clause
      Returns:
      the pivot values
      Since:
      2.2.1
    • setPivotValues

      public QueryConfig setPivotValues(String pivotValues)
      Set the pivot 'VALUES' clause
      Returns:
      configured QueryConfig
      Since:
      2.2.1
    • setTopN

      public QueryConfig setTopN(OrderDefinition order, int size)
      Return only the top N results according to the order definition. A continuous query will remove a row when it has added a new row to keep the total result set no larger than N. Use OrderDefinition.reverse() to get the "bottom N".
      Parameters:
      order - - an OrderDefinition object that describes how rows should be ordered
      size - the maximum number of rows that will ever be in the result set.
      Returns:
      this object
      Since:
      1.4
    • setApproximateSnapshotOrder

      public QueryConfig setApproximateSnapshotOrder(OrderDefinition order)
      Return the snapshot part of the query in this approximate order, subject to parallel scan interleaving. A snapshot-parallelism of 1 will return rows in exact order, while increasing parallelism will cause increasing disorder. There is no limit to the size of the returned result set.
      Parameters:
      order - - an OrderDefinition object that describes how rows should be ordered
      Returns:
      this object
      Since:
      1.4
    • getApproximateSnapshotOrder

      public OrderDefinition getApproximateSnapshotOrder()
      The OrderDefinition object set by equivalent setter or setTopN.
      Returns:
      an OrderDefinition object that describes how rows should be ordered
      Since:
      2.0.1
    • setPredicate

      public QueryConfig setPredicate(String predicate, int timePredicateInMillis)
      Configure the predicate
      Parameters:
      predicate - the predicate to filter on.
      timePredicateInMillis - the predicate must be continuously true for timePredicateInMillis, before the query is satisfied.
      Returns:
      this object
    • setSelectFields

      public QueryConfig setSelectFields(Schema.Field... fields)
      Configure the result fields
      Parameters:
      fields - the fields to retrieve in the result
      Returns:
      this object
    • setSelectFields

      public QueryConfig setSelectFields(List<Schema.Field> fields)
      Configure the result fields
      Parameters:
      fields - the fields to retrieve in the result
      Returns:
      this object
    • setSelectExprs

      public QueryConfig setSelectExprs(String... exprs)
      Configure the result fields
      Parameters:
      exprs - the fields (as expressions) to retrieve in the result
      Returns:
      this object
    • setSelectExprs

      public QueryConfig setSelectExprs(List<String> exprs)
      Configure the result fields
      Parameters:
      exprs - the fields (as expressions) to retrieve in the result
      Returns:
      this object
    • getSelectExprs

      public List<String> getSelectExprs()
      The selectExprs set by the equivalent setters
      Returns:
      the selectExprs
      Since:
      2.0.1
    • setGroupByExprs

      public QueryConfig setGroupByExprs(String... exprs)
      Configure group-by
      Parameters:
      exprs - the group-by expressions
      Returns:
      this object
    • setGroupByExprs

      public QueryConfig setGroupByExprs(List<String> groupByExprs)
      Configure group-by
      Parameters:
      groupByExprs - the group-by expressions
      Returns:
      this object
    • getGroupByExprs

      public List<String> getGroupByExprs()
      the group-by expressions set by equivalent setters
      Returns:
      the group-by expressions
      Since:
      2.0.1
    • setLimit

      public QueryConfig setLimit(int limit)
      Deprecated.
      1.4 use setMaxResultSetSize(int) instead
      Configure the row limit. If/when the number of returned rows exceeds limit, an exception is thrown and the query is closed.
      Parameters:
      limit - the row limit
      Returns:
      this object
    • setMaxResultSetSize

      public QueryConfig setMaxResultSetSize(int limit)
      Configure the row limit. If/when the number of returned rows exceeds limit, an exception is thrown and the query is closed.
      Parameters:
      limit - the row limit
      Returns:
      this object
      Since:
      1.4
    • setQueryType

      public QueryConfig setQueryType(LiveViewQueryType queryType)
      Configure the query type. This method takes effect both when setQueryString(String) is used or the individual builder methods are invoked.
      Parameters:
      queryType - the query type.
      Returns:
      this object
      Since:
      1.3
    • setQueryString

      public QueryConfig setQueryString(String query)
      Configure the query using a single string, SQL-like syntax. Refer to the documentation for full details on the syntax.

      Use of this method overrides any other methods that configure individual parts of the query

      Parameters:
      query - A SQL-like string that can contain
      select [* | col [,col]*] from table where <predicate> [order by col[,col,...] [asc | desc] ] [limit <#rows>]
      Returns:
      the builder config object
    • extractTableNameFromQueryString

      public static String extractTableNameFromQueryString(String query)
    • setQuery

      public QueryConfig setQuery(String table, String predicate)
      Configure the table to query and predicate
      Parameters:
      table - the table to query
      predicate - the predicate to filter on, may be null to request all rows
      Returns:
      this object
    • setQuery

      public QueryConfig setQuery(List<Schema.Field> fields, String table, String predicate)
      Configure the table to query, the predicate and the result fields
      Parameters:
      fields - the list of fields from the table, may be null to request all fields
      table - the table to query
      predicate - the predicate to filter on, may be null to request all rows
      Returns:
      this object
    • setQuery

      public QueryConfig setQuery(List<Schema.Field> fields, String table, String predicate, int limit)
      Configure the table to query, the predicate and the result fields using a specified row limit
      Parameters:
      fields - the list of fields from the table, may be null to request all fields
      table - the table to query
      predicate - the predicate to filter on, may be null to request all rows
      limit - the row limit to impose
      Returns:
      this object
    • setQuery

      public QueryConfig setQuery(List<Schema.Field> fields, String table, String predicate, int limit, long timePredicateInMillis)
      Configure the table to query, the predicate and the result fields using a specified row limit and row delay
      Parameters:
      fields - the list of fields from the table, may be null to request all fields
      table - the table to query
      predicate - the predicate to filter on, may be null to request all rows
      limit - the row limit to impose
      timePredicateInMillis - the delay in propagating a row that satisfies the predicate
      Returns:
      this configured QueryConfig instance
    • setPivotQuery

      public QueryConfig setPivotQuery(String tableName, String pivotAggExprs, String pivotField, String pivotValues, String... groupByExprs)
      Configure the pivot query.

      CAUTION: projection "*" is the only valid projection in case of pivot queries currently supported which is the default if this method is used.

       Example of pivot query:
       select * from tableFoo 
       PIVOT sum(xField), avg(xField) 
       FOR zField
       VALUES [1, 2==3]
       GROUP BY qField
       

       The API usage corresponding to the above query is as follows:
       setPivotQuery(
       tableFoo,
       "sum(xField), avg(xField)", 
       "zField", 
       "1, 2==3",
        qField)
       
      Parameters:
      tableName - the table against which the query should be configured
      pivotAggExprs - ('PIVOT') the list of aggregate expressions that are to be computed for all values in pivot 'VALUES' clause
      pivotField - ('FOR') the column that should be used for literal values in 'VALUES' clause, optional(null) if no literals are used in 'VALUES' clause
      pivotValues - ('VALUES') boolean expressions or literals
      groupByExprs - configures the group-by expressions
      Returns:
      QueryConfig the configured QueryConfig object
    • getTable

      public String getTable()
      Get the table or null if not specified
      Returns:
      the table
    • getPredicate

      public String getPredicate()
      Get the predicate or null if not specified
      Returns:
      the predicate
    • getTimePredicateInMillis

      public long getTimePredicateInMillis()
      Get the time predicate or -1 if not specified
      Returns:
      The time predicate in milliseconds
    • setTimePredicateInMillis

      public QueryConfig setTimePredicateInMillis(long ms)
      Set the time predicate. This is the number of consecutive milliseconds the predicate condition must be true before the predicate condition matches.
      Returns:
      this object
    • getFields

      public List<Schema.Field> getFields()
      Get the fields or null if not specified
      Returns:
      the fields
    • getLimit

      public int getLimit()
      Get the limit or -1 if not specified
      Returns:
      the limit
    • getQueryType

      public LiveViewQueryType getQueryType()
      Get the type of query
      Returns:
      the type of query that should be run on the server
    • getDescription

      public String getDescription()
      Get the description for this query
      Returns:
      the description
    • setDescription

      public QueryConfig setDescription(String description)
      Configure the description for this query
      Parameters:
      description -
      Returns:
      this object
    • getVersion

      public Long getVersion()
    • getVersionString

      public String getVersionString()
    • getName

      public String getName()
    • setName

      public QueryConfig setName(String name)
      Parameters:
      name -
      Returns:
      this object
    • getOwner

      public String getOwner()
    • setOwner

      public QueryConfig setOwner(String owner)
      Parameters:
      owner -
      Returns:
      this object
    • getCreated

      public XMLGregorianCalendar getCreated()
    • getLastUpdated

      public XMLGregorianCalendar getLastUpdated()
    • getIncludeInternal

      public boolean getIncludeInternal()
      Is this query set to include internal fields?
      Returns:
      true if this query will override includeInternal property.
      Since:
      LiveView 1.6
    • setIncludeInternal

      public QueryConfig setIncludeInternal(boolean includeInternal)
      set to make this query include internal fields, regardless of the state of includeInternal property if false, use the property (which is set by the URI when connecting)
      Parameters:
      includeInternal -
      Returns:
      this object
      Since:
      LiveView 1.6