Search in sources :

Example 1 with Context

use of org.apache.calcite.plan.Context in project flink by apache.

the class PlannerContext method createRelBuilder.

/**
 * Creates a configured {@link FlinkRelBuilder} for a planning session.
 *
 * @param currentCatalog the current default catalog to look for first during planning.
 * @param currentDatabase the current default database to look for first during planning.
 * @return configured rel builder
 */
public FlinkRelBuilder createRelBuilder(String currentCatalog, String currentDatabase) {
    FlinkCalciteCatalogReader relOptSchema = createCatalogReader(false, currentCatalog, currentDatabase);
    Context chain = Contexts.of(context, // Sets up the ViewExpander explicitly for FlinkRelBuilder.
    createFlinkPlanner(currentCatalog, currentDatabase).createToRelContext());
    return new FlinkRelBuilder(chain, cluster, relOptSchema);
}
Also used : Context(org.apache.calcite.plan.Context) FlinkContext(org.apache.flink.table.planner.calcite.FlinkContext) FlinkRelBuilder(org.apache.flink.table.planner.calcite.FlinkRelBuilder) FlinkCalciteCatalogReader(org.apache.flink.table.planner.plan.FlinkCalciteCatalogReader)

Example 2 with Context

use of 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();
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) Context(org.apache.calcite.plan.Context) HivePlannerContext(org.apache.hadoop.hive.ql.optimizer.calcite.HivePlannerContext) HivePlannerContext(org.apache.hadoop.hive.ql.optimizer.calcite.HivePlannerContext) OperatorStats(org.apache.hadoop.hive.ql.stats.OperatorStats) StatsSource(org.apache.hadoop.hive.ql.plan.mapper.StatsSource)

Example 3 with Context

use of 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);
}
Also used : Context(org.apache.calcite.plan.Context) CalciteConnectionConfigImpl(org.apache.calcite.config.CalciteConnectionConfigImpl) CalciteConnectionConfig(org.apache.calcite.config.CalciteConnectionConfig) SchemaPlus(org.apache.calcite.schema.SchemaPlus) Properties(java.util.Properties)

Example 4 with Context

use of org.apache.calcite.plan.Context in project calcite by apache.

the class RelOptRulesTest method testExtractYearMonthToRange.

@Test
public void testExtractYearMonthToRange() {
    final String sql = "select *\n" + "from sales.emp_b as e\n" + "where extract(year from birthdate) = 2014" + "and extract(month from birthdate) = 4";
    HepProgram program = new HepProgramBuilder().addRuleInstance(DateRangeRules.FILTER_INSTANCE).build();
    final Context context = Contexts.of(new CalciteConnectionConfigImpl(new Properties()));
    sql(sql).with(program).withContext(context).check();
}
Also used : Context(org.apache.calcite.plan.Context) CalciteConnectionConfigImpl(org.apache.calcite.config.CalciteConnectionConfigImpl) HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Properties(java.util.Properties) Test(org.junit.Test)

Example 5 with Context

use of org.apache.calcite.plan.Context in project calcite by apache.

the class RelOptRulesTest method testExtractYearToRange.

/**
 * Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-434">[CALCITE-434]
 * Converting predicates on date dimension columns into date ranges</a>,
 * specifically a rule that converts {@code EXTRACT(YEAR FROM ...) = constant}
 * to a range.
 */
@Test
public void testExtractYearToRange() {
    final String sql = "select *\n" + "from sales.emp_b as e\n" + "where extract(year from birthdate) = 2014";
    HepProgram program = new HepProgramBuilder().addRuleInstance(DateRangeRules.FILTER_INSTANCE).build();
    final Context context = Contexts.of(new CalciteConnectionConfigImpl(new Properties()));
    sql(sql).with(program).withContext(context).check();
}
Also used : Context(org.apache.calcite.plan.Context) CalciteConnectionConfigImpl(org.apache.calcite.config.CalciteConnectionConfigImpl) HepProgram(org.apache.calcite.plan.hep.HepProgram) HepProgramBuilder(org.apache.calcite.plan.hep.HepProgramBuilder) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Context (org.apache.calcite.plan.Context)5 Properties (java.util.Properties)3 CalciteConnectionConfigImpl (org.apache.calcite.config.CalciteConnectionConfigImpl)3 HepProgram (org.apache.calcite.plan.hep.HepProgram)2 HepProgramBuilder (org.apache.calcite.plan.hep.HepProgramBuilder)2 Test (org.junit.Test)2 JdbcConnection (org.apache.beam.sdk.extensions.sql.impl.JdbcConnection)1 Context (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context)1 RelTraitDef (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelTraitDef)1 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)1 RuleSet (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.tools.RuleSet)1 CalciteConnectionConfig (org.apache.calcite.config.CalciteConnectionConfig)1 RelOptCluster (org.apache.calcite.plan.RelOptCluster)1 SchemaPlus (org.apache.calcite.schema.SchemaPlus)1 FlinkContext (org.apache.flink.table.planner.calcite.FlinkContext)1 FlinkRelBuilder (org.apache.flink.table.planner.calcite.FlinkRelBuilder)1 FlinkCalciteCatalogReader (org.apache.flink.table.planner.plan.FlinkCalciteCatalogReader)1 HivePlannerContext (org.apache.hadoop.hive.ql.optimizer.calcite.HivePlannerContext)1 StatsSource (org.apache.hadoop.hive.ql.plan.mapper.StatsSource)1 OperatorStats (org.apache.hadoop.hive.ql.stats.OperatorStats)1