public final class QueryConfig
extends java.lang.Object
The client must call one or more of the set*
methods or QueryConfig.setQueryString(String)
to properly set the query.
A query can return snapshot only or snapshot and continuous updates by calling QueryConfig.setQueryType(LiveViewQueryType)
.
The default is LiveViewQueryType.SNAPSHOT
.
Modifier and Type | Field and 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 and Description |
---|
QueryConfig()
A new query configuration, initially configured for
LiveViewQueryType.SNAPSHOT |
QueryConfig(LiveViewQueryType type)
A new query configuration of the given type
|
QueryConfig(com.streambase.liveview.internal.protocol.jaxb.Query jaxbQuery) |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
extractTableNameFromQueryString(java.lang.String query) |
OrderDefinition |
getApproximateSnapshotOrder()
The OrderDefinition object set by equivalent setter or setTopN.
|
javax.xml.datatype.XMLGregorianCalendar |
getCreated() |
java.lang.String |
getDescription()
Get the description for this query
|
java.util.List<Schema.Field> |
getFields()
Get the fields or null if not specified
|
java.util.List<java.lang.String> |
getGroupByExprs()
the group-by expressions set by equivalent setters
|
boolean |
getIncludeInternal()
Is this query set to include internal fields?
|
static com.streambase.liveview.internal.protocol.jaxb.Query |
getJaxbQuery(QueryConfig config,
boolean convertSnapOnlyToContinuousOnly) |
javax.xml.datatype.XMLGregorianCalendar |
getLastUpdated() |
int |
getLimit()
Get the limit or -1 if not specified
|
java.lang.String |
getName() |
java.lang.String |
getOwner() |
java.lang.String |
getPivotAggExpr()
Get the pivot aggregate expressions, 'PIVOT' clause
|
java.lang.String |
getPivotField()
Get the pivot 'FOR' clause
|
java.lang.String |
getPivotValues()
Get the pivot 'VALUES' clause
|
java.lang.String |
getPredicate()
Get the predicate or null if not specified
|
java.lang.String |
getQuery()
Retrieves the string representation of the query.
|
LiveViewQueryType |
getQueryType()
Get the type of query
|
java.util.List<java.lang.String> |
getSelectExprs()
The selectExprs set by the equivalent setters
|
java.lang.String |
getTable()
Get the table or null if not specified
|
long |
getTimePredicateInMillis()
Get the time predicate or -1 if not specified
|
java.lang.String |
getTimestampField()
Get the value set in setTimeWindow
|
java.lang.Long |
getVersion() |
java.lang.String |
getVersionString() |
java.lang.String |
getWindowEndTimeExpr()
Get the value set in setTimeWindow
|
java.lang.String |
getWindowStartTimeExpr()
Get the value set in setTimeWindow
|
QueryConfig |
setApproximateSnapshotOrder(OrderDefinition order)
Return the snapshot part of the query in this approximate order,
subject to parallel scan interleaving.
|
QueryConfig |
setDescription(java.lang.String description)
Configure the description for this query
|
QueryConfig |
setGroupByExprs(java.util.List<java.lang.String> groupByExprs)
Configure group-by
|
QueryConfig |
setGroupByExprs(java.lang.String... exprs)
Configure group-by
|
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)
|
QueryConfig |
setLimit(int limit)
Deprecated.
1.4 use
QueryConfig.setMaxResultSetSize(int) instead |
QueryConfig |
setMaxResultSetSize(int limit)
Configure the row limit.
|
QueryConfig |
setName(java.lang.String name) |
QueryConfig |
setOwner(java.lang.String owner) |
QueryConfig |
setPivotAggExpr(java.lang.String pivotAggExpr)
Set the pivot aggregate expressions, 'PIVOT' clause
|
QueryConfig |
setPivotField(java.lang.String pivotField)
Set the pivot 'FOR' clause
|
QueryConfig |
setPivotQuery(java.lang.String tableName,
java.lang.String pivotAggExprs,
java.lang.String pivotField,
java.lang.String pivotValues,
java.lang.String... groupByExprs)
Configure the pivot query
|
QueryConfig |
setPivotValues(java.lang.String pivotValues)
Set the pivot 'VALUES' clause
|
QueryConfig |
setPredicate(java.lang.String predicate)
Configure the predicate
|
QueryConfig |
setPredicate(java.lang.String predicate,
int timePredicateInMillis)
Configure the predicate
|
QueryConfig |
setQuery(java.util.List<Schema.Field> fields,
java.lang.String table,
java.lang.String predicate)
Configure the table to query, the predicate and the result fields
|
QueryConfig |
setQuery(java.util.List<Schema.Field> fields,
java.lang.String table,
java.lang.String predicate,
int limit)
Configure the table to query, the predicate and the result fields using a specified row limit
|
QueryConfig |
setQuery(java.util.List<Schema.Field> fields,
java.lang.String table,
java.lang.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
|
QueryConfig |
setQuery(java.lang.String table,
java.lang.String predicate)
Configure the table to query and predicate
|
QueryConfig |
setQueryString(java.lang.String query)
Configure the query using a single string, SQL-like syntax.
|
QueryConfig |
setQueryType(LiveViewQueryType queryType)
Configure the query type.
|
QueryConfig |
setSelectExprs(java.util.List<java.lang.String> exprs)
Configure the result fields
|
QueryConfig |
setSelectExprs(java.lang.String... exprs)
Configure the result fields
|
QueryConfig |
setSelectFields(java.util.List<Schema.Field> fields)
Configure the result fields
|
QueryConfig |
setSelectFields(Schema.Field... fields)
Configure the result fields
|
QueryConfig |
setTable(java.lang.String table)
Configure the table to query
|
QueryConfig |
setTimePredicateInMillis(long ms)
Set the time predicate.
|
QueryConfig |
setTimeWindow(java.lang.String startTimeExpr,
java.lang.String endTimeExpr,
java.lang.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.
|
public static final int DEFAULT_LIMIT
public static final int NO_LIMIT
public static final int DEFAULT_TIME_PREDICATE_IN_MILLISECONDS
public QueryConfig()
LiveViewQueryType.SNAPSHOT
public QueryConfig(LiveViewQueryType type)
type
- the type of query as a LiveViewQueryType
LiveViewQueryType
public QueryConfig(com.streambase.liveview.internal.protocol.jaxb.Query jaxbQuery)
public static com.streambase.liveview.internal.protocol.jaxb.Query getJaxbQuery(QueryConfig config, boolean convertSnapOnlyToContinuousOnly)
public java.lang.String getQuery()
public QueryConfig setTable(java.lang.String table)
table
- the target table for this querypublic QueryConfig setPredicate(java.lang.String predicate)
predicate
- the predicate to filter on, may be null to request all rowspublic QueryConfig setTimeWindow(java.lang.String startTimeExpr, java.lang.String endTimeExpr, java.lang.String timestampField)
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
public java.lang.String getWindowStartTimeExpr()
public java.lang.String getWindowEndTimeExpr()
public java.lang.String getTimestampField()
public java.lang.String getPivotAggExpr()
public QueryConfig setPivotAggExpr(java.lang.String pivotAggExpr)
public java.lang.String getPivotField()
public QueryConfig setPivotField(java.lang.String pivotField)
public java.lang.String getPivotValues()
public QueryConfig setPivotValues(java.lang.String pivotValues)
public QueryConfig setTopN(OrderDefinition order, int size)
OrderDefinition.reverse()
to get the "bottom N".order
- - an OrderDefinition object that describes how rows should be orderedsize
- the maximum number of rows that will ever be in the result set.public QueryConfig setApproximateSnapshotOrder(OrderDefinition order)
order
- - an OrderDefinition object that describes how rows should be orderedpublic OrderDefinition getApproximateSnapshotOrder()
public QueryConfig setPredicate(java.lang.String predicate, int timePredicateInMillis)
predicate
- the predicate to filter on.timePredicateInMillis
- the predicate must be continuously true for timePredicateInMillis, before the query is satisfied.public QueryConfig setSelectFields(Schema.Field... fields)
fields
- the fields to retrieve in the resultpublic QueryConfig setSelectFields(java.util.List<Schema.Field> fields)
fields
- the fields to retrieve in the resultpublic QueryConfig setSelectExprs(java.lang.String... exprs)
exprs
- the fields (as expressions) to retrieve in the resultpublic QueryConfig setSelectExprs(java.util.List<java.lang.String> exprs)
exprs
- the fields (as expressions) to retrieve in the resultpublic java.util.List<java.lang.String> getSelectExprs()
public QueryConfig setGroupByExprs(java.lang.String... exprs)
exprs
- the group-by expressionspublic QueryConfig setGroupByExprs(java.util.List<java.lang.String> groupByExprs)
groupByExprs
- the group-by expressionspublic java.util.List<java.lang.String> getGroupByExprs()
public QueryConfig setLimit(int limit)
QueryConfig.setMaxResultSetSize(int)
insteadlimit
- the row limitpublic QueryConfig setMaxResultSetSize(int limit)
limit
- the row limitpublic QueryConfig setQueryType(LiveViewQueryType queryType)
QueryConfig.setQueryString(String)
is used or the
individual builder methods are invoked.queryType
- the query type.public QueryConfig setQueryString(java.lang.String query)
Use of this method overrides any other methods that configure individual parts of the query
query
- A SQL-like string that can contain select [* | col [,col]*] from table where <predicate> [order by col[,col,...] [asc | desc] ] [limit <#rows>]
public static java.lang.String extractTableNameFromQueryString(java.lang.String query)
public QueryConfig setQuery(java.lang.String table, java.lang.String predicate)
table
- the table to querypredicate
- the predicate to filter on, may be null to request all rowspublic QueryConfig setQuery(java.util.List<Schema.Field> fields, java.lang.String table, java.lang.String predicate)
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 rowspublic QueryConfig setQuery(java.util.List<Schema.Field> fields, java.lang.String table, java.lang.String predicate, int limit)
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 imposepublic QueryConfig setQuery(java.util.List<Schema.Field> fields, java.lang.String table, java.lang.String predicate, int limit, long timePredicateInMillis)
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 predicatepublic QueryConfig setPivotQuery(java.lang.String tableName, java.lang.String pivotAggExprs, java.lang.String pivotField, java.lang.String pivotValues, java.lang.String... groupByExprs)
tableName
- the table against which the query should be configuredpivotAggExpr('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 expressionsQueryConfig
the configured QueryConfig object
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)public java.lang.String getTable()
public java.lang.String getPredicate()
public long getTimePredicateInMillis()
public QueryConfig setTimePredicateInMillis(long ms)
public java.util.List<Schema.Field> getFields()
public int getLimit()
public LiveViewQueryType getQueryType()
public java.lang.String getDescription()
public QueryConfig setDescription(java.lang.String description)
description
- public java.lang.Long getVersion()
public java.lang.String getVersionString()
public java.lang.String getName()
public QueryConfig setName(java.lang.String name)
name
- public java.lang.String getOwner()
public QueryConfig setOwner(java.lang.String owner)
owner
- public javax.xml.datatype.XMLGregorianCalendar getCreated()
public javax.xml.datatype.XMLGregorianCalendar getLastUpdated()
public boolean getIncludeInternal()
public QueryConfig setIncludeInternal(boolean includeInternal)
includeInternal
-