use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project drill by apache.
the class CreateTableHandler method convertToDrel.
private DrillRel convertToDrel(RelNode relNode, AbstractSchema schema, String tableName, List<String> partitionColumns, RelDataType queryRowType, StorageStrategy storageStrategy) throws RelConversionException, SqlUnsupportedException {
final DrillRel convertedRelNode = convertToRawDrel(relNode);
// Put a non-trivial topProject to ensure the final output field name is preserved, when necessary.
// Only insert project when the field count from the child is same as that of the queryRowType.
final DrillRel topPreservedNameProj = queryRowType.getFieldCount() == convertedRelNode.getRowType().getFieldCount() ? addRenamedProject(convertedRelNode, queryRowType) : convertedRelNode;
final RelTraitSet traits = convertedRelNode.getCluster().traitSet().plus(DrillRel.DRILL_LOGICAL);
final DrillWriterRel writerRel = new DrillWriterRel(convertedRelNode.getCluster(), traits, topPreservedNameProj, schema.createNewTable(tableName, partitionColumns, storageStrategy));
return new DrillScreenRel(writerRel.getCluster(), writerRel.getTraitSet(), writerRel);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project drill by apache.
the class ConversionContext method getLogicalTraits.
public RelTraitSet getLogicalTraits() {
RelTraitSet set = RelTraitSet.createEmpty();
set.add(DrillRel.DRILL_LOGICAL);
return set;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project drill by apache.
the class ElasticsearchFilterRule method convert.
@Override
public RelNode convert(RelNode relNode) {
Filter filter = (Filter) relNode;
NodeTypeFinder filterFinder = new NodeTypeFinder(ElasticsearchFilter.class);
filter.getInput().accept(filterFinder);
if (filterFinder.containsNode) {
return null;
}
RelTraitSet traitSet = filter.getTraitSet().replace(out);
try {
CalciteUtils.analyzePredicate(filter.getCondition());
} catch (Exception e) {
logger.info("Unable to push filter into ElasticSearch :{}", e.getMessage(), e);
return null;
}
return CalciteUtils.createFilter(traitSet, convert(filter.getInput(), out), filter.getCondition());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project drill by apache.
the class ElasticsearchProjectRule method convert.
@Override
public RelNode convert(RelNode relNode) {
Project project = (Project) relNode;
NodeTypeFinder projectFinder = new NodeTypeFinder(ElasticsearchProject.class);
project.getInput().accept(projectFinder);
if (projectFinder.containsNode) {
// Calcite adapter allows only a single Elasticsearch project per tree
return null;
}
RelTraitSet traitSet = project.getTraitSet().replace(out);
List<RexNode> innerProjections = new ArrayList<>();
RelDataType rowType = project.getInput().getRowType();
// check for literals only without input exprs
DrillRelOptUtil.InputRefVisitor collectRefs = new DrillRelOptUtil.InputRefVisitor();
project.getChildExps().forEach(exp -> exp.accept(collectRefs));
if (!collectRefs.getInputRefs().isEmpty()) {
for (RelDataTypeField relDataTypeField : rowType.getFieldList()) {
innerProjections.add(project.getCluster().getRexBuilder().makeInputRef(project.getInput(), relDataTypeField.getIndex()));
}
}
boolean allExprsInputRefs = project.getChildExps().stream().allMatch(rexNode -> rexNode instanceof RexInputRef);
if (collectRefs.getInputRefs().isEmpty() || allExprsInputRefs) {
return CalciteUtils.createProject(traitSet, convert(project.getInput(), out), project.getProjects(), project.getRowType());
} else {
Project elasticsearchProject = CalciteUtils.createProject(traitSet, convert(project.getInput(), out), innerProjections, project.getInput().getRowType());
return project.copy(project.getTraitSet(), elasticsearchProject, project.getProjects(), project.getRowType());
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet in project drill by apache.
the class AbstractIndexPlanGenerator method getSortNode.
public static RelNode getSortNode(IndexCallContext indexContext, RelNode newRel, boolean donotGenerateSort, boolean isSingleton, boolean isExchangeRequired) {
OrderedRel rel = indexContext.getSort();
DrillDistributionTrait hashDistribution = new DrillDistributionTrait(DrillDistributionTrait.DistributionType.HASH_DISTRIBUTED, ImmutableList.copyOf(indexContext.getDistributionFields()));
if (toRemoveSort(indexContext.getCollation(), newRel.getTraitSet().getTrait(RelCollationTraitDef.INSTANCE))) {
// we are going to remove sort
logger.debug("Not generating SortPrel since we have the required collation");
if (IndexPlanUtils.generateLimit(rel)) {
newRel = new LimitPrel(newRel.getCluster(), 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, traits, hashDistribution, indexContext, newRel);
} else {
if (donotGenerateSort) {
logger.debug("Not generating SortPrel and index plan, since just picking index for full index scan is not beneficial.");
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)));
newRel = getExchange(newRel.getCluster(), isSingleton, isExchangeRequired, traits, hashDistribution, indexContext, newRel);
}
return newRel;
}
Aggregations