Class SqlFieldsQuery
- java.lang.Object
-
- org.apache.ignite.cache.query.Query<List<?>>
-
- org.apache.ignite.cache.query.SqlFieldsQuery
-
- All Implemented Interfaces:
Serializable
public class SqlFieldsQuery extends Query<List<?>>
SQL Fields query. This query can return specific fields of data based on SQL'select'clause.Collocated Flag
Collocation flag is used for optimization purposes. Whenever Ignite executes a distributed query, it sends sub-queries to individual cluster members. If you know in advance that the elements of your query selection are collocated together on the same node, usually based on some affinity-key, Ignite can make significant performance and network optimizations.For example, in case of Word-Count example, we know that all identical words are processed on the same cluster member, because we use the
worditself as affinity key. This allows Ignite to execute the'limit'clause on the remote nodes and bring back only the small data set specified within the 'limit' clause, instead of the whole query result as would happen in a non-collocated execution.- See Also:
IgniteCache.query(Query), Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static booleanDFLT_LAZYDo not remove.-
Fields inherited from class org.apache.ignite.cache.query.Query
DFLT_PAGE_SIZE
-
-
Constructor Summary
Constructors Constructor Description SqlFieldsQuery(String sql)Constructs SQL fields query.SqlFieldsQuery(String sql, boolean collocated)Constructs SQL fields query.SqlFieldsQuery(SqlFieldsQuery qry)Copy constructs SQL fields query.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description SqlFieldsQuerycopy()Object[]getArgs()Gets SQL arguments.@org.jetbrains.annotations.Nullable int[]getPartitions()StringgetQueryInitiatorId()@Nullable StringgetSchema()Get schema for the query.StringgetSql()Gets SQL clause.intgetTimeout()Gets the query execution timeout in milliseconds.intgetUpdateBatchSize()Gets update internal bach size.booleanisCollocated()Checks if this query is collocated.booleanisDistributedJoins()Check if distributed joins are enabled for this query.booleanisEnforceJoinOrder()Checks if join order of tables if enforced.booleanisLazy()Deprecated.UseQuery.getPageSize()instead.booleanisReplicatedOnly()Deprecated.No longer used as of Apache Ignite 2.8.static voidresetThreadedQueryInitiatorId()Used at the job worker to clear originator for current thread.SqlFieldsQuerysetArgs(Object... args)Sets SQL arguments.SqlFieldsQuerysetCollocated(boolean collocated)Sets flag defining if this query is collocated.SqlFieldsQuerysetDistributedJoins(boolean distributedJoins)Specify if distributed joins are enabled for this query.SqlFieldsQuerysetEnforceJoinOrder(boolean enforceJoinOrder)Sets flag to enforce join order of tables in the query.SqlFieldsQuerysetLazy(boolean lazy)Deprecated.UsesetPageSize(int)instead.SqlFieldsQuerysetLocal(boolean loc)Sets whether this query should be executed on local node only.SqlFieldsQuerysetPageSize(int pageSize)Sets optional page size, if0, then default is used.SqlFieldsQuerysetPartitions(@org.jetbrains.annotations.Nullable int... parts)Sets partitions for a query.SqlFieldsQuerysetQueryInitiatorId(String qryInitiatorId)SqlFieldsQuerysetReplicatedOnly(boolean replicatedOnly)Deprecated.No longer used as of Apache Ignite 2.8.SqlFieldsQuerysetSchema(@Nullable String schema)Set schema for the query.SqlFieldsQuerysetSql(String sql)Sets SQL clause.static voidsetThreadedQueryInitiatorId(String originator)Used at the Job worker to setup originator by default for current thread.SqlFieldsQuerysetTimeout(int timeout, TimeUnit timeUnit)Sets the query execution timeout.SqlFieldsQuerysetUpdateBatchSize(int updateBatchSize)Sets update internal bach size.static StringthreadedQueryInitiatorId()StringtoString()-
Methods inherited from class org.apache.ignite.cache.query.Query
getPageSize, isLocal, prepare
-
-
-
-
Constructor Detail
-
SqlFieldsQuery
public SqlFieldsQuery(SqlFieldsQuery qry)
Copy constructs SQL fields query.- Parameters:
qry- SQL query.
-
SqlFieldsQuery
public SqlFieldsQuery(String sql)
Constructs SQL fields query.- Parameters:
sql- SQL query.
-
SqlFieldsQuery
public SqlFieldsQuery(String sql, boolean collocated)
Constructs SQL fields query.- Parameters:
sql- SQL query.collocated- Collocated flag.
-
-
Method Detail
-
getSql
public String getSql()
Gets SQL clause.- Returns:
- SQL clause.
-
setSql
public SqlFieldsQuery setSql(String sql)
Sets SQL clause.- Parameters:
sql- SQL clause.- Returns:
thisFor chaining.
-
getArgs
public Object[] getArgs()
Gets SQL arguments.- Returns:
- SQL arguments.
-
setArgs
public SqlFieldsQuery setArgs(Object... args)
Sets SQL arguments.- Parameters:
args- SQL arguments.- Returns:
thisFor chaining.
-
getTimeout
public int getTimeout()
Gets the query execution timeout in milliseconds.- Returns:
- Timeout value.
-
setTimeout
public SqlFieldsQuery setTimeout(int timeout, TimeUnit timeUnit)
Sets the query execution timeout. Query will be automatically cancelled if the execution timeout is exceeded.- Parameters:
timeout- Timeout value. Zero value disables timeout.timeUnit- Time unit.- Returns:
thisFor chaining.
-
isCollocated
public boolean isCollocated()
Checks if this query is collocated.- Returns:
trueIf the query is collocated.
-
setCollocated
public SqlFieldsQuery setCollocated(boolean collocated)
Sets flag defining if this query is collocated. Collocation flag is used for optimization purposes of queries with GROUP BY statements. Whenever Ignite executes a distributed query, it sends sub-queries to individual cluster members. If you know in advance that the elements of your query selection are collocated together on the same node and you group by collocated key (primary or affinity key), then Ignite can make significant performance and network optimizations by grouping data on remote nodes.- Parameters:
collocated- Flag value.- Returns:
thisFor chaining.
-
isEnforceJoinOrder
public boolean isEnforceJoinOrder()
Checks if join order of tables if enforced.- Returns:
- Flag value.
-
setEnforceJoinOrder
public SqlFieldsQuery setEnforceJoinOrder(boolean enforceJoinOrder)
Sets flag to enforce join order of tables in the query. If set totruequery optimizer will not reorder tables in join. By default isfalse.It is not recommended to enable this property until you are sure that your indexes and the query itself are correct and tuned as much as possible but query optimizer still produces wrong join order.
- Parameters:
enforceJoinOrder- Flag value.- Returns:
thisFor chaining.
-
setDistributedJoins
public SqlFieldsQuery setDistributedJoins(boolean distributedJoins)
Specify if distributed joins are enabled for this query.- Parameters:
distributedJoins- Distributed joins enabled.- Returns:
thisFor chaining.
-
isDistributedJoins
public boolean isDistributedJoins()
Check if distributed joins are enabled for this query.- Returns:
trueIf distributed joins enabled.
-
setPageSize
public SqlFieldsQuery setPageSize(int pageSize)
Sets optional page size, if0, then default is used.- Overrides:
setPageSizein classQuery<List<?>>- Parameters:
pageSize- Optional page size.- Returns:
thisfor chaining.
-
setLocal
public SqlFieldsQuery setLocal(boolean loc)
Sets whether this query should be executed on local node only.
-
setReplicatedOnly
@Deprecated public SqlFieldsQuery setReplicatedOnly(boolean replicatedOnly)
Deprecated.No longer used as of Apache Ignite 2.8.Specify if the query contains only replicated tables. This is a hint for potentially more effective execution.- Parameters:
replicatedOnly- The query contains only replicated tables.- Returns:
thisFor chaining.
-
isReplicatedOnly
@Deprecated public boolean isReplicatedOnly()
Deprecated.No longer used as of Apache Ignite 2.8.Check is the query contains only replicated tables.- Returns:
trueIf the query contains only replicated tables.
-
setLazy
public SqlFieldsQuery setLazy(boolean lazy)
Deprecated.UsesetPageSize(int)instead.Sets lazy query execution flag.If
lazy=falseIgnite will attempt to fetch the whole query result set to memory and send it to the client. For small and medium result sets this provides optimal performance and minimize duration of internal database locks, thus increasing concurrency.If result set is too big to fit in available memory this could lead to excessive GC pauses and even
OutOfMemoryError. Use this flag as a hint for Ignite to fetch result set lazily, thus minimizing memory consumption at the cost of moderate performance hit.Defaults to
true, meaning that the only first page of result set is fetched to memory.- Parameters:
lazy- Lazy query execution flag.- Returns:
thisFor chaining.
-
isLazy
public boolean isLazy()
Deprecated.UseQuery.getPageSize()instead.Gets lazy query execution flag.See
setLazy(boolean)for more information.- Returns:
- Lazy flag.
-
getPartitions
@Nullable public @org.jetbrains.annotations.Nullable int[] getPartitions()
- Returns:
- Partitions for query, in ascending order.
-
setPartitions
public SqlFieldsQuery setPartitions(@Nullable @org.jetbrains.annotations.Nullable int... parts)
Sets partitions for a query. The query will be executed only on nodes which are primary for specified partitions.Note what passed array'll be sorted in place for performance reasons, if it wasn't sorted yet.
- Parameters:
parts- Partitions.- Returns:
thisfor chaining.
-
getSchema
@Nullable public @Nullable String getSchema()
Get schema for the query. If not set, current cache name is used, which means you can omit schema name for tables within the current cache.- Returns:
- Schema. Null if schema is not set.
-
setSchema
public SqlFieldsQuery setSchema(@Nullable @Nullable String schema)
Set schema for the query. If not set, current cache name is used, which means you can omit schema name for tables within the current cache.- Parameters:
schema- Schema. Null to unset schema.- Returns:
thisfor chaining.
-
getUpdateBatchSize
public int getUpdateBatchSize()
Gets update internal bach size. Default is 1 to prevent deadlock on update where keys sequence are different in several concurrent updates.- Returns:
- Update internal batch size
-
setUpdateBatchSize
public SqlFieldsQuery setUpdateBatchSize(int updateBatchSize)
Sets update internal bach size. Default is 1 to prevent deadlock on update where keys sequence are different in several concurrent updates.- Parameters:
updateBatchSize- Update internal batch size.- Returns:
thisfor chaining.
-
getQueryInitiatorId
public String getQueryInitiatorId()
- Returns:
- Query's initiator identifier string (client host+port, user name, job name or any user's information about query initiator).
-
setQueryInitiatorId
public SqlFieldsQuery setQueryInitiatorId(String qryInitiatorId)
- Parameters:
qryInitiatorId- Query's initiator identifier string (client host+port, user name, job name or any user's information about query initiator).- Returns:
thisfor chaining.
-
copy
public SqlFieldsQuery copy()
- Returns:
- Copy of this query.
-
setThreadedQueryInitiatorId
public static void setThreadedQueryInitiatorId(String originator)
Used at the Job worker to setup originator by default for current thread.- Parameters:
originator- Query's originator string.
-
resetThreadedQueryInitiatorId
public static void resetThreadedQueryInitiatorId()
Used at the job worker to clear originator for current thread.
-
threadedQueryInitiatorId
public static String threadedQueryInitiatorId()
- Returns:
- originator set up by the job worker.
-
-