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);
}
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();
}
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);
}
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();
}
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();
}
Aggregations