org.apache.ignite.internal.processors.query

## Interface GridQueryIndexing

    public interface GridQueryIndexing

Abstraction for internal indexing implementation.

### Method Summary

All Methods Instance Methods Abstract Methods
`IndexingQueryFilter` `backupFilter(AffinityTopologyVersion topVer, int[] parts)` Returns backup filter.
`void` `cancelAllQueries()` Cancels all executing queries.
`void` `cancelQueries(Collection<Long> queries)` Cancel specified queries.
`void` `checkStatementStreamable(PreparedStatement nativeStmt)` Check if passed statement is insert statement eligible for streaming, throw an `IgniteSQLException` if not.
`void` `dynamicAddColumn(String schemaName, String tblName, List<QueryField> cols, boolean ifTblExists, boolean ifColNotExists)` Add columns to dynamic table.
`void` `dynamicDropColumn(String schemaName, String tblName, List<String> cols, boolean ifTblExists, boolean ifColExists)` Drop columns from dynamic table.
`void` `dynamicIndexCreate(String schemaName, String tblName, QueryIndexDescriptorImpl idxDesc, boolean ifNotExists, SchemaIndexCacheVisitor cacheVisitor)` Create new index locally.
`void` `dynamicIndexDrop(String schemaName, String idxName, boolean ifExists)` Remove index from the cache.
`void` `markForRebuildFromHash(String cacheName)` Marks all indexes of given type for rebuild from hash index, making them unusable until rebuild finishes.
`void` `onClientDisconnect()` Performs necessary actions on disconnect of a stateful client (say, one associated with a transaction).
`void` `onDisconnected(IgniteFuture<?> reconnectFut)` Client disconnected callback.
`UpdateSourceIterator<?>` `prepareDistributedUpdate(GridCacheContext<?,?> cctx, int[] ids, int[] parts, String schema, String qry, Object[] params, int flags, int pageSize, int timeout, AffinityTopologyVersion topVer, MvccSnapshot mvccSnapshot, GridQueryCancel cancel)`
`PreparedStatement` `prepareNativeStatement(String schemaName, String sql)` Prepare native statement to retrieve JDBC metadata from.
`<K,V> QueryCursor<javax.cache.Cache.Entry<K,V>>` `queryDistributedSql(String schemaName, String cacheName, SqlQuery qry, boolean keepBinary)` Parses SQL query into two step query and executes it.
`<K,V> QueryCursor<javax.cache.Cache.Entry<K,V>>` `queryLocalSql(String schemaName, String cacheName, SqlQuery qry, IndexingQueryFilter filter, boolean keepBinary)` Executes regular query.
`FieldsQueryCursor<List<?>>` `queryLocalSqlFields(String schemaName, SqlFieldsQuery qry, boolean keepBinary, IndexingQueryFilter filter, GridQueryCancel cancel)` Queries individual fields (generally used by JDBC drivers).
`<K,V> GridCloseableIterator<IgniteBiTuple<K,V>>` `queryLocalText(String schemaName, String cacheName, String qry, String typeName, IndexingQueryFilter filter)` Executes text query.
`List<FieldsQueryCursor<List<?>>>` `querySqlFields(String schemaName, SqlFieldsQuery qry, SqlClientContext cliCtx, boolean keepBinary, boolean failOnMultipleStmts, MvccQueryTracker tracker, GridQueryCancel cancel)` Detect whether SQL query should be executed in distributed or local manner and execute it.
`void` `rebuildIndexesFromHash(String cacheName)` Rebuilds all indexes of given type from hash index.
`void` `registerCache(String cacheName, String schemaName, GridCacheContext<?,?> cctx)` Registers cache.
`boolean` `registerType(GridCacheContext cctx, GridQueryTypeDescriptor desc)` Registers type if it was not known before or updates it otherwise.
`void` `remove(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row)` Removes index entry by key.
`GridQueryRowCacheCleaner` `rowCacheCleaner(int cacheGroupId)` Return row cache cleaner.
`Collection<GridRunningQueryInfo>` `runningQueries(long duration)` Collect queries that already running more than specified duration.
`String` `schema(String cacheName)` Gets database schema from cache name.
`void` `start(GridKernalContext ctx, GridSpinBusyLock busyLock)` Starts indexing.
`void` `stop()` Stops indexing.
`void` `store(GridCacheContext cctx, GridQueryTypeDescriptor type, CacheDataRow row, CacheDataRow prevRow, boolean prevRowAvailable)` Updates index.
`List<Long>` `streamBatchedUpdateQuery(String schemaName, String qry, List<Object[]> params, SqlClientContext cliCtx)` Execute a batched INSERT statement using data streamer as receiver.
`long` `streamUpdateQuery(String schemaName, String qry, Object[] params, IgniteDataStreamer<?,?> streamer)` Execute an INSERT statement using data streamer as receiver.
`void` `unregisterCache(GridCacheContext cctx, boolean rmvIdx)` Unregisters cache.

