本文整理汇总了Java中org.apache.calcite.tools.RelBuilder.push方法的典型用法代码示例。如果您正苦于以下问题:Java RelBuilder.push方法的具体用法?Java RelBuilder.push怎么用?Java RelBuilder.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.tools.RelBuilder
的用法示例。
在下文中一共展示了RelBuilder.push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public RelNode visit(final LogicalFilter filter) {
final RelBuilder relBuilder = newCalciteRelBuilderWithoutContext(filter.getCluster());
RelNode input = filter.getInput().accept(this);
relBuilder.push(input);
RexNode newCondition = filter.getCondition().accept(new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef inputRef) {
return relBuilder.field(filter.getRowType().getFieldNames().get(inputRef.getIndex()));
}
});
relBuilder.filter(newCondition);
return relBuilder.build();
}
示例2: createUnion
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override protected RelNode createUnion(RelBuilder relBuilder, RexBuilder rexBuilder,
RelNode topProject, RelNode unionInputQuery, RelNode unionInputView) {
relBuilder.push(unionInputQuery);
relBuilder.push(unionInputView);
relBuilder.union(true);
List<RexNode> exprList = new ArrayList<>(relBuilder.peek().getRowType().getFieldCount());
List<String> nameList = new ArrayList<>(relBuilder.peek().getRowType().getFieldCount());
for (int i = 0; i < relBuilder.peek().getRowType().getFieldCount(); i++) {
// We can take unionInputQuery as it is query based.
RelDataTypeField field = unionInputQuery.getRowType().getFieldList().get(i);
exprList.add(
rexBuilder.ensureType(
field.getType(),
rexBuilder.makeInputRef(relBuilder.peek(), i),
true));
nameList.add(field.getName());
}
relBuilder.project(exprList, nameList);
return relBuilder.build();
}
示例3: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
final Aggregate aggregate = call.rel(0);
final RelNode input = call.rel(1);
if (!aggregate.getAggCallList().isEmpty() || aggregate.indicator) {
return;
}
final RelMetadataQuery mq = call.getMetadataQuery();
if (!SqlFunctions.isTrue(mq.areColumnsUnique(input, aggregate.getGroupSet()))) {
return;
}
// Distinct is "GROUP BY c1, c2" (where c1, c2 are a set of columns on
// which the input is unique, i.e. contain a key) and has no aggregate
// functions. It can be removed.
final RelNode newInput = convert(input, aggregate.getTraitSet().simplify());
// If aggregate was projecting a subset of columns, add a project for the
// same effect.
final RelBuilder relBuilder = call.builder();
relBuilder.push(newInput);
if (newInput.getRowType().getFieldCount()
> aggregate.getRowType().getFieldCount()) {
relBuilder.project(relBuilder.fields(aggregate.getGroupSet().asList()));
}
call.transformTo(relBuilder.build());
}
示例4: createProject
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
* Creates a relational expression which projects an array of expressions,
* and optionally optimizes.
*
* <p>The result may not be a
* {@link org.apache.calcite.rel.logical.LogicalProject}. If the
* projection is trivial, <code>child</code> is returned directly; and future
* versions may return other formulations of expressions, such as
* {@link org.apache.calcite.rel.logical.LogicalCalc}.
*
* @param child input relational expression
* @param exprs list of expressions for the input columns
* @param fieldNames aliases of the expressions, or null to generate
* @param optimize Whether to return <code>child</code> unchanged if the
* projections are trivial.
* @param relBuilder Factory to create project operators
*/
public static RelNode createProject(
RelNode child,
List<? extends RexNode> exprs,
List<String> fieldNames,
boolean optimize,
RelBuilder relBuilder) {
final RelOptCluster cluster = child.getCluster();
final RelDataType rowType =
RexUtil.createStructType(cluster.getTypeFactory(), exprs,
fieldNames, SqlValidatorUtil.F_SUGGESTER);
if (optimize
&& RexUtil.isIdentity(exprs, child.getRowType())) {
if (child instanceof Project && fieldNames != null) {
// Rename columns of child projection if desired field names are given.
Project childProject = (Project) child;
child = childProject.copy(childProject.getTraitSet(),
childProject.getInput(), childProject.getProjects(), rowType);
}
return child;
}
relBuilder.push(child);
relBuilder.project(exprs, rowType.getFieldNames(), !optimize);
return relBuilder.build();
}
示例5: updateScan
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public RelNode updateScan(IncrementallyUpdateable scan) {
if (UPDATE_COLUMN.equals(refreshColumn)) {
return scan;
}
RelDataTypeField refreshField = scan.getRowType().getField(refreshColumn, false, false);
if(refreshField == null){
throw UserException.dataReadError()
.message("Table does not include column identified for incremental update of name '%s'.", refreshField.getName())
.build(logger);
} else if(refreshField.getType().getSqlTypeName() != SqlTypeName.BIGINT){
throw UserException.dataReadError()
.message("Dremio only supports incremental column update on BIGINT types. The identified column was of type %s.", refreshField.getType().getSqlTypeName())
.build(logger);
}
final RelBuilder relBuilder = newCalciteRelBuilderWithoutContext(scan.getCluster());
relBuilder.push(scan);
List<String> newFieldNames = ImmutableList.<String>builder().addAll(scan.getRowType().getFieldNames()).add(UPDATE_COLUMN).build();
Iterable<RexInputRef> projects = FluentIterable.from(scan.getRowType().getFieldNames())
.transform(new Function<String, RexInputRef>() {
@Override
public RexInputRef apply(String fieldName) {
return relBuilder.field(fieldName);
}
})
.append(relBuilder.field(refreshColumn));
relBuilder.project(projects, newFieldNames);
return relBuilder.build();
}
示例6: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
final Project proj = call.rel(0);
final ScanCrel scan = call.rel(1);
ProjectPushInfo columnInfo = PrelUtil.getColumns(scan.getRowType(), proj.getProjects());
// get TableBase, either wrapped in RelOptTable, or TranslatableTable. TableBase table = scan.getTable().unwrap(TableBase.class);
if (columnInfo == null || columnInfo.isStarQuery()) {
return;
}
final RelNode newScan = scan.cloneWithProject(columnInfo.columns);
List<RexNode> newProjects = Lists.newArrayList();
for (RexNode n : proj.getChildExps()) {
newProjects.add(n.accept(columnInfo.getInputRewriter()));
}
final RelBuilder relBuilder = relBuilderFactory.create(proj.getCluster(), null);
relBuilder.push(newScan);
relBuilder.project(newProjects, proj.getRowType().getFieldNames());
final RelNode newProj = relBuilder.build();
if (newProj instanceof Project
&& ProjectRemoveRule.isTrivial((Project) newProj)
&& newScan.getRowType().getFullTypeString().equals(newProj.getRowType().getFullTypeString())) {
call.transformTo(newScan);
} else {
call.transformTo(newProj);
}
}
示例7: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
final Project proj = call.rel(0);
final OldScanCrel scan = call.rel(1);
ProjectPushInfo columnInfo = PrelUtil.getColumns(scan.getRowType(), proj.getProjects());
// get TableBase, either wrapped in RelOptTable, or TranslatableTable. TableBase table = scan.getTable().unwrap(TableBase.class);
if (columnInfo == null || columnInfo.isStarQuery() || !scan.getGroupScan().canPushdownProjects(columnInfo.columns)) {
return;
}
final OldScanCrel newScan = new OldScanCrel(scan.getCluster(),
scan.getTable(),
scan.getTraitSet(),
columnInfo.createNewRowType(proj.getInput().getCluster().getTypeFactory()),
scan.getGroupScan().clone(columnInfo.columns),
scan.getLayoutInfo(),
scan.getRowCountDiscount());
List<RexNode> newProjects = Lists.newArrayList();
for (RexNode n : proj.getChildExps()) {
newProjects.add(n.accept(columnInfo.getInputRewriter()));
}
final RelBuilder relBuilder = relBuilderFactory.create(proj.getCluster(), null);
relBuilder.push(newScan);
relBuilder.project(newProjects, proj.getRowType().getFieldNames());
final RelNode newProj = relBuilder.build();
if (newProj instanceof Project
&& ProjectRemoveRule.isTrivial((Project) newProj)
&& newScan.getRowType().getFullTypeString().equals(newProj.getRowType().getFullTypeString())) {
call.transformTo(newScan);
} else {
call.transformTo(newProj);
}
}
示例8: convertMonopole
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
* Converts an aggregate relational expression that contains just one
* distinct aggregate function (or perhaps several over the same arguments)
* and no non-distinct aggregate functions.
*/
private RelBuilder convertMonopole(RelBuilder relBuilder, Aggregate aggregate,
List<Integer> argList, int filterArg) {
// For example,
// SELECT deptno, COUNT(DISTINCT sal), SUM(DISTINCT sal)
// FROM emp
// GROUP BY deptno
//
// becomes
//
// SELECT deptno, COUNT(distinct_sal), SUM(distinct_sal)
// FROM (
// SELECT DISTINCT deptno, sal AS distinct_sal
// FROM EMP GROUP BY deptno)
// GROUP BY deptno
// Project the columns of the GROUP BY plus the arguments
// to the agg function.
final Map<Integer, Integer> sourceOf = new HashMap<>();
createSelectDistinct(relBuilder, aggregate, argList, filterArg, sourceOf);
// Create an aggregate on top, with the new aggregate list.
final List<AggregateCall> newAggCalls =
Lists.newArrayList(aggregate.getAggCallList());
rewriteAggCalls(newAggCalls, argList, sourceOf);
final int cardinality = aggregate.getGroupSet().cardinality();
relBuilder.push(
aggregate.copy(aggregate.getTraitSet(), relBuilder.build(),
aggregate.indicator, ImmutableBitSet.range(cardinality), null,
newAggCalls));
return relBuilder;
}
示例9: convertMonopole
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
* Converts an aggregate relational expression that contains just one
* distinct aggregate function (or perhaps several over the same arguments)
* and no non-distinct aggregate functions.
*/
private RelBuilder convertMonopole(RelBuilder relBuilder, Aggregate aggregate,
List<Integer> argList, int filterArg) {
// For example,
// SELECT deptno, COUNT(DISTINCT sal), SUM(DISTINCT sal)
// FROM emp
// GROUP BY deptno
//
// becomes
//
// SELECT deptno, COUNT(distinct_sal), SUM(distinct_sal)
// FROM (
// SELECT DISTINCT deptno, sal AS distinct_sal
// FROM EMP GROUP BY deptno)
// GROUP BY deptno
// Project the columns of the GROUP BY plus the arguments
// to the agg function.
final Map<Integer, Integer> sourceOf = new HashMap<>();
createSelectDistinct(relBuilder, aggregate, argList, filterArg, sourceOf);
// Create an aggregate on top, with the new aggregate list.
final List<AggregateCall> newAggCalls =
Lists.newArrayList(aggregate.getAggCallList());
rewriteAggCalls(newAggCalls, argList, sourceOf);
final int cardinality = aggregate.getGroupSet().cardinality();
relBuilder.push(
aggregate.copy(aggregate.getTraitSet(), relBuilder.build(),
aggregate.indicator, ImmutableBitSet.range(cardinality), null,
newAggCalls));
return relBuilder;
}
示例10: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
SemiJoin semiJoin = call.rel(0);
LogicalProject project = call.rel(1);
// Convert the LHS semi-join keys to reference the child projection
// expression; all projection expressions must be RexInputRefs,
// otherwise, we wouldn't have created this semi-join.
final List<Integer> newLeftKeys = new ArrayList<>();
final List<Integer> leftKeys = semiJoin.getLeftKeys();
final List<RexNode> projExprs = project.getProjects();
for (int leftKey : leftKeys) {
RexInputRef inputRef = (RexInputRef) projExprs.get(leftKey);
newLeftKeys.add(inputRef.getIndex());
}
// convert the semijoin condition to reflect the LHS with the project
// pulled up
RexNode newCondition = adjustCondition(project, semiJoin);
SemiJoin newSemiJoin =
SemiJoin.create(project.getInput(), semiJoin.getRight(), newCondition,
ImmutableIntList.copyOf(newLeftKeys), semiJoin.getRightKeys());
// Create the new projection. Note that the projection expressions
// are the same as the original because they only reference the LHS
// of the semijoin and the semijoin only projects out the LHS
final RelBuilder relBuilder = call.builder();
relBuilder.push(newSemiJoin);
relBuilder.project(projExprs, project.getRowType().getFieldNames());
call.transformTo(relBuilder.build());
}
示例11: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override public void onMatch(RelOptRuleCall call) {
final Calc calc = call.rel(0);
final Pair<ImmutableList<RexNode>, ImmutableList<RexNode>> projectFilter =
calc.getProgram().split();
final RelBuilder relBuilder = call.builder();
relBuilder.push(calc.getInput());
relBuilder.filter(projectFilter.right);
relBuilder.project(projectFilter.left, calc.getRowType().getFieldNames());
call.transformTo(relBuilder.build());
}
示例12: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
final Project topProject = call.rel(0);
final Project bottomProject = call.rel(1);
final RelBuilder relBuilder = call.builder();
// merge projects assuming it doesn't alter the unique count of flattens.
final FlattenCounter counter = new FlattenCounter();
counter.add(topProject);
counter.add(bottomProject);
final int uniqueFlattens = counter.getCount();
// If one or both projects are permutations, short-circuit the complex logic
// of building a RexProgram.
final Permutation topPermutation = topProject.getPermutation();
if (topPermutation != null) {
if (topPermutation.isIdentity()) {
// Let ProjectRemoveRule handle this.
return;
}
final Permutation bottomPermutation = bottomProject.getPermutation();
if (bottomPermutation != null) {
if (bottomPermutation.isIdentity()) {
// Let ProjectRemoveRule handle this.
return;
}
final Permutation product = topPermutation.product(bottomPermutation);
relBuilder.push(bottomProject.getInput());
List<RexNode> exprs = relBuilder.fields(product);
relBuilder.project(exprs, topProject.getRowType().getFieldNames());
if(FlattenVisitors.count(exprs) == uniqueFlattens){
call.transformTo(relBuilder.build());
}
return;
}
}
final List<RexNode> newProjects =
RelOptUtil.pushPastProject(topProject.getProjects(), bottomProject);
final RelNode input = bottomProject.getInput();
if (RexUtil.isIdentity(newProjects, input.getRowType()) && uniqueFlattens == 0) {
call.transformTo(input);
}
// replace the two projects with a combined projection
relBuilder.push(bottomProject.getInput());
relBuilder.project(newProjects, topProject.getRowType().getFieldNames());
if(FlattenVisitors.count(newProjects) == uniqueFlattens){
call.transformTo(relBuilder.build());
}
}
示例13: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
Filter filterRel = call.rel(0);
Project projRel = call.rel(1);
// get a conjunctions of the filter condition. For each conjunction, if it refers to ITEM or FLATTEN expression
// then we could not pushed down. Otherwise, it's qualified to be pushed down.
final List<RexNode> predList = RelOptUtil.conjunctions(filterRel.getCondition());
final List<RexNode> qualifiedPredList = Lists.newArrayList();
final List<RexNode> unqualifiedPredList = Lists.newArrayList();
for (final RexNode pred : predList) {
if (findItemOrFlatten(pred, projRel.getProjects()) == null) {
qualifiedPredList.add(pred);
} else {
unqualifiedPredList.add(pred);
}
}
final RexNode qualifedPred = RexUtil.composeConjunction(filterRel.getCluster().getRexBuilder(), qualifiedPredList, true);
if (qualifedPred == null) {
return;
}
// convert the filter to one that references the child of the project
RexNode newCondition =
RelOptUtil.pushPastProject(qualifedPred, projRel);
RelBuilder relBuilder = relBuilderFactory.create(filterRel.getCluster(), null);
relBuilder.push(projRel.getInput());
relBuilder.filter(newCondition);
relBuilder.project(Pair.left(projRel.getNamedProjects()), Pair.right(projRel.getNamedProjects()));
final RexNode unqualifiedPred = RexUtil.composeConjunction(filterRel.getCluster().getRexBuilder(), unqualifiedPredList, true);
if (unqualifiedPred == null) {
call.transformTo(relBuilder.build());
} else {
// if there are filters not qualified to be pushed down, then we have to put those filters on top of
// the new Project operator.
// Filter -- unqualified filters
// \
// Project
// \
// Filter -- qualified filters
relBuilder.filter(unqualifiedPred);
call.transformTo(relBuilder.build());
}
}
示例14: rewriteQuery
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override protected RelNode rewriteQuery(
RelBuilder relBuilder,
RexBuilder rexBuilder,
RexSimplify simplify,
RelMetadataQuery mq,
RexNode compensationColumnsEquiPred,
RexNode otherCompensationPred,
Project topProject,
RelNode node,
BiMap<RelTableRef, RelTableRef> viewToQueryTableMapping,
EquivalenceClasses viewEC, EquivalenceClasses queryEC) {
// All columns required by compensating predicates must be contained
// in the query.
List<RexNode> queryExprs = extractReferences(rexBuilder, node);
if (!compensationColumnsEquiPred.isAlwaysTrue()) {
compensationColumnsEquiPred = rewriteExpression(rexBuilder, mq,
node, queryExprs, viewToQueryTableMapping.inverse(), queryEC, false,
compensationColumnsEquiPred);
if (compensationColumnsEquiPred == null) {
// Skip it
return null;
}
}
// For the rest, we use the query equivalence classes
if (!otherCompensationPred.isAlwaysTrue()) {
otherCompensationPred = rewriteExpression(rexBuilder, mq,
node, queryExprs, viewToQueryTableMapping.inverse(), viewEC, true,
otherCompensationPred);
if (otherCompensationPred == null) {
// Skip it
return null;
}
}
final RexNode queryCompensationPred = RexUtil.not(
RexUtil.composeConjunction(
rexBuilder,
ImmutableList.of(
compensationColumnsEquiPred,
otherCompensationPred),
false));
// Generate query rewriting.
relBuilder.push(node);
relBuilder.filter(simplify.simplify(queryCompensationPred));
if (topProject != null) {
return topProject.copy(topProject.getTraitSet(), ImmutableList.of(relBuilder.build()));
}
return relBuilder.build();
}
示例15: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
@Override public void onMatch(RelOptRuleCall call) {
final Union union = call.rel(0);
final int count = union.getRowType().getFieldCount();
if (count == 1) {
// No room for optimization since we cannot create an empty Project
// operator. If we created a Project with one column, this rule would
// cycle.
return;
}
final RexBuilder rexBuilder = union.getCluster().getRexBuilder();
final RelMetadataQuery mq = call.getMetadataQuery();
final RelOptPredicateList predicates = mq.getPulledUpPredicates(union);
if (predicates == null) {
return;
}
final Map<Integer, RexNode> constants = new HashMap<>();
for (Map.Entry<RexNode, RexNode> e : predicates.constantMap.entrySet()) {
if (e.getKey() instanceof RexInputRef) {
constants.put(((RexInputRef) e.getKey()).getIndex(), e.getValue());
}
}
// None of the expressions are constant. Nothing to do.
if (constants.isEmpty()) {
return;
}
// Create expressions for Project operators before and after the Union
List<RelDataTypeField> fields = union.getRowType().getFieldList();
List<RexNode> topChildExprs = new ArrayList<>();
List<String> topChildExprsFields = new ArrayList<>();
List<RexNode> refs = new ArrayList<>();
ImmutableBitSet.Builder refsIndexBuilder = ImmutableBitSet.builder();
for (RelDataTypeField field : fields) {
final RexNode constant = constants.get(field.getIndex());
if (constant != null) {
topChildExprs.add(constant);
topChildExprsFields.add(field.getName());
} else {
final RexNode expr = rexBuilder.makeInputRef(union, field.getIndex());
topChildExprs.add(expr);
topChildExprsFields.add(field.getName());
refs.add(expr);
refsIndexBuilder.set(field.getIndex());
}
}
ImmutableBitSet refsIndex = refsIndexBuilder.build();
// Update top Project positions
final Mappings.TargetMapping mapping =
RelOptUtil.permutation(refs, union.getInput(0).getRowType()).inverse();
topChildExprs = ImmutableList.copyOf(RexUtil.apply(mapping, topChildExprs));
// Create new Project-Union-Project sequences
final RelBuilder relBuilder = call.builder();
for (RelNode input : union.getInputs()) {
List<Pair<RexNode, String>> newChildExprs = new ArrayList<>();
for (int j : refsIndex) {
newChildExprs.add(
Pair.<RexNode, String>of(rexBuilder.makeInputRef(input, j),
input.getRowType().getFieldList().get(j).getName()));
}
if (newChildExprs.isEmpty()) {
// At least a single item in project is required.
newChildExprs.add(
Pair.of(topChildExprs.get(0), topChildExprsFields.get(0)));
}
// Add the input with project on top
relBuilder.push(input);
relBuilder.project(Pair.left(newChildExprs), Pair.right(newChildExprs));
}
relBuilder.union(union.all, union.getInputs().size());
// Create top Project fixing nullability of fields
relBuilder.project(topChildExprs, topChildExprsFields);
relBuilder.convert(union.getRowType(), false);
call.transformTo(relBuilder.build());
}