Search in sources :

Example 1 with PartitionAllNode

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

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

PartitionAllNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionAllNode)2 PartitionNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode)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 PartitionCompositeNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionCompositeNode)1 PartitionTableAffinityDescriptor (org.apache.ignite.internal.sql.optimizer.affinity.PartitionTableAffinityDescriptor)1 PartitionTableModel (org.apache.ignite.internal.sql.optimizer.affinity.PartitionTableModel)1