本文整理汇总了Java中org.apache.calcite.tools.RelBuilder.filter方法的典型用法代码示例。如果您正苦于以下问题:Java RelBuilder.filter方法的具体用法?Java RelBuilder.filter怎么用?Java RelBuilder.filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.tools.RelBuilder
的用法示例。
在下文中一共展示了RelBuilder.filter方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: addAdditionalFilters
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
* Determines whether any additional filters are applicable to a join tree.
* If there are any, creates a filter node on top of the join tree with the
* additional filters.
*
* @param relBuilder Builder holding current join tree
* @param multiJoin join factors being optimized
* @param left left side of join tree
* @param right right side of join tree
* @param filtersToAdd remaining filters
*/
private void addAdditionalFilters(
RelBuilder relBuilder,
LoptMultiJoin multiJoin,
LoptJoinTree left,
LoptJoinTree right,
List<RexNode> filtersToAdd) {
RexNode filterCond =
addFilters(multiJoin, left, -1, right, filtersToAdd, false);
if (!filterCond.isAlwaysTrue()) {
// adjust the filter to reflect the outer join output
int [] adjustments = new int[multiJoin.getNumTotalFields()];
if (needsAdjustment(multiJoin, adjustments, left, right, false)) {
RexBuilder rexBuilder =
multiJoin.getMultiJoinRel().getCluster().getRexBuilder();
filterCond =
filterCond.accept(
new RelOptUtil.RexInputConverter(
rexBuilder,
multiJoin.getMultiJoinFields(),
relBuilder.peek().getRowType().getFieldList(),
adjustments));
relBuilder.filter(filterCond);
}
}
}
示例3: 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());
}
示例4: 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());
}
}
示例5: 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();
}
示例6: createTopProject
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
/**
* Creates the topmost projection that will sit on top of the selected join
* ordering. The projection needs to match the original join ordering. Also,
* places any post-join filters on top of the project.
*
* @param multiJoin join factors being optimized
* @param joinTree selected join ordering
* @param fieldNames field names corresponding to the projection expressions
*
* @return created projection
*/
private RelNode createTopProject(
RelBuilder relBuilder,
LoptMultiJoin multiJoin,
LoptJoinTree joinTree,
List<String> fieldNames) {
List<RexNode> newProjExprs = Lists.newArrayList();
RexBuilder rexBuilder =
multiJoin.getMultiJoinRel().getCluster().getRexBuilder();
// create a projection on top of the joins, matching the original
// join order
final List<Integer> newJoinOrder = joinTree.getTreeOrder();
int nJoinFactors = multiJoin.getNumJoinFactors();
List<RelDataTypeField> fields = multiJoin.getMultiJoinFields();
// create a mapping from each factor to its field offset in the join
// ordering
final Map<Integer, Integer> factorToOffsetMap = new HashMap<>();
for (int pos = 0, fieldStart = 0; pos < nJoinFactors; pos++) {
factorToOffsetMap.put(newJoinOrder.get(pos), fieldStart);
fieldStart +=
multiJoin.getNumFieldsInJoinFactor(newJoinOrder.get(pos));
}
for (int currFactor = 0; currFactor < nJoinFactors; currFactor++) {
// if the factor is the right factor in a removable self-join,
// then where possible, remap references to the right factor to
// the corresponding reference in the left factor
Integer leftFactor = null;
if (multiJoin.isRightFactorInRemovableSelfJoin(currFactor)) {
leftFactor = multiJoin.getOtherSelfJoinFactor(currFactor);
}
for (int fieldPos = 0;
fieldPos < multiJoin.getNumFieldsInJoinFactor(currFactor);
fieldPos++) {
int newOffset = factorToOffsetMap.get(currFactor) + fieldPos;
if (leftFactor != null) {
Integer leftOffset =
multiJoin.getRightColumnMapping(currFactor, fieldPos);
if (leftOffset != null) {
newOffset =
factorToOffsetMap.get(leftFactor) + leftOffset;
}
}
newProjExprs.add(
rexBuilder.makeInputRef(
fields.get(newProjExprs.size()).getType(),
newOffset));
}
}
relBuilder.push(joinTree.getJoinTree());
relBuilder.project(newProjExprs, fieldNames);
// Place the post-join filter (if it exists) on top of the final
// projection.
RexNode postJoinFilter =
multiJoin.getMultiJoinRel().getPostJoinFilter();
if (postJoinFilter != null) {
relBuilder.filter(postJoinFilter);
}
return relBuilder.build();
}
示例7: onMatch
import org.apache.calcite.tools.RelBuilder; //导入方法依赖的package包/类
public void onMatch(RelOptRuleCall call) {
final Filter filter = call.rel(0);
final Correlate corr = call.rel(1);
final List<RexNode> aboveFilters =
RelOptUtil.conjunctions(filter.getCondition());
final List<RexNode> leftFilters = new ArrayList<>();
final List<RexNode> rightFilters = new ArrayList<>();
// Try to push down above filters. These are typically where clause
// filters. They can be pushed down if they are not on the NULL
// generating side.
RelOptUtil.classifyFilters(
corr,
aboveFilters,
JoinRelType.INNER,
false,
!corr.getJoinType().toJoinType().generatesNullsOnLeft(),
!corr.getJoinType().toJoinType().generatesNullsOnRight(),
aboveFilters,
leftFilters,
rightFilters);
if (leftFilters.isEmpty()
&& rightFilters.isEmpty()) {
// no filters got pushed
return;
}
// Create Filters on top of the children if any filters were
// pushed to them.
final RexBuilder rexBuilder = corr.getCluster().getRexBuilder();
final RelBuilder relBuilder = call.builder();
final RelNode leftRel =
relBuilder.push(corr.getLeft()).filter(leftFilters).build();
final RelNode rightRel =
relBuilder.push(corr.getRight()).filter(rightFilters).build();
// Create the new Correlate
RelNode newCorrRel =
corr.copy(corr.getTraitSet(), ImmutableList.of(leftRel, rightRel));
call.getPlanner().onCopy(corr, newCorrRel);
if (!leftFilters.isEmpty()) {
call.getPlanner().onCopy(filter, leftRel);
}
if (!rightFilters.isEmpty()) {
call.getPlanner().onCopy(filter, rightRel);
}
// Create a Filter on top of the join if needed
relBuilder.push(newCorrRel);
relBuilder.filter(
RexUtil.fixUp(rexBuilder, aboveFilters,
RelOptUtil.getFieldTypeList(relBuilder.peek().getRowType())));
call.transformTo(relBuilder.build());
}