### Method Detail

#### start

    void start(GridKernalContext ctx,
               GridSpinBusyLock busyLock)
        throws IgniteCheckedException

Starts indexing.

Parameters:
  `ctx` - Context.
  `busyLock` - Busy lock.
Throws:
  `IgniteCheckedException` - If failed.

#### stop

    void stop()
       throws IgniteCheckedException

Stops indexing.

Throws:
  `IgniteCheckedException` - If failed.

#### onClientDisconnect

    void onClientDisconnect()
                     throws IgniteCheckedException

Performs necessary actions on disconnect of a stateful client (say, one associated with a transaction).

Throws:
  `IgniteCheckedException` - If failed.

#### queryDistributedSql

    <K,V> QueryCursor<javax.cache.Cache.Entry<K,V>> queryDistributedSql(String schemaName,
                                                                        String cacheName,
                                                                        SqlQuery qry,
                                                                        boolean keepBinary)
                                                                 throws IgniteCheckedException

Parses SQL query into two step query and executes it.

Parameters:
  `schemaName` - Schema name.
  `cacheName` - Cache name.
  `qry` - Query.
  `keepBinary` - Keep binary flag.
Throws:
  `IgniteCheckedException` - If failed.

#### querySqlFields

    List<FieldsQueryCursor<List<?>>> querySqlFields(String schemaName,
                                                    SqlFieldsQuery qry,
                                                    SqlClientContext cliCtx,
                                                    boolean keepBinary,
                                                    boolean failOnMultipleStmts,
                                                    MvccQueryTracker tracker,
                                                    GridQueryCancel cancel)

Detect whether SQL query should be executed in distributed or local manner and execute it.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `cliCtx` - Client context.
  `keepBinary` - Keep binary flag.
  `failOnMultipleStmts` - Whether an exception should be thrown for multiple statements query.
  `tracker` - Query tracker.
Returns:
  Cursor.

#### streamUpdateQuery

    long streamUpdateQuery(String schemaName,
                           String qry,
                           @Nullable
                           Object[] params,
                           IgniteDataStreamer<?,?> streamer)
                    throws IgniteCheckedException

Execute an INSERT statement using data streamer as receiver.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `params` - Query parameters.
  `streamer` - Data streamer to feed data to.
Returns:
  Update counter.
Throws:
  `IgniteCheckedException` - If failed.

#### streamBatchedUpdateQuery

    List<Long> streamBatchedUpdateQuery(String schemaName,
                                        String qry,
                                        List<Object[]> params,
                                        SqlClientContext cliCtx)
                                 throws IgniteCheckedException

Execute a batched INSERT statement using data streamer as receiver.

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `params` - Query parameters.
  `cliCtx` - Client connection context.
Returns:
  Update counters.
Throws:
  `IgniteCheckedException` - If failed.

#### queryLocalSql

    <K,V> QueryCursor<javax.cache.Cache.Entry<K,V>> queryLocalSql(String schemaName,
                                                                  String cacheName,
                                                                  SqlQuery qry,
                                                                  IndexingQueryFilter filter,
                                                                  boolean keepBinary)
                                                           throws IgniteCheckedException

Executes regular query.

Parameters:
  `schemaName` - Schema name.
  `cacheName` - Cache name.
  `qry` - Query.
  `filter` - Cache name and key filter.
  `keepBinary` - Keep binary flag. @return Cursor.
Throws:
  `IgniteCheckedException`

#### queryLocalSqlFields

    FieldsQueryCursor<List<?>> queryLocalSqlFields(String schemaName,
                                                   SqlFieldsQuery qry,
                                                   boolean keepBinary,
                                                   IndexingQueryFilter filter,
                                                   GridQueryCancel cancel)
                                            throws IgniteCheckedException

