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