private static RelNode getSortOrTopN(IndexCallContext indexContext, RelNode sortNode, RelNode newRel, RelNode child) { if (sortNode instanceof TopNPrel) { return new TopNPrel(sortNode.getCluster(), newRel.getTraitSet().replace(Prel.DRILL_PHYSICAL).plus(indexContext.getCollation()), child, ((TopNPrel)sortNode).getLimit(), indexContext.getCollation()); } return new SortPrel(sortNode.getCluster(), newRel.getTraitSet().replace(Prel.DRILL_PHYSICAL).plus(indexContext.getCollation()), child, indexContext.getCollation()); }
public static RelNode getExchange(RelOptCluster cluster, boolean isSingleton, boolean isExchangeRequired, RelTraitSet traits, DrillDistributionTrait distributionTrait, IndexCallContext indexContext, RelNode input) { if (!isExchangeRequired) { return input; } if (isSingleton) { return new SingleMergeExchangePrel(cluster, traits.replace(DrillDistributionTrait.SINGLETON), input, indexContext.getCollation()); } else { return new HashToMergeExchangePrel(cluster, traits.replace(distributionTrait), input, distributionTrait.getFields(), indexContext.getCollation(), PrelUtil.getSettings(cluster).numEndPoints()); } }
ImmutableList.copyOf(indexContext.getDistributionFields())); if ( toRemoveSort(indexContext.getCollation(), newRel.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE))) { newRel.getTraitSet().plus(indexContext.getCollation()).plus(Prel.DRILL_PHYSICAL), newRel, IndexPlanUtils.getOffset(rel), IndexPlanUtils.getFetch(rel)); RelTraitSet traits = newRel.getTraitSet().plus(indexContext.getCollation()).plus(Prel.DRILL_PHYSICAL); newRel = Prule.convert(newRel, traits); newRel = getExchange(newRel.getCluster(), isSingleton, isExchangeRequired, return null; RelTraitSet traits = newRel.getTraitSet().plus(indexContext.getCollation()).plus(Prel.DRILL_PHYSICAL); newRel = getSortOrTopN(indexContext, rel, newRel, Prule.convert(newRel, newRel.getTraitSet().replace(Prel.DRILL_PHYSICAL)));
private boolean buildAndCheckCollation(IndexProperties indexProps) { IndexDescriptor indexDesc = indexProps.getIndexDesc(); FunctionalIndexInfo functionInfo = indexDesc.getFunctionalInfo(); RelCollation inputCollation; // for the purpose of collation we can assume that a covering index scan would provide // the collation property that would be relevant for non-covering as well ScanPrel indexScanPrel = IndexPlanUtils.buildCoveringIndexScan(indexContext.getScan(), indexDesc.getIndexGroupScan(), indexContext, indexDesc); inputCollation = indexScanPrel.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE); // we don't create collation for Filter because it will inherit the child's collation if (indexContext.hasLowerProject()) { inputCollation = IndexPlanUtils.buildCollationProject(indexContext.getLowerProject().getProjects(), null, indexContext.getScan(), functionInfo,indexContext); } if (indexContext.hasUpperProject()) { inputCollation = IndexPlanUtils.buildCollationProject(indexContext.getUpperProject().getProjects(), indexContext.getLowerProject(), indexContext.getScan(), functionInfo, indexContext); } if ((inputCollation != null) && (inputCollation.satisfies(indexContext.getCollation()))) { return true; } return false; }
indexContext.getCollation().getFieldCollations() : null);
if (toRemoveSort(indexContext.getCollation(), newRel.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE))) { ((IndexGroupScan)indexScanPrel.getGroupScan()).setParallelizationWidth(1);