Queries individual fields (generally used by JDBC drivers).

Parameters:
  `schemaName` - Schema name.
  `qry` - Query.
  `keepBinary` - Keep binary flag.
  `filter` - Cache name and key filter.
  `cancel` - Query cancel.
Returns:
  Cursor.
Throws:
  `IgniteCheckedException`

#### queryLocalText

    <K,V> GridCloseableIterator<IgniteBiTuple<K,V>> queryLocalText(String schemaName,
                                                                   String cacheName,
                                                                   String qry,
                                                                   String typeName,
                                                                   IndexingQueryFilter filter)
                                                            throws IgniteCheckedException

Executes text query.

Parameters:
  `schemaName` - Schema name.
  `cacheName` - Cache name.
  `qry` - Text query.
  `typeName` - Type name.
  `filter` - Cache name and key filter. @return Queried rows.
Throws:
  `IgniteCheckedException` - If failed.

#### dynamicIndexCreate

    void dynamicIndexCreate(String schemaName,
                            String tblName,
                            QueryIndexDescriptorImpl idxDesc,
                            boolean ifNotExists,
                            SchemaIndexCacheVisitor cacheVisitor)
                     throws IgniteCheckedException

Create new index locally.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
  `idxDesc` - Index descriptor.
  `ifNotExists` - Ignore operation if index exists (instead of throwing an error).
  `cacheVisitor` - Cache visitor
Throws:
  `IgniteCheckedException` - if failed.

#### dynamicIndexDrop

    void dynamicIndexDrop(String schemaName,
                          String idxName,
                          boolean ifExists)
                   throws IgniteCheckedException

Remove index from the cache.

Parameters:
  `schemaName` - Schema name.
  `idxName` - Index name.
  `ifExists` - Ignore operation if index does not exist (instead of throwing an error).
Throws:
  `IgniteCheckedException` - If failed.

#### dynamicAddColumn

    void dynamicAddColumn(String schemaName,
                          String tblName,
                          List<QueryField> cols,
                          boolean ifTblExists,
                          boolean ifColNotExists)
                   throws IgniteCheckedException

Add columns to dynamic table.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
  `cols` - Columns to add.
  `ifTblExists` - Ignore operation if target table does not exist (instead of throwing an error).
  `ifColNotExists` - Ignore operation if column already exists (instead of throwing an error) - is honored only for single column case.
Throws:
  `IgniteCheckedException` - If failed.

#### dynamicDropColumn

    void dynamicDropColumn(String schemaName,
                           String tblName,
                           List<String> cols,
                           boolean ifTblExists,
                           boolean ifColExists)
                    throws IgniteCheckedException

Drop columns from dynamic table.

Parameters:
  `schemaName` - Schema name.
  `tblName` - Table name.
  `cols` - Columns to drop.
  `ifTblExists` - Ignore operation if target table does not exist (instead of throwing an error).
  `ifColExists` - Ignore operation if column does not exist (instead of throwing an error) - is honored only for single column case.
Throws:
  `IgniteCheckedException` - If failed.

#### registerCache

    void registerCache(String cacheName,
                       String schemaName,
                       GridCacheContext<?,?> cctx)
                throws IgniteCheckedException

Registers cache.

Parameters:
  `cacheName` - Cache name.
  `schemaName` - Schema name.
  `cctx` - Cache context.
Throws:
  `IgniteCheckedException` - If failed.

#### unregisterCache

    void unregisterCache(GridCacheContext cctx,
                         boolean rmvIdx)
                  throws IgniteCheckedException

Unregisters cache.

Parameters:
  `cctx` - Cache context.
  `rmvIdx` - If `true`, will remove index.
Throws:
  `IgniteCheckedException` - If failed to drop cache schema.

#### prepareDistributedUpdate

    UpdateSourceIterator<?> prepareDistributedUpdate(GridCacheContext<?,?> cctx,
                                                     int[] ids,
                                                     int[] parts,
                                                     String schema,
                                                     String qry,
                                                     Object[] params,
                                                     int flags,
                                                     int pageSize,
                                                     int timeout,
                                                     AffinityTopologyVersion topVer,
                                                     MvccSnapshot mvccSnapshot,
                                                     GridQueryCancel cancel)
                                              throws IgniteCheckedException

