Search in sources :

Example 1 with PartitionNode

use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode 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 PartitionNode

use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode 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 PartitionNode

use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode 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)

Example 4 with PartitionNode

use of org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode 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

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