use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project flink by apache.
the class PushFilterIntoTableSourceScanRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
if (!super.matches(call)) {
return false;
}
Filter filter = call.rel(0);
if (filter.getCondition() == null) {
return false;
}
LogicalTableScan scan = call.rel(1);
TableSourceTable tableSourceTable = scan.getTable().unwrap(TableSourceTable.class);
return canPushdownFilter(tableSourceTable);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project flink by apache.
the class PushFilterIntoTableSourceScanRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
Filter filter = call.rel(0);
LogicalTableScan scan = call.rel(1);
TableSourceTable table = scan.getTable().unwrap(TableSourceTable.class);
pushFilterIntoScan(call, filter, scan, table);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project flink by apache.
the class PushFilterIntoTableSourceScanRule method pushFilterIntoScan.
private void pushFilterIntoScan(RelOptRuleCall call, Filter filter, LogicalTableScan scan, FlinkPreparingTableBase relOptTable) {
RelBuilder relBuilder = call.builder();
Tuple2<RexNode[], RexNode[]> extractedPredicates = extractPredicates(filter.getInput().getRowType().getFieldNames().toArray(new String[0]), filter.getCondition(), scan, relBuilder.getRexBuilder());
RexNode[] convertiblePredicates = extractedPredicates._1;
RexNode[] unconvertedPredicates = extractedPredicates._2;
if (convertiblePredicates.length == 0) {
// no condition can be translated to expression
return;
}
Tuple2<SupportsFilterPushDown.Result, TableSourceTable> scanAfterPushdownWithResult = resolveFiltersAndCreateTableSourceTable(convertiblePredicates, relOptTable.unwrap(TableSourceTable.class), scan, relBuilder);
SupportsFilterPushDown.Result result = scanAfterPushdownWithResult._1;
TableSourceTable tableSourceTable = scanAfterPushdownWithResult._2;
LogicalTableScan newScan = LogicalTableScan.create(scan.getCluster(), tableSourceTable, scan.getHints());
if (result.getRemainingFilters().isEmpty() && unconvertedPredicates.length == 0) {
call.transformTo(newScan);
} else {
RexNode remainingCondition = createRemainingCondition(relBuilder, result.getRemainingFilters(), unconvertedPredicates);
RexNode simplifiedRemainingCondition = FlinkRexUtil.simplify(relBuilder.getRexBuilder(), remainingCondition, filter.getCluster().getPlanner().getExecutor());
Filter newFilter = filter.copy(filter.getTraitSet(), newScan, simplifiedRemainingCondition);
call.transformTo(newFilter);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project flink by apache.
the class RelDecorrelator method decorrelateInputWithValueGenerator.
private Frame decorrelateInputWithValueGenerator(RelNode rel, Frame frame) {
// currently only handles one input
assert rel.getInputs().size() == 1;
RelNode oldInput = frame.r;
final SortedMap<CorDef, Integer> corDefOutputs = new TreeMap<>(frame.corDefOutputs);
final Collection<CorRef> corVarList = cm.mapRefRelToCorRef.get(rel);
// This means that we do not need a value generator.
if (rel instanceof Filter) {
SortedMap<CorDef, Integer> map = new TreeMap<>();
List<RexNode> projects = new ArrayList<>();
for (CorRef correlation : corVarList) {
final CorDef def = correlation.def();
if (corDefOutputs.containsKey(def) || map.containsKey(def)) {
continue;
}
try {
findCorrelationEquivalent(correlation, ((Filter) rel).getCondition());
} catch (Util.FoundOne e) {
if (e.getNode() instanceof RexInputRef) {
map.put(def, ((RexInputRef) e.getNode()).getIndex());
} else {
map.put(def, frame.r.getRowType().getFieldCount() + projects.size());
projects.add((RexNode) e.getNode());
}
}
}
// generator.
if (map.size() == corVarList.size()) {
map.putAll(frame.corDefOutputs);
final RelNode r;
if (!projects.isEmpty()) {
relBuilder.push(oldInput).project(Iterables.concat(relBuilder.fields(), projects));
r = relBuilder.build();
} else {
r = oldInput;
}
return register(rel.getInput(0), r, frame.oldToNewOutputs, map);
}
}
int leftInputOutputCount = frame.r.getRowType().getFieldCount();
// can directly add positions into corDefOutputs since join
// does not change the output ordering from the inputs.
RelNode valueGen = createValueGenerator(corVarList, leftInputOutputCount, corDefOutputs);
RelNode join = relBuilder.push(frame.r).push(valueGen).join(JoinRelType.INNER, relBuilder.literal(true), ImmutableSet.of()).build();
// Filter) are in the output and in the same position.
return register(rel.getInput(0), join, frame.oldToNewOutputs, corDefOutputs);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.core.Filter in project beam by apache.
the class ExpressionConverter method convertIntervalToRexIntervalLiteral.
private RexNode convertIntervalToRexIntervalLiteral(ResolvedLiteral resolvedLiteral) {
if (resolvedLiteral.getType().getKind() != TYPE_STRING) {
throw new ZetaSqlException(INTERVAL_FORMAT_MSG);
}
String valStr = resolvedLiteral.getValue().getStringValue();
List<String> stringList = Arrays.stream(valStr.split(" ")).filter(s -> !s.isEmpty()).collect(Collectors.toList());
if (stringList.size() != 3) {
throw new ZetaSqlException(INTERVAL_FORMAT_MSG);
}
if (!Ascii.toUpperCase(stringList.get(0)).equals("INTERVAL")) {
throw new ZetaSqlException(INTERVAL_FORMAT_MSG);
}
long intervalValue;
try {
intervalValue = Long.parseLong(stringList.get(1));
} catch (NumberFormatException e) {
throw new ZetaSqlException(Status.UNIMPLEMENTED.withDescription(INTERVAL_FORMAT_MSG).withCause(e).asRuntimeException());
}
String intervalDatepart = Ascii.toUpperCase(stringList.get(2));
return createCalciteIntervalRexLiteral(intervalValue, intervalDatepart);
}
Aggregations