new LinkedHashSet<RelDataTypeField>(extraFields); RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(combinedInputExtraFields); inputFinder.inputBitSet.addAll(fieldsUsed); conditionExpr.accept(inputFinder);
new LinkedHashSet<RelDataTypeField>(extraFields); RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(combinedInputExtraFields); inputFinder.inputBitSet.addAll(fieldsUsed); conditionExpr.accept(inputFinder);
/** * Given an expression, it will create all equivalent expressions resulting * from replacing all possible combinations of references in the mapping by * the corresponding expressions. * * @param rexBuilder rexBuilder * @param expr expression * @param mapping mapping * @return set of resulting expressions equivalent to the input expression */ protected static Set<RexNode> createAllPossibleExpressions(RexBuilder rexBuilder, RexNode expr, Map<RexInputRef, Set<RexNode>> mapping) { // Extract input fields referenced by expression final Set<RelDataTypeField> inputExtraFields = new LinkedHashSet<>(); final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); expr.accept(inputFinder); final ImmutableBitSet predFieldsUsed = inputFinder.inputBitSet.build(); if (predFieldsUsed.isEmpty()) { // The unique expression is the input expression return ImmutableSet.of(expr); } return createAllPossibleExpressions(rexBuilder, expr, predFieldsUsed, mapping, new HashMap<>()); }
final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); pred.accept(inputFinder); final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build();
new LinkedHashSet<>(extraFields); RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); for (Ord<RexNode> ord : Ord.zip(project.getProjects())) { if (fieldsUsed.get(ord.i)) {
new LinkedHashSet<>(extraFields); RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); for (Ord<RexNode> ord : Ord.zip(project.getProjects())) { if (fieldsUsed.get(ord.i)) {
new LinkedHashSet<>(extraFields); RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); inputFinder.inputBitSet.addAll(fieldsUsed); conditionExpr.accept(inputFinder);
new LinkedHashSet<>(extraFields); RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); inputFinder.inputBitSet.addAll(fieldsUsed); conditionExpr.accept(inputFinder);
final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); pred.accept(inputFinder); final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build();
final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); outputExpression.accept(inputFinder); final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build();
final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); pred.accept(inputFinder); final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build();
/** * Expression lineage from {@link TableScan}. * * <p>We extract the fields referenced by the expression and we express them * using {@link RexTableInputRef}. */ public Set<RexNode> getExpressionLineage(TableScan rel, RelMetadataQuery mq, RexNode outputExpression) { final RexBuilder rexBuilder = rel.getCluster().getRexBuilder(); // Extract input fields referenced by expression final Set<RelDataTypeField> inputExtraFields = new LinkedHashSet<>(); final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); outputExpression.accept(inputFinder); final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build(); // Infer column origin expressions for given references final Map<RexInputRef, Set<RexNode>> mapping = new LinkedHashMap<>(); for (int idx : inputFieldsUsed) { final RexNode inputRef = RexTableInputRef.of( RelTableRef.of(rel.getTable(), 0), RexInputRef.of(idx, rel.getRowType().getFieldList())); final RexInputRef ref = RexInputRef.of(idx, rel.getRowType().getFieldList()); mapping.put(ref, ImmutableSet.of(inputRef)); } // Return result return createAllPossibleExpressions(rexBuilder, outputExpression, mapping); }
/** * Expression lineage from Project. */ public Set<RexNode> getExpressionLineage(Project rel, final RelMetadataQuery mq, RexNode outputExpression) { final RelNode input = rel.getInput(); final RexBuilder rexBuilder = rel.getCluster().getRexBuilder(); // Extract input fields referenced by expression final Set<RelDataTypeField> inputExtraFields = new LinkedHashSet<>(); final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); outputExpression.accept(inputFinder); final ImmutableBitSet inputFieldsUsed = inputFinder.inputBitSet.build(); // Infer column origin expressions for given references final Map<RexInputRef, Set<RexNode>> mapping = new LinkedHashMap<>(); for (int idx : inputFieldsUsed) { final RexNode inputExpr = rel.getChildExps().get(idx); final Set<RexNode> originalExprs = mq.getExpressionLineage(input, inputExpr); if (originalExprs == null) { // Bail out return null; } final RexInputRef ref = RexInputRef.of(idx, rel.getRowType().getFieldList()); mapping.put(ref, originalExprs); } // Return result return createAllPossibleExpressions(rexBuilder, outputExpression, mapping); }
/** * Returns a bit set describing the inputs used by a collection of * project expressions and an optional condition. */ public static ImmutableBitSet bits(List<RexNode> exprs, RexNode expr) { final InputFinder inputFinder = new InputFinder(); RexUtil.apply(inputFinder, exprs, expr); return inputFinder.inputBitSet.build(); }
/** Returns an input finder that has analyzed a given expression. */ public static InputFinder analyze(RexNode node) { final InputFinder inputFinder = new InputFinder(); node.accept(inputFinder); return inputFinder; }
private ImmutableBitSet fieldBitmap(RexNode joinFilter) { final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(); joinFilter.accept(inputFinder); return inputFinder.inputBitSet.build(); }
/** Returns an input finder that has analyzed a given expression. */ public static InputFinder analyze(RexNode node) { final InputFinder inputFinder = new InputFinder(); node.accept(inputFinder); return inputFinder; }
private ImmutableBitSet fieldBitmap(RexNode joinFilter) { final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(); joinFilter.accept(inputFinder); return inputFinder.inputBitSet.build(); }
private static ImmutableBitSet extractInputRefs(RexNode expr) { final Set<RelDataTypeField> inputExtraFields = new LinkedHashSet<>(); final RelOptUtil.InputFinder inputFinder = new RelOptUtil.InputFinder(inputExtraFields); expr.accept(inputFinder); return inputFinder.inputBitSet.build(); } }
/** * Returns a bit set describing the inputs used by a collection of * project expressions and an optional condition. */ public static ImmutableBitSet bits(List<RexNode> exprs, RexNode expr) { final InputFinder inputFinder = new InputFinder(); RexUtil.apply(inputFinder, exprs, expr); return inputFinder.inputBitSet.build(); }