use of org.apache.beam.vendor.calcite.v1_28_0.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.beam.vendor.calcite.v1_28_0.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();
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context 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.plan.Context in project beam by apache.
the class ZetaSQLPlannerImpl method rel.
public RelRoot rel(String sql, QueryParameters params) {
RelOptCluster cluster = RelOptCluster.create(planner, new RexBuilder(typeFactory));
AnalyzerOptions options = SqlAnalyzer.getAnalyzerOptions(params, defaultTimezone);
BeamZetaSqlCatalog catalog = BeamZetaSqlCatalog.create(defaultSchemaPlus, (JavaTypeFactory) cluster.getTypeFactory(), options);
// Set up table providers that need to be pre-registered
SqlAnalyzer analyzer = new SqlAnalyzer();
List<List<String>> tables = analyzer.extractTableNames(sql, options);
TableResolution.registerTables(this.defaultSchemaPlus, tables);
QueryTrait trait = new QueryTrait();
catalog.addTables(tables, trait);
ResolvedQueryStmt statement = analyzer.analyzeQuery(sql, options, catalog);
ExpressionConverter expressionConverter = new ExpressionConverter(cluster, params, catalog.getUserFunctionDefinitions());
ConversionContext context = ConversionContext.of(config, expressionConverter, cluster, trait);
RelNode convertedNode = QueryStatementConverter.convertRootQuery(context, statement);
return RelRoot.of(convertedNode, SqlKind.ALL);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.Context 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