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;
}
}
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);
}
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());
}
Aggregations