use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context in project beam by apache.
the class SqlDdlNodes method schema.
/**
* Returns the schema in which to create an object.
*/
static Pair<CalciteSchema, String> schema(CalcitePrepare.Context context, boolean mutable, SqlIdentifier id) {
final List<String> path;
if (id.isSimple()) {
path = context.getDefaultSchemaPath();
} else {
path = Util.skipLast(id.names);
}
CalciteSchema schema = mutable ? context.getMutableRootSchema() : context.getRootSchema();
for (String p : path) {
schema = schema.getSubSchema(p, true);
if (schema == null) {
throw new AssertionError(String.format("Got null sub-schema for path '%s' in %s", p, path));
}
}
return Pair.of(schema, name(id));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context in project beam by apache.
the class BigQueryTable method generateRowRestrictions.
private String generateRowRestrictions(Schema schema, List<RexNode> supported) {
assert !supported.isEmpty();
final IntFunction<SqlNode> field = i -> new SqlIdentifier(schema.getField(i).getName(), SqlParserPos.ZERO);
// TODO: BigQuerySqlDialectWithTypeTranslation can be replaced with BigQuerySqlDialect after
// updating vendor Calcite version.
SqlImplementor.Context context = new BeamSqlUnparseContext(field);
// Create a single SqlNode from a list of RexNodes
SqlNode andSqlNode = null;
for (RexNode node : supported) {
SqlNode sqlNode = context.toSql(null, node);
if (andSqlNode == null) {
andSqlNode = sqlNode;
continue;
}
// AND operator must have exactly 2 operands.
andSqlNode = SqlStdOperatorTable.AND.createCall(SqlParserPos.ZERO, ImmutableList.of(andSqlNode, sqlNode));
}
return andSqlNode.toSqlString(BeamBigQuerySqlDialect.DEFAULT).getSql();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context in project beam by apache.
the class ZetaSqlTestBase method initialize.
protected void initialize() {
JdbcConnection jdbcConnection = JdbcDriver.connect(createBeamTableProvider(), PipelineOptionsFactory.create());
this.config = Frameworks.newConfigBuilder().defaultSchema(jdbcConnection.getCurrentSchemaPlus()).traitDefs(ImmutableList.of(ConventionTraitDef.INSTANCE)).context(Contexts.of(jdbcConnection.config())).ruleSets(ZetaSQLQueryPlanner.getZetaSqlRuleSets().toArray(new RuleSet[0])).costFactory(BeamCostModel.FACTORY).typeSystem(jdbcConnection.getTypeFactory().getTypeSystem()).build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context in project hive by apache.
the class HiveRelMdRuntimeRowCount method getRuntimeRowCount.
public Optional<Long> getRuntimeRowCount(RelNode rel) {
RelOptCluster cluster = rel.getCluster();
Context context = cluster.getPlanner().getContext();
if (context instanceof HivePlannerContext) {
StatsSource ss = ((HivePlannerContext) context).unwrap(StatsSource.class);
if (ss.canProvideStatsFor(rel.getClass())) {
Optional<OperatorStats> os = ss.lookup(RelTreeSignature.of(rel));
if (os.isPresent()) {
long outputRecords = os.get().getOutputRecords();
return Optional.of(outputRecords);
}
}
}
return Optional.empty();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context in project calcite by apache.
the class PlannerImpl method createCatalogReader.
// CalciteCatalogReader is stateless; no need to store one
private CalciteCatalogReader createCatalogReader() {
final SchemaPlus rootSchema = rootSchema(defaultSchema);
final Context context = config.getContext();
final CalciteConnectionConfig connectionConfig;
if (context != null) {
connectionConfig = context.unwrap(CalciteConnectionConfig.class);
} else {
Properties properties = new Properties();
properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive()));
connectionConfig = new CalciteConnectionConfigImpl(properties);
}
return new CalciteCatalogReader(CalciteSchema.from(rootSchema), CalciteSchema.from(defaultSchema).path(null), typeFactory, connectionConfig);
}
Aggregations