Search in sources :

Example 6 with PartitionResult

use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult in project ignite by apache.

the class JdbcThinConnection method updateAffinityCache.

/**
 * Recreates affinity cache if affinity topology version was changed and adds partition result to sql cache.
 *
 * @param qryReq Query request.
 * @param res Jdbc Response.
 */
private void updateAffinityCache(JdbcQueryExecuteRequest qryReq, JdbcResponse res) {
    if (partitionAwareness) {
        AffinityTopologyVersion resAffVer = res.affinityVersion();
        if (resAffVer != null && (affinityCache == null || affinityCache.version().compareTo(resAffVer) < 0)) {
            affinityCache = new AffinityCache(resAffVer, connProps.getPartitionAwarenessPartitionDistributionsCacheSize(), connProps.getPartitionAwarenessSqlCacheSize());
        }
        // Partition result was requested.
        if (res.response() instanceof JdbcQueryExecuteResult && qryReq.partitionResponseRequest()) {
            PartitionResult partRes = ((JdbcQueryExecuteResult) res.response()).partitionResult();
            if (partRes == null || affinityCache.version().equals(partRes.topologyVersion())) {
                int cacheId = (partRes != null && partRes.tree() != null) ? GridCacheUtils.cacheId(partRes.cacheName()) : -1;
                PartitionClientContext partClientCtx = partRes != null ? new PartitionClientContext(partRes.partitionsCount()) : null;
                QualifiedSQLQuery qry = new QualifiedSQLQuery(qryReq.schemaName(), qryReq.sqlQuery());
                JdbcThinPartitionResultDescriptor partResDescr = new JdbcThinPartitionResultDescriptor(partRes, cacheId, partClientCtx);
                affinityCache.addSqlQuery(qry, partResDescr);
            }
        }
    }
}
Also used : PartitionClientContext(org.apache.ignite.internal.sql.optimizer.affinity.PartitionClientContext) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) JdbcQueryExecuteResult(org.apache.ignite.internal.processors.odbc.jdbc.JdbcQueryExecuteResult) PartitionResult(org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult) Savepoint(java.sql.Savepoint)

Example 7 with PartitionResult

use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult in project ignite by apache.

the class PartitionExtractor method extract.

/**
 * Extract partitions.
 *
 * @param qry Query.
 * @return Partitions.
 */
public PartitionResult extract(GridSqlQuery qry) throws IgniteCheckedException {
    // No unions support yet.
    if (!(qry instanceof GridSqlSelect))
        return null;
    GridSqlSelect select = (GridSqlSelect) qry;
    // Prepare table model.
    PartitionTableModel tblModel = prepareTableModel(select.from());
    // Do extract.
    PartitionNode tree = extractFromExpression(select.where(), tblModel, false);
    assert tree != null;
    // Reduce tree if possible.
    tree = tree.optimize();
    if (tree instanceof PartitionAllNode)
        return null;
    // Done.
    return new PartitionResult(tree, tblModel.joinGroupAffinity(tree.joinGroup()), ctx.cache().context().exchange().readyAffinityVersion());
}
Also used : PartitionAllNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionAllNode) PartitionNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode) PartitionTableModel(org.apache.ignite.internal.sql.optimizer.affinity.PartitionTableModel) PartitionResult(org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult) GridSqlSelect(org.apache.ignite.internal.processors.query.h2.sql.GridSqlSelect)

Aggregations

PartitionResult (org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult)7 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 PartitionAllNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionAllNode)2 PartitionNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode)2 BatchUpdateException (java.sql.BatchUpdateException)1 ResultSet (java.sql.ResultSet)1 Savepoint (java.sql.Savepoint)1 Collections.singletonList (java.util.Collections.singletonList)1 Iterator (java.util.Iterator)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 BulkLoadContextCursor (org.apache.ignite.cache.query.BulkLoadContextCursor)1 FieldsQueryCursor (org.apache.ignite.cache.query.FieldsQueryCursor)1 QueryCancelledException (org.apache.ignite.cache.query.QueryCancelledException)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 AffinityCache (org.apache.ignite.internal.jdbc.thin.AffinityCache)1 QualifiedSQLQuery (org.apache.ignite.internal.jdbc.thin.QualifiedSQLQuery)1 BulkLoadAckClientParameters (org.apache.ignite.internal.processors.bulkload.BulkLoadAckClientParameters)1 BulkLoadProcessor (org.apache.ignite.internal.processors.bulkload.BulkLoadProcessor)1