Search in sources :

Example 1 with PartitionCompositeNode

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

the class PartitionExtractor method extractFromAnd.

/**
 * Extract partition information from AND.
 *
 * @param op Operation.
 * @param tblModel Table model.
 * @param disjunct Disjunction marker.
 * @return Partition.
 */
private PartitionNode extractFromAnd(GridSqlOperation op, PartitionTableModel tblModel, boolean disjunct) throws IgniteCheckedException {
    assert op.size() == 2;
    PartitionNode betweenNodes = tryExtractBetween(op, tblModel);
    if (betweenNodes != null)
        return betweenNodes;
    PartitionNode part1 = extractFromExpression(op.child(0), tblModel, disjunct);
    PartitionNode part2 = extractFromExpression(op.child(1), tblModel, disjunct);
    return new PartitionCompositeNode(part1, part2, PartitionCompositeNodeOperator.AND);
}
Also used : PartitionNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode) PartitionCompositeNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionCompositeNode)

Example 2 with PartitionCompositeNode

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

the class PartitionExtractor method extractFromOr.

/**
 * Extract partition information from OR.
 *
 * @param op Operation.
 * @param tblModel Table model.
 * @return Partition.
 */
private PartitionNode extractFromOr(GridSqlOperation op, PartitionTableModel tblModel) throws IgniteCheckedException {
    assert op.size() == 2;
    // Parse inner expressions recursively with disjuncion flag set.
    PartitionNode part1 = extractFromExpression(op.child(0), tblModel, true);
    PartitionNode part2 = extractFromExpression(op.child(1), tblModel, true);
    return new PartitionCompositeNode(part1, part2, PartitionCompositeNodeOperator.OR);
}
Also used : PartitionNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode) PartitionCompositeNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionCompositeNode)

Example 3 with PartitionCompositeNode

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

the class PartitionExtractor method mergeMapQueries.

/**
 * Merge partition info from multiple queries.
 *
 * @param qrys Queries.
 * @return Partition result or {@code null} if nothing is resolved.
 */
@SuppressWarnings("IfMayBeConditional")
public PartitionResult mergeMapQueries(List<GridCacheSqlQuery> qrys) {
    // Check if merge is possible.
    PartitionTableAffinityDescriptor aff = null;
    for (GridCacheSqlQuery qry : qrys) {
        PartitionResult qryRes = (PartitionResult) qry.derivedPartitions();
        // Failed to get results for one query -> broadcast.
        if (qryRes == null)
            return null;
        // This only possible if query is resolved to "NONE". Will be skipped later during map request prepare.
        if (qryRes.affinity() == null)
            continue;
        if (aff == null)
            aff = qryRes.affinity();
        else if (!aff.isCompatible(qryRes.affinity()))
            // Queries refer to incompatible affinity groups, cannot merge -> broadcast.
            return null;
    }
    // Merge.
    PartitionNode tree = null;
    AffinityTopologyVersion affinityTopVer = null;
    for (GridCacheSqlQuery qry : qrys) {
        PartitionResult qryRes = (PartitionResult) qry.derivedPartitions();
        if (tree == null)
            tree = qryRes.tree();
        else
            tree = new PartitionCompositeNode(tree, qryRes.tree(), PartitionCompositeNodeOperator.OR);
        if (affinityTopVer == null)
            affinityTopVer = qryRes.topologyVersion();
        else
            assert affinityTopVer.equals(qryRes.topologyVersion());
    }
    // Optimize.
    assert tree != null;
    tree = tree.optimize();
    if (tree instanceof PartitionAllNode)
        return null;
    // If there is no affinity, then we assume "NONE" result.
    assert aff != null || tree == PartitionNoneNode.INSTANCE;
    // TODO: during PartitionResult construction/application.
    assert affinityTopVer != null;
    return new PartitionResult(tree, aff, affinityTopVer);
}
Also used : PartitionAllNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionAllNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) PartitionNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode) GridCacheSqlQuery(org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery) PartitionResult(org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult) PartitionCompositeNode(org.apache.ignite.internal.sql.optimizer.affinity.PartitionCompositeNode) PartitionTableAffinityDescriptor(org.apache.ignite.internal.sql.optimizer.affinity.PartitionTableAffinityDescriptor)

Aggregations

PartitionCompositeNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionCompositeNode)3 PartitionNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridCacheSqlQuery (org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery)1 PartitionAllNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionAllNode)1 PartitionResult (org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult)1 PartitionTableAffinityDescriptor (org.apache.ignite.internal.sql.optimizer.affinity.PartitionTableAffinityDescriptor)1