Search in sources :

Example 6 with RuleSet

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();
}
Also used : RuleSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet) JdbcConnection(org.apache.beam.sdk.extensions.sql.impl.JdbcConnection)

Example 7 with RuleSet

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);
}
Also used : RuleSet(org.apache.calcite.tools.RuleSet) HepProgram(org.apache.calcite.plan.hep.HepProgram) UnionMergeRule(org.apache.calcite.rel.rules.UnionMergeRule) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) HepPlanner(org.apache.calcite.plan.hep.HepPlanner) Test(org.junit.Test)

Example 8 with RuleSet

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");
}
Also used : TimeMonitor(org.apache.beam.sdk.testutils.metrics.TimeMonitor) RuleSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet) BeamRelNode(org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode) ArrayList(java.util.ArrayList) PipelineResult(org.apache.beam.sdk.PipelineResult) InMemoryMetaStore(org.apache.beam.sdk.extensions.sql.meta.store.InMemoryMetaStore) RelOptRule(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule) Test(org.junit.Test)

Example 9 with RuleSet

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();
}
Also used : RuleSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet) CalciteCatalogReader(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.CalciteCatalogReader) CalciteConnectionConfig(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.config.CalciteConnectionConfig) RelTraitDef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef) SqlOperatorTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.SqlOperatorTable) SqlParser(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser) SchemaPlus(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus) SqlParserImplFactory(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParserImplFactory)

Example 10 with RuleSet

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();
}
Also used : Context(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context) RuleSet(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet) RelTraitDef(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef) SchemaPlus(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus) JdbcConnection(org.apache.beam.sdk.extensions.sql.impl.JdbcConnection)

Aggregations

RuleSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet)10 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)6 Test (org.junit.Test)6 RelNode (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.RelNode)5 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)5 RelOptRule (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptRule)3 RelTraitDef (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef)3 SqlParser (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.sql.parser.SqlParser)3 ArrayList (java.util.ArrayList)2 JdbcConnection (org.apache.beam.sdk.extensions.sql.impl.JdbcConnection)2 CalciteConnectionConfig (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.config.CalciteConnectionConfig)2 RelTraitSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitSet)2 CalciteCatalogReader (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.CalciteCatalogReader)2 JoinCommuteRule (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rel.rules.JoinCommuteRule)2 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)2 RelOptRule (org.apache.calcite.plan.RelOptRule)2 RelTraitSet (org.apache.calcite.plan.RelTraitSet)2 HepPlanner (org.apache.calcite.plan.hep.HepPlanner)2 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)2 VolcanoPlanner (org.apache.calcite.plan.volcano.VolcanoPlanner)2