use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.
the class StormSqlImpl method execute.
@Override
public void execute(Iterable<String> statements, ChannelHandler result) throws Exception {
Map<String, DataSource> dataSources = new HashMap<>();
for (String sql : statements) {
StormParser parser = new StormParser(sql);
SqlNode node = parser.impl().parseSqlStmtEof();
if (node instanceof SqlCreateTable) {
handleCreateTable((SqlCreateTable) node, dataSources);
} else if (node instanceof SqlCreateFunction) {
handleCreateFunction((SqlCreateFunction) node);
} else {
FrameworkConfig config = buildFrameWorkConfig();
Planner planner = Frameworks.getPlanner(config);
SqlNode parse = planner.parse(sql);
SqlNode validate = planner.validate(parse);
RelNode tree = planner.convert(validate);
PlanCompiler compiler = new PlanCompiler(typeFactory);
AbstractValuesProcessor proc = compiler.compile(tree);
proc.initialize(dataSources, result);
}
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project storm by apache.
the class PlanCompiler method doChainOperators.
private void doChainOperators(PrintWriter pw, RelNode node, Set<TableScan> tables, String parentCtx) {
pw.print(String.format(" ChannelContext CTX_%d = Channels.chain(%2$s, %3$s);\n", node.getId(), parentCtx, RelNodeCompiler.getStageName(node)));
String currentCtx = String.format("CTX_%d", node.getId());
if (node instanceof TableScan) {
tables.add((TableScan) node);
}
for (RelNode i : node.getInputs()) {
doChainOperators(pw, i, tables, currentCtx);
}
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project flink by apache.
the class FlinkRelDecorrelator method decorrelateRel.
/**
* Rewrite LogicalFilter.
*
* @param rel the filter rel to rewrite
*/
public Frame decorrelateRel(LogicalFilter rel) {
//
// Rewrite logic:
//
// 1. If a LogicalFilter references a correlated field in its filter
// condition, rewrite the LogicalFilter to be
// LogicalFilter
// LogicalJoin(cross product)
// OriginalFilterInput
// ValueGenerator(produces distinct sets of correlated variables)
// and rewrite the correlated fieldAccess in the filter condition to
// reference the LogicalJoin output.
//
// 2. If LogicalFilter does not reference correlated variables, simply
// rewrite the filter condition using new input.
//
final RelNode oldInput = rel.getInput();
Frame frame = getInvoke(oldInput, rel);
if (frame == null) {
// If input has not been rewritten, do not rewrite this rel.
return null;
}
// and produce the correlated variables in the new output.
if (cm.mapRefRelToCorVar.containsKey(rel)) {
decorrelateInputWithValueGenerator(rel);
// The old input should be mapped to the newly created LogicalJoin by
// rewriteInputWithValueGenerator().
frame = map.get(oldInput);
}
// Replace the filter expression to reference output of the join
// Map filter to the new filter over join
RelNode newFilter = RelOptUtil.createFilter(frame.r, decorrelateExpr(rel.getCondition()));
// input rel.
return register(rel, newFilter, frame.oldToNewOutputPos, frame.corVarOutputPos);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project flink by apache.
the class FlinkRelDecorrelator method createCopyHook.
private Function2<RelNode, RelNode, Void> createCopyHook() {
return new Function2<RelNode, RelNode, Void>() {
public Void apply(RelNode oldNode, RelNode newNode) {
if (cm.mapRefRelToCorVar.containsKey(oldNode)) {
cm.mapRefRelToCorVar.putAll(newNode, cm.mapRefRelToCorVar.get(oldNode));
}
if (oldNode instanceof LogicalCorrelate && newNode instanceof LogicalCorrelate) {
LogicalCorrelate oldCor = (LogicalCorrelate) oldNode;
CorrelationId c = oldCor.getCorrelationId();
if (cm.mapCorVarToCorRel.get(c) == oldNode) {
cm.mapCorVarToCorRel.put(c, newNode);
}
if (generatedCorRels.contains(oldNode)) {
generatedCorRels.add((LogicalCorrelate) newNode);
}
}
return null;
}
};
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode in project flink by apache.
the class FlinkRelDecorrelator method getNewForOldInputRef.
private RexInputRef getNewForOldInputRef(RexInputRef oldInputRef) {
assert currentRel != null;
int oldOrdinal = oldInputRef.getIndex();
int newOrdinal = 0;
// determine which input rel oldOrdinal references, and adjust
// oldOrdinal to be relative to that input rel
RelNode oldInput = null;
for (RelNode oldInput0 : currentRel.getInputs()) {
RelDataType oldInputType = oldInput0.getRowType();
int n = oldInputType.getFieldCount();
if (oldOrdinal < n) {
oldInput = oldInput0;
break;
}
RelNode newInput = map.get(oldInput0).r;
newOrdinal += newInput.getRowType().getFieldCount();
oldOrdinal -= n;
}
assert oldInput != null;
final Frame frame = map.get(oldInput);
assert frame != null;
// now oldOrdinal is relative to oldInput
int oldLocalOrdinal = oldOrdinal;
// figure out the newLocalOrdinal, relative to the newInput.
int newLocalOrdinal = oldLocalOrdinal;
if (!frame.oldToNewOutputPos.isEmpty()) {
newLocalOrdinal = frame.oldToNewOutputPos.get(oldLocalOrdinal);
}
newOrdinal += newLocalOrdinal;
return new RexInputRef(newOrdinal, frame.r.getRowType().getFieldList().get(newLocalOrdinal).getType());
}
Aggregations