Search in sources :

Example 1 with PartitionTableAffinityDescriptor

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

the class PartitionExtractor method prepareTable.

/**
 * Prepare single table.
 *
 * @param from Expression.
 * @param tblModel Table model.
 * @return Added table or {@code null} if table is exlcuded from the model.
 */
private static PartitionTable prepareTable(GridSqlAst from, PartitionTableModel tblModel) {
    // Unwrap alias. We assume that every table must be aliased.
    assert from instanceof GridSqlAlias;
    String alias = ((GridSqlAlias) from).alias();
    from = from.child();
    if (from instanceof GridSqlTable) {
        // Normal table.
        GridSqlTable from0 = (GridSqlTable) from;
        GridH2Table tbl0 = from0.dataTable();
        // Unknown table type, e.g. temp table.
        if (tbl0 == null) {
            tblModel.addExcludedTable(alias);
            return null;
        }
        String cacheName = tbl0.cacheName();
        String affColName = null;
        String secondAffColName = null;
        for (Column col : tbl0.getColumns()) {
            if (tbl0.isColumnForPartitionPruningStrict(col)) {
                if (affColName == null)
                    affColName = col.getName();
                else {
                    secondAffColName = col.getName();
                    // Break as we cannot have more than two affinity key columns.
                    break;
                }
            }
        }
        PartitionTable tbl = new PartitionTable(alias, cacheName, affColName, secondAffColName);
        PartitionTableAffinityDescriptor aff = affinityForCache(tbl0.cacheInfo().config());
        if (aff == null) {
            // Non-standard affinity, exclude table.
            tblModel.addExcludedTable(alias);
            return null;
        }
        tblModel.addTable(tbl, aff);
        return tbl;
    } else {
        // Subquery/union/view, etc.
        assert alias != null;
        tblModel.addExcludedTable(alias);
        return null;
    }
}
Also used : PartitionTable(org.apache.ignite.internal.sql.optimizer.affinity.PartitionTable) GridSqlAlias(org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlias) Column(org.h2.table.Column) GridSqlColumn(org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn) GridSqlTable(org.apache.ignite.internal.processors.query.h2.sql.GridSqlTable) GridH2Table(org.apache.ignite.internal.processors.query.h2.opt.GridH2Table) PartitionTableAffinityDescriptor(org.apache.ignite.internal.sql.optimizer.affinity.PartitionTableAffinityDescriptor)

Example 2 with PartitionTableAffinityDescriptor

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

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

the class PartitionExtractor method affinityForCache.

/**
 * Prepare affinity identifier for cache.
 *
 * @param ccfg Cache configuration.
 * @return Affinity identifier.
 */
private static PartitionTableAffinityDescriptor affinityForCache(CacheConfiguration ccfg) {
    // Partition could be extracted only from PARTITIONED caches.
    if (ccfg.getCacheMode() != CacheMode.PARTITIONED)
        return null;
    PartitionAffinityFunctionType aff = ccfg.getAffinity().getClass().equals(RendezvousAffinityFunction.class) ? PartitionAffinityFunctionType.RENDEZVOUS : PartitionAffinityFunctionType.CUSTOM;
    boolean hasNodeFilter = ccfg.getNodeFilter() != null && !(ccfg.getNodeFilter() instanceof CacheConfiguration.IgniteAllNodesPredicate);
    return new PartitionTableAffinityDescriptor(aff, ccfg.getAffinity().partitions(), hasNodeFilter, ccfg.getDataRegionName());
}
Also used : PartitionAffinityFunctionType(org.apache.ignite.internal.sql.optimizer.affinity.PartitionAffinityFunctionType) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PartitionTableAffinityDescriptor(org.apache.ignite.internal.sql.optimizer.affinity.PartitionTableAffinityDescriptor)

Aggregations

PartitionTableAffinityDescriptor (org.apache.ignite.internal.sql.optimizer.affinity.PartitionTableAffinityDescriptor)3 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 GridCacheSqlQuery (org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery)1 GridH2Table (org.apache.ignite.internal.processors.query.h2.opt.GridH2Table)1 GridSqlAlias (org.apache.ignite.internal.processors.query.h2.sql.GridSqlAlias)1 GridSqlColumn (org.apache.ignite.internal.processors.query.h2.sql.GridSqlColumn)1 GridSqlTable (org.apache.ignite.internal.processors.query.h2.sql.GridSqlTable)1 PartitionAffinityFunctionType (org.apache.ignite.internal.sql.optimizer.affinity.PartitionAffinityFunctionType)1 PartitionAllNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionAllNode)1 PartitionCompositeNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionCompositeNode)1 PartitionNode (org.apache.ignite.internal.sql.optimizer.affinity.PartitionNode)1 PartitionResult (org.apache.ignite.internal.sql.optimizer.affinity.PartitionResult)1 PartitionTable (org.apache.ignite.internal.sql.optimizer.affinity.PartitionTable)1 Column (org.h2.table.Column)1