Package com.streambase.liveview.client
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 orsetQueryString(String)
to properly set the query.A query can return snapshot only or snapshot and continuous updates by calling
setQueryType(LiveViewQueryType)
. The default isLiveViewQueryType.SNAPSHOT
.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_LIMIT
The default number of rows to return in a query value.static int
DEFAULT_TIME_PREDICATE_IN_MILLISECONDS
The default delay in propagating a row that satisfies a queries predicate.static int
NO_LIMIT
The value for row limit that means no limit (-1)
-
Constructor Summary
Constructors Constructor Description QueryConfig()
A new query configuration, initially configured forLiveViewQueryType.SNAPSHOT
QueryConfig(LiveViewQueryType type)
A new query configuration of the given typeQueryConfig(Query jaxbQuery)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
extractTableNameFromQueryString(String query)
OrderDefinition
getApproximateSnapshotOrder()
The OrderDefinition object set by equivalent setter or setTopN.XMLGregorianCalendar
getCreated()
String
getDescription()
Get the description for this queryList<Schema.Field>
getFields()
Get the fields or null if not specifiedList<String>
getGroupByExprs()
the group-by expressions set by equivalent settersString
getHaving()
Get the 'HAVING' clauseboolean
getIncludeInternal()
Is this query set to include internal fields?static Query
getJaxbQuery(QueryConfig config, boolean convertSnapOnlyToContinuousOnly)
XMLGregorianCalendar
getLastUpdated()
int
getLimit()
Get the limit or -1 if not specifiedString
getName()
String
getOwner()
String
getPivotAggExpr()
Get the pivot aggregate expressions, 'PIVOT' clauseString
getPivotField()
Get the pivot 'FOR' clauseString
getPivotValues()
Get the pivot 'VALUES' clauseString
getPredicate()
Get the predicate or null if not specifiedString
getQuery()
Retrieves the string representation of the query.LiveViewQueryType
getQueryType()
Get the type of queryList<String>
getSelectExprs()
The selectExprs set by the equivalent settersString
getTable()
Get the table or null if not specifiedlong
getTimePredicateInMillis()
Get the time predicate or -1 if not specifiedString
getTimestampField()
Get the value set in setTimeWindowLong
getVersion()
String
getVersionString()
String
getWindowEndTimeExpr()
Get the value set in setTimeWindowString
getWindowStartTimeExpr()
Get the value set in setTimeWindowQueryConfig
setApproximateSnapshotOrder(OrderDefinition order)
Return the snapshot part of the query in this approximate order, subject to parallel scan interleaving.QueryConfig
setDescription(String description)
Configure the description for this queryQueryConfig
setGroupByExprs(String... exprs)
Configure group-byQueryConfig
setGroupByExprs(List<String> groupByExprs)
Configure group-byQueryConfig
setHaving(String having)
Set the having filter, 'HAVING' clauseQueryConfig
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)QueryConfig
setLimit(int limit)
Deprecated.1.4 usesetMaxResultSetSize(int)
insteadQueryConfig
setMaxResultSetSize(int limit)
Configure the row limit.QueryConfig
setName(String name)
QueryConfig
setOwner(String owner)
QueryConfig
setPivotAggExpr(String pivotAggExpr)
Set the pivot aggregate expressions, 'PIVOT' clauseQueryConfig
setPivotField(String pivotField)
Set the pivot 'FOR' clauseQueryConfig
setPivotQuery(String tableName, String pivotAggExprs, String pivotField, String pivotValues, String... groupByExprs)
Configure the pivot query.QueryConfig
setPivotValues(String pivotValues)
Set the pivot 'VALUES' clauseQueryConfig
setPredicate(String predicate)
Configure the predicateQueryConfig
setPredicate(String predicate, int timePredicateInMillis)
Configure the predicateQueryConfig
setQuery(String table, String predicate)
Configure the table to query and predicateQueryConfig
setQuery(List<Schema.Field> fields, String table, String predicate)
Configure the table to query, the predicate and the result fieldsQueryConfig
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 limitQueryConfig
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 delayQueryConfig
setQueryString(String query)
Configure the query using a single string, SQL-like syntax.QueryConfig
setQueryType(LiveViewQueryType queryType)
Configure the query type.QueryConfig
setSelectExprs(String... exprs)
Configure the result fieldsQueryConfig
setSelectExprs(List<String> exprs)
Configure the result fieldsQueryConfig
setSelectFields(Schema.Field... fields)
Configure the result fieldsQueryConfig
setSelectFields(List<Schema.Field> fields)
Configure the result fieldsQueryConfig
setTable(String table)
Configure the table to queryQueryConfig
setTimePredicateInMillis(long ms)
Set the time predicate.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.QueryConfig
setTopN(OrderDefinition order, int size)
Return only the top N results according to the order definition.
-
-
-
Field Detail
-
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:
- Constant Field Values
-
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:
- Constant Field Values
-
-
Constructor Detail
-
QueryConfig
public QueryConfig()
A new query configuration, initially configured forLiveViewQueryType.SNAPSHOT
-
QueryConfig
public QueryConfig(LiveViewQueryType type)
A new query configuration of the given type- Parameters:
type
- the type of query as aLiveViewQueryType
- Since:
- 1.5.4
- See Also:
LiveViewQueryType
-
QueryConfig
public QueryConfig(Query jaxbQuery)
-
-
Method Detail
-
getJaxbQuery
public static 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 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
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. 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
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 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
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 whensetQueryString(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 containselect [* | col [,col]*] from table where <predicate> [order by col[,col,...] [asc | desc] ] [limit <#rows>]
- Returns:
- the builder config object
-
setQuery
public QueryConfig setQuery(String table, String predicate)
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
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 fieldstable
- the table to querypredicate
- 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 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
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
-
-