use of org.apache.calcite.plan.RelOptCluster in project beam by apache.
the class ZetaSQLPlannerImpl method rel.
public RelRoot rel(String sql, QueryParameters params) {
RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory));
AnalyzerOptions options = SqlAnalyzer.getAnalyzerOptions(params, defaultTimezone);
BeamZetaSqlCatalog catalog = BeamZetaSqlCatalog.create(defaultSchemaPlus, (JavaTypeFactory) cluster.getTypeFactory(), options);
// Set up table providers that need to be pre-registered
SqlAnalyzer analyzer = new SqlAnalyzer();
List<List<String>> tables = analyzer.extractTableNames(sql, options);
TableResolution.registerTables(this.defaultSchemaPlus, tables);
QueryTrait trait = new QueryTrait();
catalog.addTables(tables, trait);
ResolvedQueryStmt statement = analyzer.analyzeQuery(sql, options, catalog);
ExpressionConverter expressionConverter = new ExpressionConverter(cluster, params, catalog.getUserFunctionDefinitions());
ConversionContext context = ConversionContext.of(config, expressionConverter, cluster, trait);
RelNode convertedNode = QueryStatementConverter.convertRootQuery(context, statement);
return RelRoot.of(convertedNode, SqlKind.ALL);
}
use of org.apache.calcite.plan.RelOptCluster in project flink by apache.
the class HiveParserUtils method genValuesRelNode.
// creates LogicalValues node
public static RelNode genValuesRelNode(RelOptCluster cluster, RelDataType rowType, List<List<RexLiteral>> rows) {
List<Object> immutableRows = rows.stream().map(HiveParserUtils::toImmutableList).collect(Collectors.toList());
Class[] argTypes = new Class[] { RelOptCluster.class, RelDataType.class, null };
if (useShadedImmutableList) {
argTypes[2] = HiveParserUtils.shadedImmutableListClz;
} else {
argTypes[2] = HiveParserUtils.immutableListClz;
}
Method method = HiveReflectionUtils.tryGetMethod(LogicalValues.class, "create", argTypes);
Preconditions.checkState(method != null, "Cannot get the method to create LogicalValues");
try {
return (RelNode) method.invoke(null, cluster, rowType, HiveParserUtils.toImmutableList(immutableRows));
} catch (IllegalAccessException | InvocationTargetException e) {
throw new FlinkHiveException("Failed to create LogicalValues", e);
}
}
use of org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class EnumerableSort method create.
/**
* Creates an EnumerableSort.
*/
public static EnumerableSort create(RelNode child, RelCollation collation, RexNode offset, RexNode fetch) {
final RelOptCluster cluster = child.getCluster();
final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE).replace(collation);
return new EnumerableSort(cluster, traitSet, child, collation, offset, fetch);
}
use of org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class EnumerableFilter method create.
/**
* Creates an EnumerableFilter.
*/
public static EnumerableFilter create(final RelNode input, RexNode condition) {
final RelOptCluster cluster = input.getCluster();
final RelMetadataQuery mq = cluster.getMetadataQuery();
final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE).replaceIfs(RelCollationTraitDef.INSTANCE, new Supplier<List<RelCollation>>() {
public List<RelCollation> get() {
return RelMdCollation.filter(mq, input);
}
}).replaceIf(RelDistributionTraitDef.INSTANCE, new Supplier<RelDistribution>() {
public RelDistribution get() {
return RelMdDistribution.filter(mq, input);
}
});
return new EnumerableFilter(cluster, traitSet, input, condition);
}
use of org.apache.calcite.plan.RelOptCluster in project calcite by apache.
the class EnumerableJoin method create.
/**
* Creates an EnumerableJoin.
*/
public static EnumerableJoin create(RelNode left, RelNode right, RexNode condition, ImmutableIntList leftKeys, ImmutableIntList rightKeys, Set<CorrelationId> variablesSet, JoinRelType joinType) throws InvalidRelException {
final RelOptCluster cluster = left.getCluster();
final RelTraitSet traitSet = cluster.traitSetOf(EnumerableConvention.INSTANCE);
return new EnumerableJoin(cluster, traitSet, left, right, condition, leftKeys, rightKeys, variablesSet, joinType);
}
Aggregations