本文整理汇总了Java中org.apache.calcite.rex.RexShuttle类的典型用法代码示例。如果您正苦于以下问题:Java RexShuttle类的具体用法?Java RexShuttle怎么用?Java RexShuttle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RexShuttle类属于org.apache.calcite.rex包,在下文中一共展示了RexShuttle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.apache.calcite.rex.RexShuttle; //导入依赖的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: shuttleReferences
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
/**
* Replaces all the input references by the position in the
* input column set. If a reference index cannot be found in
* the input set, then we return null.
*/
private static RexNode shuttleReferences(final RexBuilder rexBuilder,
final RexNode node, final Mapping mapping) {
try {
RexShuttle visitor =
new RexShuttle() {
@Override public RexNode visitInputRef(RexInputRef inputRef) {
int pos = mapping.getTargetOpt(inputRef.getIndex());
if (pos != -1) {
// Found it
return rexBuilder.makeInputRef(inputRef.getType(), pos);
}
throw Util.FoundOne.NULL;
}
};
return visitor.apply(node);
} catch (Util.FoundOne ex) {
Util.swallow(ex, null);
return null;
}
}
示例3: accept
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
public RelNode accept(RexShuttle shuttle) {
RexNode joinFilter = shuttle.apply(this.joinFilter);
List<RexNode> outerJoinConditions = shuttle.apply(this.outerJoinConditions);
RexNode postJoinFilter = shuttle.apply(this.postJoinFilter);
if (joinFilter == this.joinFilter
&& outerJoinConditions == this.outerJoinConditions
&& postJoinFilter == this.postJoinFilter) {
return this;
}
return new MultiJoin(
getCluster(),
inputs,
joinFilter,
rowType,
isFullOuterJoin,
outerJoinConditions,
joinTypes,
projFields,
joinFieldRefCountsMap,
postJoinFilter);
}
示例4: transformRex
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
private static List<RexNode> transformRex(
List<RexNode> nodes,
final List<RelDataTypeField> oldFields,
final List<RelDataTypeField> newFields) {
RexShuttle shuttle = new RexShuttle() {
@Override public RexNode visitInputRef(RexInputRef ref) {
RelDataTypeField f = oldFields.get(ref.getIndex());
for (int index = 0; index < newFields.size(); index++) {
RelDataTypeField newf = newFields.get(index);
if (f.getKey().equals(newf.getKey())
&& f.getValue() == newf.getValue()) {
return new RexInputRef(index, f.getValue());
}
}
throw MatchFailed.INSTANCE;
}
};
return shuttle.apply(nodes);
}
示例5: apply
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
public UnifyResult apply(UnifyRuleCall call) {
final MutableProject target = (MutableProject) call.target;
final MutableScan query = (MutableScan) call.query;
// We do not need to check query's parent type to avoid duplication
// of ProjectToProjectUnifyRule or FilterToProjectUnifyRule, since
// SubstitutionVisitor performs a top-down match.
if (!query.equals(target.getInput())) {
return null;
}
final RexShuttle shuttle = getRexShuttle(target);
final RexBuilder rexBuilder = target.cluster.getRexBuilder();
final List<RexNode> newProjects;
try {
newProjects = (List<RexNode>)
shuttle.apply(rexBuilder.identityProjects(query.rowType));
} catch (MatchFailed e) {
return null;
}
final MutableProject newProject =
MutableProject.of(query.rowType, target, newProjects);
final MutableRel newProject2 = MutableRels.strip(newProject);
return call.result(newProject2);
}
示例6: onMatch
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
LogicalCalc calc = call.rel(0);
// Expand decimals in every expression in this program. If no
// expression changes, don't apply the rule.
final RexProgram program = calc.getProgram();
if (!RexUtil.requiresDecimalExpansion(program, true)) {
return;
}
final RexBuilder rexBuilder = calc.getCluster().getRexBuilder();
final RexShuttle shuttle = new DecimalShuttle(rexBuilder);
RexProgramBuilder programBuilder =
RexProgramBuilder.create(
rexBuilder,
calc.getInput().getRowType(),
program.getExprList(),
program.getProjectList(),
program.getCondition(),
program.getOutputRowType(),
shuttle,
true);
final RexProgram newProgram = programBuilder.getProgram();
LogicalCalc newCalc = LogicalCalc.create(calc.getInput(), newProgram);
call.transformTo(newCalc);
}
示例7: accept
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
public RelNode accept(RexShuttle shuttle) {
List<RexNode> oldExprs = program.getExprList();
List<RexNode> exprs = shuttle.apply(oldExprs);
List<RexLocalRef> oldProjects = program.getProjectList();
List<RexLocalRef> projects = shuttle.apply(oldProjects);
RexLocalRef oldCondition = program.getCondition();
RexNode condition;
if (oldCondition != null) {
condition = shuttle.apply(oldCondition);
assert condition instanceof RexLocalRef
: "Invalid condition after rewrite. Expected RexLocalRef, got "
+ condition;
} else {
condition = null;
}
if (exprs == oldExprs
&& projects == oldProjects
&& condition == oldCondition) {
return this;
}
return copy(traitSet, getInput(),
new RexProgram(program.getInputRowType(),
exprs,
projects,
(RexLocalRef) condition,
program.getOutputRowType()));
}
示例8: accept
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
@Override public RelNode accept(RexShuttle shuttle) {
RexNode condition = shuttle.apply(this.condition);
if (this.condition == condition) {
return this;
}
return copy(traitSet, condition, left, right, joinType, isSemiJoinDone());
}
示例9: accept
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
public RelNode accept(RexShuttle shuttle) {
RexNode condition = shuttle.apply(this.condition);
if (this.condition == condition) {
return this;
}
return copy(traitSet, getInput(), condition);
}
示例10: accept
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
public RelNode accept(RexShuttle shuttle) {
RexNode offset = shuttle.apply(this.offset);
RexNode fetch = shuttle.apply(this.fetch);
List<RexNode> fieldExps = shuttle.apply(this.fieldExps);
assert fieldExps == this.fieldExps
: "Sort node does not support modification of input field expressions."
+ " Old expressions: " + this.fieldExps + ", new ones: " + fieldExps;
if (offset == this.offset
&& fetch == this.fetch) {
return this;
}
return copy(traitSet, getInput(), collation, offset, fetch);
}
示例11: accept
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
public RelNode accept(RexShuttle shuttle) {
List<RexNode> exps = shuttle.apply(this.exps);
if (this.exps == exps) {
return this;
}
return copy(traitSet, getInput(), exps, rowType);
}
示例12: accept
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
public RelNode accept(RexShuttle shuttle) {
RexNode rexCall = shuttle.apply(this.rexCall);
if (rexCall == this.rexCall) {
return this;
}
return copy(traitSet, inputs, rexCall, elementType, rowType,
columnMappings);
}
示例13: pushShuttle
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
private static RexShuttle pushShuttle(final Project project) {
return new RexShuttle() {
@Override public RexNode visitInputRef(RexInputRef ref) {
return project.getProjects().get(ref.getIndex());
}
};
}
示例14: convertOver
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
private RexNode convertOver(Blackboard bb, SqlNode node) {
SqlCall call = (SqlCall) node;
SqlCall aggCall = call.operand(0);
SqlNode windowOrRef = call.operand(1);
final SqlWindow window =
validator.resolveWindow(windowOrRef, bb.scope, true);
// ROW_NUMBER() expects specific kind of framing.
if (aggCall.getKind() == SqlKind.ROW_NUMBER) {
window.setLowerBound(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO));
window.setUpperBound(SqlWindow.createCurrentRow(SqlParserPos.ZERO));
window.setRows(SqlLiteral.createBoolean(true, SqlParserPos.ZERO));
}
final SqlNodeList partitionList = window.getPartitionList();
final ImmutableList.Builder<RexNode> partitionKeys =
ImmutableList.builder();
for (SqlNode partition : partitionList) {
partitionKeys.add(bb.convertExpression(partition));
}
RexNode lowerBound = bb.convertExpression(window.getLowerBound());
RexNode upperBound = bb.convertExpression(window.getUpperBound());
SqlNodeList orderList = window.getOrderList();
if ((orderList.size() == 0) && !window.isRows()) {
// A logical range requires an ORDER BY clause. Use the implicit
// ordering of this relation. There must be one, otherwise it would
// have failed validation.
orderList = bb.scope.getOrderList();
if (orderList == null) {
throw new AssertionError(
"Relation should have sort key for implicit ORDER BY");
}
}
final ImmutableList.Builder<RexFieldCollation> orderKeys =
ImmutableList.builder();
final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
for (SqlNode order : orderList) {
flags.clear();
RexNode e = bb.convertSortExpression(order, flags);
orderKeys.add(new RexFieldCollation(e, flags));
}
try {
Preconditions.checkArgument(bb.window == null,
"already in window agg mode");
bb.window = window;
RexNode rexAgg = exprConverter.convertCall(bb, aggCall);
rexAgg =
rexBuilder.ensureType(
validator.getValidatedNodeType(call), rexAgg, false);
// Walk over the tree and apply 'over' to all agg functions. This is
// necessary because the returned expression is not necessarily a call
// to an agg function. For example, AVG(x) becomes SUM(x) / COUNT(x).
final RexShuttle visitor =
new HistogramShuttle(
partitionKeys.build(), orderKeys.build(),
RexWindowBound.create(window.getLowerBound(), lowerBound),
RexWindowBound.create(window.getUpperBound(), upperBound),
window);
return rexAgg.accept(visitor);
} finally {
bb.window = null;
}
}
示例15: convertOver
import org.apache.calcite.rex.RexShuttle; //导入依赖的package包/类
private RexNode convertOver(Blackboard bb, SqlNode node) {
SqlCall call = (SqlCall) node;
SqlCall aggCall = call.operand(0);
SqlNode windowOrRef = call.operand(1);
final SqlWindow window =
validator.resolveWindow(windowOrRef, bb.scope, true);
// ROW_NUMBER() expects specific kind of framing.
if (aggCall.getKind() == SqlKind.ROW_NUMBER) {
window.setLowerBound(SqlWindow.createUnboundedPreceding(SqlParserPos.ZERO));
window.setUpperBound(SqlWindow.createCurrentRow(SqlParserPos.ZERO));
window.setRows(SqlLiteral.createBoolean(true, SqlParserPos.ZERO));
}
final SqlNodeList partitionList = window.getPartitionList();
final ImmutableList.Builder<RexNode> partitionKeys =
ImmutableList.builder();
for (SqlNode partition : partitionList) {
partitionKeys.add(bb.convertExpression(partition));
}
RexNode lowerBound = bb.convertExpression(window.getLowerBound());
RexNode upperBound = bb.convertExpression(window.getUpperBound());
SqlNodeList orderList = window.getOrderList();
if ((orderList.size() == 0) && !window.isRows()) {
// A logical range requires an ORDER BY clause. Use the implicit
// ordering of this relation. There must be one, otherwise it would
// have failed validation.
orderList = bb.scope.getOrderList();
if (orderList == null) {
throw new AssertionError(
"Relation should have sort key for implicit ORDER BY");
}
}
final ImmutableList.Builder<RexFieldCollation> orderKeys =
ImmutableList.builder();
final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
for (SqlNode order : orderList) {
flags.clear();
RexNode e = bb.convertSortExpression(order, flags);
orderKeys.add(new RexFieldCollation(e, flags));
}
try {
Preconditions.checkArgument(bb.window == null,
"already in window agg mode");
bb.window = window;
RexNode rexAgg = exprConverter.convertCall(bb, aggCall);
rexAgg =
rexBuilder.ensureType(
validator.getValidatedNodeType(call), rexAgg, false);
// Walk over the tree and apply 'over' to all agg functions. This is
// necessary because the returned expression is not necessarily a call
// to an agg function. For example, AVG(x) becomes SUM(x) / COUNT(x).
boolean isDistinct = false;
if (aggCall.getFunctionQuantifier() != null
&& aggCall.getFunctionQuantifier().getValue().equals(SqlSelectKeyword.DISTINCT)) {
isDistinct = true;
}
final RexShuttle visitor =
new HistogramShuttle(
partitionKeys.build(), orderKeys.build(),
RexWindowBound.create(window.getLowerBound(), lowerBound),
RexWindowBound.create(window.getUpperBound(), upperBound),
window,
isDistinct);
RexNode overNode = rexAgg.accept(visitor);
return overNode;
} finally {
bb.window = null;
}
}