use of 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.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.calcite.rel.RelNode in project hive by apache.
the class HiveSubQRemoveRelBuilder method convert.
/**
* Creates a projection that converts the current relational expression's
* output to a desired row type.
*
* @param castRowType row type after cast
* @param rename if true, use field names from castRowType; if false,
* preserve field names from rel
*/
public HiveSubQRemoveRelBuilder convert(RelDataType castRowType, boolean rename) {
final RelNode r = build();
final RelNode r2 = RelOptUtil.createCastRel(r, castRowType, rename, projectFactory);
push(r2);
return this;
}
use of org.apache.calcite.rel.RelNode in project hive by apache.
the class HiveSubQRemoveRelBuilder method scan.
// Methods that create relational expressions
/** Creates a {@link org.apache.calcite.rel.core.TableScan} of the table
* with a given name.
*
* <p>Throws if the table does not exist.
*
* <p>Returns this builder.
*
* @param tableNames Name of table (can optionally be qualified)
*/
public HiveSubQRemoveRelBuilder scan(Iterable<String> tableNames) {
final List<String> names = ImmutableList.copyOf(tableNames);
final RelOptTable relOptTable = relOptSchema.getTableForMember(names);
if (relOptTable == null) {
throw Static.RESOURCE.tableNotFound(Joiner.on(".").join(names)).ex();
}
final RelNode scan = scanFactory.createScan(cluster, relOptTable);
push(scan);
return this;
}
use of org.apache.calcite.rel.RelNode in project hive by apache.
the class HiveSubQRemoveRelBuilder method field.
/** As {@link #field(int, int, int)}, but if {@code alias} is true, the method
* may apply an alias to make sure that the field has the same name as in the
* input frame. If no alias is applied the expression is definitely a
* {@link RexInputRef}. */
private RexNode field(int inputCount, int inputOrdinal, int fieldOrdinal, boolean alias) {
final Frame frame = peek_(inputCount, inputOrdinal);
final RelNode input = frame.rel;
final RelDataType rowType = input.getRowType();
if (fieldOrdinal < 0 || fieldOrdinal > rowType.getFieldCount()) {
throw new IllegalArgumentException("field ordinal [" + fieldOrdinal + "] out of range; input fields are: " + rowType.getFieldNames());
}
final RelDataTypeField field = rowType.getFieldList().get(fieldOrdinal);
final int offset = inputOffset(inputCount, inputOrdinal);
final RexInputRef ref = cluster.getRexBuilder().makeInputRef(field.getType(), offset + fieldOrdinal);
final RelDataTypeField aliasField = frame.fields().get(fieldOrdinal);
if (!alias || field.getName().equals(aliasField.getName())) {
return ref;
} else {
return alias(ref, aliasField.getName());
}
}
Aggregations