Java Code Examples for org.apache.calcite.tools.Frameworks#ConfigBuilder
The following examples show how to use
org.apache.calcite.tools.Frameworks#ConfigBuilder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NormalizationTrimFieldTest.java From calcite with Apache License 2.0 | 6 votes |
public static Frameworks.ConfigBuilder config() { final SchemaPlus rootSchema = Frameworks.createRootSchema(true); rootSchema.add("mv0", new AbstractTable() { @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) { return typeFactory.builder() .add("deptno", SqlTypeName.INTEGER) .add("count_sal", SqlTypeName.BIGINT) .build(); } }); return Frameworks.newConfigBuilder() .parserConfig(SqlParser.Config.DEFAULT) .defaultSchema( CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.SCOTT_WITH_TEMPORAL)) .traitDefs((List<RelTraitDef>) null); }
Example 2
Source File: RelBuilderTest.java From calcite with Apache License 2.0 | 6 votes |
/** Creates a config builder that will contain a view, "MYVIEW", and also * the SCOTT JDBC schema, whose tables implement * {@link org.apache.calcite.schema.TranslatableTable}. */ static Frameworks.ConfigBuilder expandingConfig(Connection connection) throws SQLException { final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); final SchemaPlus root = calciteConnection.getRootSchema(); CalciteAssert.SchemaSpec spec = CalciteAssert.SchemaSpec.SCOTT; CalciteAssert.addSchema(root, spec); final String viewSql = String.format(Locale.ROOT, "select * from \"%s\".\"%s\" where 1=1", spec.schemaName, "EMP"); // create view ViewTableMacro macro = ViewTable.viewMacro(root, viewSql, Collections.singletonList("test"), Arrays.asList("test", "view"), false); // register view (in root schema) root.add("MYVIEW", macro); return Frameworks.newConfigBuilder().defaultSchema(root); }
Example 3
Source File: RelBuilderTest.java From calcite with Apache License 2.0 | 6 votes |
/** * Ensures that relational algebra ({@link RelBuilder}) works with SQL views. * * <p>This test currently fails (thus ignored). */ @Test void testExpandViewInRelBuilder() throws SQLException { try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) { final Frameworks.ConfigBuilder configBuilder = expandingConfig(connection); final RelOptTable.ViewExpander viewExpander = (RelOptTable.ViewExpander) Frameworks.getPlanner(configBuilder.build()); configBuilder.context(Contexts.of(viewExpander)); final RelBuilder builder = RelBuilder.create(configBuilder.build()); RelNode node = builder.scan("MYVIEW").build(); int count = 0; try (PreparedStatement statement = connection.unwrap(RelRunner.class).prepare(node); ResultSet resultSet = statement.executeQuery()) { while (resultSet.next()) { count++; } } assertTrue(count > 1); } }
Example 4
Source File: RelBuilderTest.java From calcite with Apache License 2.0 | 6 votes |
@Test void testExpandViewShouldKeepAlias() throws SQLException { try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) { final Frameworks.ConfigBuilder configBuilder = expandingConfig(connection); final RelOptTable.ViewExpander viewExpander = (RelOptTable.ViewExpander) Frameworks.getPlanner(configBuilder.build()); configBuilder.context(Contexts.of(viewExpander)); final RelBuilder builder = RelBuilder.create(configBuilder.build()); RelNode node = builder.scan("MYVIEW") .project( builder.field(1, "MYVIEW", "EMPNO"), builder.field(1, "MYVIEW", "ENAME")) .build(); String expected = "LogicalProject(EMPNO=[$0], ENAME=[$1])\n" + " LogicalFilter(condition=[=(1, 1)])\n" + " LogicalTableScan(table=[[scott, EMP]])\n"; assertThat(node, hasTree(expected)); } }
Example 5
Source File: TpcdsLatticeSuggesterTest.java From calcite with Apache License 2.0 | 5 votes |
static Frameworks.ConfigBuilder config(CalciteAssert.SchemaSpec spec) { final SchemaPlus rootSchema = Frameworks.createRootSchema(true); final SchemaPlus schema = CalciteAssert.addSchema(rootSchema, spec); return Frameworks.newConfigBuilder() .parserConfig(SqlParser.Config.DEFAULT) .defaultSchema(schema); }
Example 6
Source File: TpcdsLatticeSuggesterTest.java From calcite with Apache License 2.0 | 5 votes |
Tester withEvolve(boolean evolve) { if (evolve == config.isEvolveLattice()) { return this; } final Frameworks.ConfigBuilder configBuilder = Frameworks.newConfigBuilder(config); return new Tester(configBuilder.evolveLattice(true).build()); }
Example 7
Source File: TpcdsTest.java From calcite with Apache License 2.0 | 5 votes |
public Frameworks.ConfigBuilder config() throws Exception { final Holder<SchemaPlus> root = Holder.of(null); CalciteAssert.model(TPCDS_MODEL) .doWithConnection(connection -> { root.set(connection.getRootSchema().getSubSchema("TPCDS")); }); return Frameworks.newConfigBuilder() .parserConfig(SqlParser.Config.DEFAULT) .defaultSchema(root.get()) .traitDefs((List<RelTraitDef>) null) .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2)); }
Example 8
Source File: RelFieldTrimmerTest.java From calcite with Apache License 2.0 | 5 votes |
public static Frameworks.ConfigBuilder config() { final SchemaPlus rootSchema = Frameworks.createRootSchema(true); return Frameworks.newConfigBuilder() .parserConfig(SqlParser.Config.DEFAULT) .defaultSchema( CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.SCOTT_WITH_TEMPORAL)) .traitDefs((List<RelTraitDef>) null) .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2)); }
Example 9
Source File: SqlStatisticProviderTest.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a config based on the "foodmart" schema. */ public static Frameworks.ConfigBuilder config() { final SchemaPlus rootSchema = Frameworks.createRootSchema(true); return Frameworks.newConfigBuilder() .parserConfig(SqlParser.Config.DEFAULT) .defaultSchema( CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.JDBC_FOODMART)) .traitDefs((List<RelTraitDef>) null) .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2)); }
Example 10
Source File: PigRelBuilderTest.java From calcite with Apache License 2.0 | 5 votes |
static PigRelBuilder createBuilder( UnaryOperator<RelBuilder.Config> transform) { final Frameworks.ConfigBuilder configBuilder = config(); configBuilder.context( Contexts.of(transform.apply(RelBuilder.Config.DEFAULT))); return PigRelBuilder.create(configBuilder.build()); }
Example 11
Source File: RelBuilderTest.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a config based on the "scott" schema. */ public static Frameworks.ConfigBuilder config() { final SchemaPlus rootSchema = Frameworks.createRootSchema(true); return Frameworks.newConfigBuilder() .parserConfig(SqlParser.Config.DEFAULT) .defaultSchema( CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.SCOTT_WITH_TEMPORAL)) .traitDefs((List<RelTraitDef>) null) .programs(Programs.heuristicJoinOrder(Programs.RULE_SET, true, 2)); }
Example 12
Source File: RelBuilderTest.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a RelBuilder with transformed config. */ static RelBuilder createBuilder(UnaryOperator<RelBuilder.Config> transform) { final Frameworks.ConfigBuilder configBuilder = config(); configBuilder.context( Contexts.of(transform.apply(RelBuilder.Config.DEFAULT))); return RelBuilder.create(configBuilder.build()); }
Example 13
Source File: RelBuilderTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testExpandTable() throws SQLException { try (Connection connection = DriverManager.getConnection("jdbc:calcite:")) { // RelBuilder expands as default. Plan contains JdbcTableScan, // because RelBuilder.scan has called RelOptTable.toRel. final Frameworks.ConfigBuilder configBuilder = expandingConfig(connection); final RelBuilder builder = RelBuilder.create(configBuilder.build()); final String expected = "LogicalFilter(condition=[>($2, 10)])\n" + " JdbcTableScan(table=[[JDBC_SCOTT, EMP]])\n"; checkExpandTable(builder, hasTree(expected)); } }
Example 14
Source File: RelOptUtilTest.java From calcite with Apache License 2.0 | 5 votes |
/** Creates a config based on the "scott" schema. */ private static Frameworks.ConfigBuilder config() { final SchemaPlus rootSchema = Frameworks.createRootSchema(true); return Frameworks.newConfigBuilder() .parserConfig(SqlParser.Config.DEFAULT) .defaultSchema(CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.SCOTT)); }
Example 15
Source File: LatticeSuggesterTest.java From calcite with Apache License 2.0 | 4 votes |
private Frameworks.ConfigBuilder builder() { return Frameworks.newConfigBuilder(config); }
Example 16
Source File: PigRelBuilderTest.java From calcite with Apache License 2.0 | 4 votes |
/** Creates a config based on the "scott" schema. */ public static Frameworks.ConfigBuilder config() { return RelBuilderTest.config(); }