Parameters:
  `cctx` - Cache context.
  `ids` - Involved cache ids.
  `parts` - Partitions.
  `schema` - Schema name.
  `qry` - Query string.
  `params` - Query parameters.
  `flags` - Flags.
  `pageSize` - Fetch page size.
  `timeout` - Timeout.
  `topVer` - Topology version.
  `mvccSnapshot` - MVCC snapshot.
  `cancel` - Query cancel object.
Returns:
  Cursor over entries which are going to be changed.
Throws:
  `IgniteCheckedException` - If failed.

#### registerType

    boolean registerType(GridCacheContext cctx,
                         GridQueryTypeDescriptor desc)
                  throws IgniteCheckedException

Registers type if it was not known before or updates it otherwise.

Parameters:
  `cctx` - Cache context.
  `desc` - Type descriptor.
Returns:
  `True` if type was registered, `false` if for some reason it was rejected.
Throws:
  `IgniteCheckedException` - If failed.

#### store

    void store(GridCacheContext cctx,
               GridQueryTypeDescriptor type,
               CacheDataRow row,
               CacheDataRow prevRow,
               boolean prevRowAvailable)
        throws IgniteCheckedException

Updates index. Note that key is unique for cache, so if cache contains multiple indexes the key should be removed from indexes other than one being updated.

Parameters:
  `cctx` - Cache context.
  `type` - Type descriptor.
  `row` - New row.
  `prevRow` - Previous row.
  `prevRowAvailable` - Whether previous row is available.
Throws:
  `IgniteCheckedException` - If failed.

#### remove

    void remove(GridCacheContext cctx,
                GridQueryTypeDescriptor type,
                CacheDataRow row)
         throws IgniteCheckedException

Removes index entry by key.

Parameters:
  `cctx` - Cache context.
  `type` - Type descriptor.
  `row` - Row.
Throws:
  `IgniteCheckedException` - If failed.

#### rebuildIndexesFromHash

    void rebuildIndexesFromHash(String cacheName)
                         throws IgniteCheckedException

Rebuilds all indexes of given type from hash index.

Parameters:
  `cacheName` - Cache name.
Throws:
  `IgniteCheckedException` - If failed.

#### markForRebuildFromHash

    void markForRebuildFromHash(String cacheName)

Marks all indexes of given type for rebuild from hash index, making them unusable until rebuild finishes.

Parameters:
  `cacheName` - Cache name.

#### backupFilter

    IndexingQueryFilter backupFilter(AffinityTopologyVersion topVer,
                                     int[] parts)

Returns backup filter.

Parameters:
  `topVer` - Topology version.
  `parts` - Partitions.
Returns:
  Backup filter.

#### onDisconnected

    void onDisconnected(IgniteFuture<?> reconnectFut)

Client disconnected callback.

Parameters:
  `reconnectFut` - Reconnect future.

#### prepareNativeStatement

    PreparedStatement prepareNativeStatement(String schemaName,
                                             String sql)
                                      throws SQLException

Prepare native statement to retrieve JDBC metadata from.

Parameters:
  `schemaName` - Schema name.
  `sql` - Query.
Returns:
  `PreparedStatement` from underlying engine to supply metadata to Prepared - most likely H2.
Throws:
  `SQLException`

#### runningQueries

    Collection<GridRunningQueryInfo> runningQueries(long duration)

Collect queries that already running more than specified duration.

Parameters:
  `duration` - Duration to check.
Returns:
  Collection of long running queries.

#### cancelQueries

    void cancelQueries(Collection<Long> queries)

Cancel specified queries.

Parameters:
  `queries` - Queries ID's to cancel.

#### cancelAllQueries

    void cancelAllQueries()

Cancels all executing queries.

#### schema

    String schema(String cacheName)

Gets database schema from cache name.

Parameters:
  `cacheName` - Cache name. `null` would be converted to an empty string.
Returns:
  Schema name. Should not be null since we should not fail for an invalid cache name.

#### checkStatementStreamable

    void checkStatementStreamable(PreparedStatement nativeStmt)

Check if passed statement is insert statement eligible for streaming, throw an `IgniteSQLException` if not.

Parameters:
  `nativeStmt` - Native statement.

#### rowCacheCleaner

    GridQueryRowCacheCleaner rowCacheCleaner(int cacheGroupId)

Return row cache cleaner.

Parameters:
  `cacheGroupId` - Cache group id.
Returns:
  Row cache cleaner.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.5
Release Date | : June 4 2019