Package com.streambase.liveview.client
Class QueryConfig
java.lang.Object
com.streambase.liveview.client.QueryConfig
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 Summary
Modifier and TypeFieldDescriptionstatic final int
The default number of rows to return in a query value.static final int
The default delay in propagating a row that satisfies a queries predicate.static final int
The value for row limit that means no limit (-1) -
Constructor Summary
ConstructorDescriptionA new query configuration, initially configured forLiveViewQueryType.SNAPSHOT
QueryConfig
(LiveViewQueryType type) A new query configuration of the given typeQueryConfig
(com.streambase.liveview.internal.protocol.jaxb.Query jaxbQuery) -
Method Summary
Modifier and TypeMethodDescriptionstatic String
The OrderDefinition object set by equivalent setter or setTopN.Get the description for this queryGet the fields or null if not specifiedthe group-by expressions set by equivalent settersGet the 'HAVING' clauseboolean
Is this query set to include internal fields?static com.streambase.liveview.internal.protocol.jaxb.Query
getJaxbQuery
(QueryConfig config, boolean convertSnapOnlyToContinuousOnly) int
getLimit()
Get the limit or -1 if not specifiedgetName()
getOwner()
Get the pivot aggregate expressions, 'PIVOT' clauseGet the pivot 'FOR' clauseGet the pivot 'VALUES' clauseGet the predicate or null if not specifiedgetQuery()
Retrieves the string representation of the query.Get the type of queryThe selectExprs set by the equivalent settersgetTable()
Get the table or null if not specifiedlong
Get the time predicate or -1 if not specifiedGet the value set in setTimeWindowGet the value set in setTimeWindowGet the value set in setTimeWindowReturn the snapshot part of the query in this approximate order, subject to parallel scan interleaving.setDescription
(String description) Configure the description for this querysetGroupByExprs
(String... exprs) Configure group-bysetGroupByExprs
(List<String> groupByExprs) Configure group-bySet the having filter, 'HAVING' clausesetIncludeInternal
(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)setLimit
(int limit) Deprecated.setMaxResultSetSize
(int limit) Configure the row limit.setPivotAggExpr
(String pivotAggExpr) Set the pivot aggregate expressions, 'PIVOT' clausesetPivotField
(String pivotField) Set the pivot 'FOR' clausesetPivotQuery
(String tableName, String pivotAggExprs, String pivotField, String pivotValues, String... groupByExprs) Configure the pivot query.setPivotValues
(String pivotValues) Set the pivot 'VALUES' clausesetPredicate
(String predicate) Configure the predicatesetPredicate
(String predicate, int timePredicateInMillis) Configure the predicateConfigure the table to query and predicatesetQuery
(List<Schema.Field> fields, String table, String predicate) Configure the table to query, the predicate and the result fieldssetQuery
(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 limitsetQuery
(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 delaysetQueryString
(String query) Configure the query using a single string, SQL-like syntax.setQueryType
(LiveViewQueryType queryType) Configure the query type.setSelectExprs
(String... exprs) Configure the result fieldssetSelectExprs
(List<String> exprs) Configure the result fieldssetSelectFields
(Schema.Field... fields) Configure the result fieldssetSelectFields
(List<Schema.Field> fields) Configure the result fieldsConfigure the table to querysetTimePredicateInMillis
(long ms) Set the time predicate.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.setTopN
(OrderDefinition order, int size) Return only the top N results according to the order definition.
-
Field Details
-
DEFAULT_LIMIT
public static final int DEFAULT_LIMITThe default number of rows to return in a query value. The default value is 10000. -
NO_LIMIT
public static final int NO_LIMITThe value for row limit that means no limit (-1)- See Also:
-
DEFAULT_TIME_PREDICATE_IN_MILLISECONDS
public static final int DEFAULT_TIME_PREDICATE_IN_MILLISECONDSThe 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 forLiveViewQueryType.SNAPSHOT
-
QueryConfig
A new query configuration of the given type- Parameters:
type
- the type of query as aLiveViewQueryType
- 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
Retrieves the string representation of the query.- Returns:
- string representation of the query
-
setTable
Configure the table to query- Parameters:
table
- the target table for this query- Returns:
- this object
-
setPredicate
Configure the predicate- Parameters:
predicate
- the predicate to filter on, may be null to request all rows- Returns:
- this object
-
setTimeWindow
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 exampleNOW-seconds(5)
. You may also use the wordbegin
.endTimeExpr
- the expression representing the end of the window, for exampleNOW-seconds(2)
You may also use the wordend
.timestampField
- the name of a timestamp field at the target table, for exampleArrivalTime
- Returns:
- this object
- Since:
- 1.4
-
getWindowStartTimeExpr
Get the value set in setTimeWindow- Returns:
- the windowStartTimeExpr
- Since:
- 2.0.1
-
getWindowEndTimeExpr
Get the value set in setTimeWindow- Returns:
- the windowEndTimeExpr
- Since:
- 2.0.1
-
getTimestampField
Get the value set in setTimeWindow- Returns:
- the timestampField
- Since:
- 2.0.1
-
getPivotAggExpr
Get the pivot aggregate expressions, 'PIVOT' clause- Returns:
- the comma separated pivot aggregate expression list
- Since:
- 2.2.1
-
setPivotAggExpr
Set the pivot aggregate expressions, 'PIVOT' clause- Returns:
- configured QueryConfig
- Since:
- 2.2.1
-
setHaving
Set the having filter, 'HAVING' clause- Returns:
- configured QueryConfig
- Since:
- 2.2.3
-
getHaving
Get the 'HAVING' clause- Returns:
- the having field
- Since:
- 2.2.3
-
getPivotField
Get the pivot 'FOR' clause- Returns:
- the pivot field
- Since:
- 2.2.1
-
setPivotField
Set the pivot 'FOR' clause- Returns:
- configured QueryConfig
- Since:
- 2.2.1
-
getPivotValues
Get the pivot 'VALUES' clause- Returns:
- the pivot values
- Since:
- 2.2.1
-
setPivotValues
Set the pivot 'VALUES' clause- Returns:
- configured QueryConfig
- Since:
- 2.2.1
-
setTopN
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. UseOrderDefinition.reverse()
to get the "bottom N".- Parameters:
order
- - an OrderDefinition object that describes how rows should be orderedsize
- the maximum number of rows that will ever be in the result set.- Returns:
- this object
- Since:
- 1.4
-
setApproximateSnapshotOrder
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
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
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
Configure the result fields- Parameters:
fields
- the fields to retrieve in the result- Returns:
- this object
-
setSelectFields
Configure the result fields- Parameters:
fields
- the fields to retrieve in the result- Returns:
- this object
-
setSelectExprs
Configure the result fields- Parameters:
exprs
- the fields (as expressions) to retrieve in the result- Returns:
- this object
-
setSelectExprs
Configure the result fields- Parameters:
exprs
- the fields (as expressions) to retrieve in the result- Returns:
- this object
-
getSelectExprs
The selectExprs set by the equivalent setters- Returns:
- the selectExprs
- Since:
- 2.0.1
-
setGroupByExprs
Configure group-by- Parameters:
exprs
- the group-by expressions- Returns:
- this object
-
setGroupByExprs
Configure group-by- Parameters:
groupByExprs
- the group-by expressions- Returns:
- this object
-
getGroupByExprs
the group-by expressions set by equivalent setters- Returns:
- the group-by expressions
- Since:
- 2.0.1
-
setLimit
Deprecated.1.4 usesetMaxResultSetSize(int)
insteadConfigure 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
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
Configure the query type. This method takes effect both whensetQueryString(String)
is used or the individual builder methods are invoked.- Parameters:
queryType
- the query type.- Returns:
- this object
- Since:
- 1.3
-
setQueryString
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 containselect [* | col [,col]*] from table where <predicate> [order by col[,col,...] [asc | desc] ] [limit <#rows>]
- Returns:
- the builder config object
-
extractTableNameFromQueryString
-
setQuery
Configure the table to query and predicate- Parameters:
table
- the table to querypredicate
- the predicate to filter on, may be null to request all rows- Returns:
- this object
-
setQuery
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 fieldstable
- the table to querypredicate
- the predicate to filter on, may be null to request all rows- Returns:
- this object
-
setQuery
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 fieldstable
- the table to querypredicate
- the predicate to filter on, may be null to request all rowslimit
- 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 fieldstable
- the table to querypredicate
- the predicate to filter on, may be null to request all rowslimit
- the row limit to imposetimePredicateInMillis
- 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 configuredpivotAggExprs
- ('PIVOT') the list of aggregate expressions that are to be computed for all values in pivot 'VALUES' clausepivotField
- ('FOR') the column that should be used for literal values in 'VALUES' clause, optional(null) if no literals are used in 'VALUES' clausepivotValues
- ('VALUES') boolean expressions or literalsgroupByExprs
- configures the group-by expressions- Returns:
QueryConfig
the configured QueryConfig object
-
getTable
Get the table or null if not specified- Returns:
- the table
-
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
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
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
Get the type of query- Returns:
- the type of query that should be run on the server
-
getDescription
Get the description for this query- Returns:
- the description
-
setDescription
Configure the description for this query- Parameters:
description
-- Returns:
- this object
-
getVersion
-
getVersionString
-
getName
-
setName
- Parameters:
name
-- Returns:
- this object
-
getOwner
-
setOwner
- Parameters:
owner
-- Returns:
- this object
-
getCreated
-
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
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
-
setMaxResultSetSize(int)
instead