use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet 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.tools.RuleSet in project calcite by apache.
the class RelToSqlConverterTest method testThreeQueryUnion.
/**
* Test case for
* <a href="https://issues.apache.org/jira/browse/CALCITE-1586">[CALCITE-1586]
* JDBC adapter generates wrong SQL if UNION has more than two inputs</a>.
*/
@Test
public void testThreeQueryUnion() {
String query = "SELECT \"product_id\" FROM \"product\" " + " UNION ALL " + "SELECT \"product_id\" FROM \"sales_fact_1997\" " + " UNION ALL " + "SELECT \"product_class_id\" AS product_id FROM \"product_class\"";
String expected = "SELECT \"product_id\"\n" + "FROM \"foodmart\".\"product\"\n" + "UNION ALL\n" + "SELECT \"product_id\"\n" + "FROM \"foodmart\".\"sales_fact_1997\"\n" + "UNION ALL\n" + "SELECT \"product_class_id\" AS \"PRODUCT_ID\"\n" + "FROM \"foodmart\".\"product_class\"";
final HepProgram program = new HepProgramBuilder().addRuleClass(UnionMergeRule.class).build();
final RuleSet rules = RuleSets.ofList(UnionMergeRule.INSTANCE);
sql(query).optimize(rules, new HepPlanner(program)).ok(expected);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet in project beam by apache.
the class BigQueryIOPushDownIT method readUsingDirectReadMethod.
@Test
public void readUsingDirectReadMethod() {
List<RelOptRule> ruleList = new ArrayList<>();
for (RuleSet x : getRuleSets()) {
x.iterator().forEachRemaining(ruleList::add);
}
// Remove push-down rule
ruleList.remove(BeamIOPushDownRule.INSTANCE);
InMemoryMetaStore inMemoryMetaStore = new InMemoryMetaStore();
inMemoryMetaStore.registerProvider(new BigQueryPerfTableProvider(NAMESPACE, FIELDS_READ_METRIC));
sqlEnv = BeamSqlEnv.builder(inMemoryMetaStore).setPipelineOptions(PipelineOptionsFactory.create()).setRuleSets(ImmutableList.of(RuleSets.ofList(ruleList))).build();
sqlEnv.executeDdl(String.format(CREATE_TABLE_STATEMENT, Method.DIRECT_READ.toString()));
BeamRelNode beamRelNode = sqlEnv.parseQuery(SELECT_STATEMENT);
BeamSqlRelUtils.toPCollection(pipeline, beamRelNode).apply(ParDo.of(new TimeMonitor<>(NAMESPACE, READ_TIME_METRIC)));
PipelineResult result = pipeline.run();
result.waitUntilFinish();
collectAndPublishMetrics(result, "_directread");
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet in project beam by apache.
the class CalciteQueryPlanner method defaultConfig.
public FrameworkConfig defaultConfig(JdbcConnection connection, Collection<RuleSet> ruleSets) {
final CalciteConnectionConfig config = connection.config();
final SqlParser.ConfigBuilder parserConfig = SqlParser.configBuilder().setQuotedCasing(config.quotedCasing()).setUnquotedCasing(config.unquotedCasing()).setQuoting(config.quoting()).setConformance(config.conformance()).setCaseSensitive(config.caseSensitive());
final SqlParserImplFactory parserFactory = config.parserFactory(SqlParserImplFactory.class, null);
if (parserFactory != null) {
parserConfig.setParserFactory(parserFactory);
}
final SchemaPlus schema = connection.getRootSchema();
final SchemaPlus defaultSchema = connection.getCurrentSchemaPlus();
final ImmutableList<RelTraitDef> traitDefs = ImmutableList.of(ConventionTraitDef.INSTANCE);
final CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(schema), ImmutableList.of(defaultSchema.getName()), connection.getTypeFactory(), connection.config());
final SqlOperatorTable opTab0 = connection.config().fun(SqlOperatorTable.class, SqlStdOperatorTable.instance());
return Frameworks.newConfigBuilder().parserConfig(parserConfig.build()).defaultSchema(defaultSchema).traitDefs(traitDefs).context(Contexts.of(connection.config())).ruleSets(ruleSets.toArray(new RuleSet[0])).costFactory(BeamCostModel.FACTORY).typeSystem(connection.getTypeFactory().getTypeSystem()).operatorTable(SqlOperatorTables.chain(opTab0, catalogReader)).build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet in project beam by apache.
the class ZetaSQLPushDownTest method initializeCalciteEnvironmentWithContext.
private static void initializeCalciteEnvironmentWithContext(Context... extraContext) {
JdbcConnection jdbcConnection = JdbcDriver.connect(tableProvider, PipelineOptionsFactory.create());
SchemaPlus defaultSchemaPlus = jdbcConnection.getCurrentSchemaPlus();
final ImmutableList<RelTraitDef> traitDefs = ImmutableList.of(ConventionTraitDef.INSTANCE);
Object[] contexts = ImmutableList.<Context>builder().add(Contexts.of(jdbcConnection.config())).add(extraContext).build().toArray();
config = Frameworks.newConfigBuilder().defaultSchema(defaultSchemaPlus).traitDefs(traitDefs).context(Contexts.of(contexts)).ruleSets(ZetaSQLQueryPlanner.getZetaSqlRuleSets().toArray(new RuleSet[0])).costFactory(BeamCostModel.FACTORY).typeSystem(jdbcConnection.getTypeFactory().getTypeSystem()).build();
}
Aggregations