public final class QueryConfig extends 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 String |
extractTableNameFromQueryString(String query) |
OrderDefinition |
getApproximateSnapshotOrder()
The OrderDefinition object set by equivalent setter or setTopN.
|
XMLGregorianCalendar |
getCreated() |
String |
getDescription()
Get the description for this query
|
List<Schema.Field> |
getFields()
Get the fields or null if not specified
|
List<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) |
static com.streambase.liveview.internal.protocol.jaxb.QueryConfig |
getJaxbQueryConfig(QueryConfig config) |
XMLGregorianCalendar |
getLastUpdated() |
int |
getLimit()
Get the limit or -1 if not specified
|
String |
getName() |
String |
getOwner() |
String |
getPredicate()
Get the predicate or null if not specified
|
String |
getQuery()
Retrieves the string representation of the query.
|
LiveViewQueryType |
getQueryType()
Get the type of query
|
List<String> |
getSelectExprs()
The selectExprs set by the equivalent setters
|
String |
getTable()
Get the table or null if not specified
|
long |
getTimePredicateInMillis()
Get the time predicate or -1 if not specified
|
String |
getTimestampField()
Get the value set in setTimeWindow
|
Long |
getVersion() |
String |
getVersionString() |
String |
getWindowEndTimeExpr()
Get the value set in setTimeWindow
|
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(String description)
Configure the description for this query
|
QueryConfig |
setGroupByExprs(List<String> groupByExprs)
Configure group-by
|
QueryConfig |
setGroupByExprs(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(String name) |
QueryConfig |
setOwner(String owner) |
QueryConfig |
setPredicate(String predicate)
Configure the predicate
|
QueryConfig |
setPredicate(String predicate,
int timePredicateInMillis)
Configure the predicate
|
QueryConfig |
setQuery(List<Schema.Field> fields,
String table,
String predicate)
Configure the table to query, the predicate and the result fields
|
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
|
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
|
QueryConfig |
setQuery(String table,
String predicate)
Configure the table to query and predicate
|
QueryConfig |
setQueryString(String query)
Configure the query using a single string, SQL-like syntax.
|
QueryConfig |
setQueryType(LiveViewQueryType queryType)
Configure the query type.
|
QueryConfig |
setSelectExprs(List<String> exprs)
Configure the result fields
|
QueryConfig |
setSelectExprs(String... exprs)
Configure the result fields
|
QueryConfig |
setSelectFields(List<Schema.Field> fields)
Configure the result fields
|
QueryConfig |
setSelectFields(Schema.Field... fields)
Configure the result fields
|
QueryConfig |
setTable(String table)
Configure the table to query
|
QueryConfig |
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.
|
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.QueryConfig getJaxbQueryConfig(QueryConfig config)
public static com.streambase.liveview.internal.protocol.jaxb.Query getJaxbQuery(QueryConfig config, boolean convertSnapOnlyToContinuousOnly)
public String getQuery()
public QueryConfig setTable(String table)
table
- the target table for this querypublic QueryConfig setPredicate(String predicate)
predicate
- the predicate to filter on, may be null to request all rowspublic QueryConfig setTimeWindow(String startTimeExpr, String endTimeExpr, 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 String getWindowStartTimeExpr()
public String getWindowEndTimeExpr()
public String getTimestampField()
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(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(List<Schema.Field> fields)
fields
- the fields to retrieve in the resultpublic QueryConfig setSelectExprs(String... exprs)
exprs
- the fields (as expressions) to retrieve in the resultpublic QueryConfig setSelectExprs(List<String> exprs)
exprs
- the fields (as expressions) to retrieve in the resultpublic List<String> getSelectExprs()
public QueryConfig setGroupByExprs(String... exprs)
exprs
- the group-by expressionspublic QueryConfig setGroupByExprs(List<String> groupByExprs)
groupByExprs
- the group-by expressionspublic List<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(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 QueryConfig setQuery(String table, String predicate)
table
- the table to querypredicate
- the predicate to filter on, may be null to request all rowspublic QueryConfig setQuery(List<Schema.Field> fields, String table, 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(List<Schema.Field> fields, String table, 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(List<Schema.Field> fields, String table, 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 String getTable()
public String getPredicate()
public long getTimePredicateInMillis()
public QueryConfig setTimePredicateInMillis(long ms)
public List<Schema.Field> getFields()
public int getLimit()
public LiveViewQueryType getQueryType()
public String getDescription()
public QueryConfig setDescription(String description)
description
- public Long getVersion()
public String getVersionString()
public String getName()
public QueryConfig setName(String name)
name
- public String getOwner()
public QueryConfig setOwner(String owner)
owner
- public XMLGregorianCalendar getCreated()
public XMLGregorianCalendar getLastUpdated()
public boolean getIncludeInternal()
public QueryConfig setIncludeInternal(boolean includeInternal)
includeInternal
-