org.apache.ignite.cache.query

## Class SqlFieldsQuery

- java.lang.Object
- - org.apache.ignite.cache.query.Query<List<?>>
  - - org.apache.ignite.cache.query.SqlFieldsQuery

All Implemented Interfaces:
  Serializable

Direct Known Subclasses:
  JdbcSqlFieldsQuery

    public class SqlFieldsQuery
    extends Query<List<?>>

SQL Fields query. This query can return specific fields of data based on SQL `'select'` clause, as opposed to `SqlQuery`, which always returns the whole key and value objects back.

# 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 `word` itself 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 inherited from class org.apache.ignite.cache.query.Query

`DFLT_PAGE_SIZE`

### Constructor Summary

Constructors
Constructor and Description
`SqlFieldsQuery(String sql)` Constructs SQL fields query.
`SqlFieldsQuery(String sql, boolean collocated)` Constructs SQL fields query.

### Method Summary

Methods
`Object[]` `getArgs()` Gets SQL arguments.
`int[]` `getPartitions()` Gets partitions for query, in ascending order.
`String` `getSql()` Gets SQL clause.
`int` `getTimeout()` Gets the query execution timeout in milliseconds.
`boolean` `isCollocated()` Checks if this query is collocated.
`boolean` `isDistributedJoins()` Check if distributed joins are enabled for this query.
`boolean` `isEnforceJoinOrder()` Checks if join order of tables if enforced.
`boolean` `isReplicatedOnly()` Check is the query contains only replicated tables.
`SqlFieldsQuery` `setArgs(Object... args)` Sets SQL arguments.
`SqlFieldsQuery` `setCollocated(boolean collocated)` Sets flag defining if this query is collocated.
`SqlFieldsQuery` `setDistributedJoins(boolean distributedJoins)` Specify if distributed joins are enabled for this query.
`SqlFieldsQuery` `setEnforceJoinOrder(boolean enforceJoinOrder)` Sets flag to enforce join order of tables in the query.
`SqlFieldsQuery` `setLocal(boolean loc)` Sets whether this query should be executed on local node only.
`SqlFieldsQuery` `setPageSize(int pageSize)` Sets optional page size, if `0`, then default is used.
`SqlFieldsQuery` `setPartitions(int... parts)` Sets partitions for a query.
`SqlFieldsQuery` `setReplicatedOnly(boolean replicatedOnly)` Specify if the query contains only replicated tables.
`SqlFieldsQuery` `setSql(String sql)` Sets SQL clause.
`SqlFieldsQuery` `setTimeout(int timeout, TimeUnit timeUnit)` Sets the query execution timeout.
`String` `toString()`

### Methods inherited from class org.apache.ignite.cache.query.Query

`getPageSize, isLocal, prepare`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### 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:
  `this` For 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:
  `this` For 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:
  `this` For chaining.

#### isCollocated

    public boolean isCollocated()

Checks if this query is collocated.

Returns:
  `true` If 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:
  `this` For 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 to `true` query optimizer will not reorder tables in join. By default is `false`.

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:
  `this` For chaining.

#### setDistributedJoins

    public SqlFieldsQuery setDistributedJoins(boolean distributedJoins)

Specify if distributed joins are enabled for this query.

Parameters:
  `distributedJoins` - Distributed joins enabled.
Returns:
  `this` For chaining.

#### isDistributedJoins

    public boolean isDistributedJoins()

Check if distributed joins are enabled for this query.

Returns:
  `true` If distributed joind enabled.

#### setPageSize

    public SqlFieldsQuery setPageSize(int pageSize)

Sets optional page size, if `0`, then default is used.

Overrides:
  `setPageSize` in class `Query<List<?>>`
Parameters:
  `pageSize` - Optional page size.
Returns:
  `this` for chaining.

#### setLocal

    public SqlFieldsQuery setLocal(boolean loc)

Sets whether this query should be executed on local node only.

Overrides:
  `setLocal` in class `Query<List<?>>`
Parameters:
  `loc` - Local flag.
Returns:
  `this` for chaining.

#### setReplicatedOnly

    public SqlFieldsQuery setReplicatedOnly(boolean replicatedOnly)

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:
  `this` For chaining.

#### isReplicatedOnly

    public boolean isReplicatedOnly()

Check is the query contains only replicated tables.

Returns:
  `true` If the query contains only replicated tables.

#### getPartitions

    @Nullable
    public int[] getPartitions()

Gets partitions for query, in ascending order.

#### setPartitions

    public SqlFieldsQuery setPartitions(@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:
  `this` for chaining.

#### toString

    public String toString()

Overrides:
  `toString` in class `Query<List<?>>`

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.0.0
Release Date | : April 30 2017