Java Code Examples for org.apache.calcite.sql.util.ChainedSqlOperatorTable#of()
The following examples show how to use
org.apache.calcite.sql.util.ChainedSqlOperatorTable#of() .
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: PlanningConfigurationBuilder.java From flink with Apache License 2.0 | 6 votes |
/** * Returns the operator table for this environment including a custom Calcite configuration. */ private SqlOperatorTable getSqlOperatorTable(CalciteConfig calciteConfig, FunctionCatalog functionCatalog) { SqlOperatorTable baseOperatorTable = ChainedSqlOperatorTable.of( new BasicOperatorTable(), new FunctionCatalogOperatorTable(functionCatalog, typeFactory) ); return JavaScalaConversionUtil.toJava(calciteConfig.sqlOperatorTable()).map(operatorTable -> { if (calciteConfig.replacesSqlOperatorTable()) { return operatorTable; } else { return ChainedSqlOperatorTable.of(baseOperatorTable, operatorTable); } } ).orElse(baseOperatorTable); }
Example 2
Source File: PlanningConfigurationBuilder.java From flink with Apache License 2.0 | 6 votes |
/** * Returns the operator table for this environment including a custom Calcite configuration. */ private SqlOperatorTable getSqlOperatorTable(CalciteConfig calciteConfig, FunctionCatalog functionCatalog) { SqlOperatorTable baseOperatorTable = ChainedSqlOperatorTable.of( new BasicOperatorTable(), new FunctionCatalogOperatorTable(functionCatalog, typeFactory) ); return JavaScalaConversionUtil.toJava(calciteConfig.sqlOperatorTable()).map(operatorTable -> { if (calciteConfig.replacesSqlOperatorTable()) { return operatorTable; } else { return ChainedSqlOperatorTable.of(baseOperatorTable, operatorTable); } } ).orElse(baseOperatorTable); }
Example 3
Source File: PlannerImpl.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
private SqlValidator createSqlValidator(CalciteCatalogReader catalogReader) { final SqlOperatorTable opTab = ChainedSqlOperatorTable.of(operatorTable, catalogReader); return new CalciteSqlValidator(opTab, catalogReader, typeFactory, sqlValidatorConfig .withDefaultNullCollation(connectionConfig.defaultNullCollation()) .withLenientOperatorLookup(connectionConfig.lenientOperatorLookup()) .withSqlConformance(connectionConfig.conformance()) .withIdentifierExpansion(true)); }
Example 4
Source File: PlannerContext.java From flink with Apache License 2.0 | 5 votes |
/** * Returns builtin the operator table and external the operator for this environment. */ private SqlOperatorTable getBuiltinSqlOperatorTable() { return ChainedSqlOperatorTable.of( new FunctionCatalogOperatorTable( context.getFunctionCatalog(), context.getCatalogManager().getDataTypeFactory(), typeFactory), FlinkSqlOperatorTable.instance()); }
Example 5
Source File: PlannerImpl.java From calcite with Apache License 2.0 | 5 votes |
private SqlValidator createSqlValidator(CalciteCatalogReader catalogReader) { final SqlOperatorTable opTab = ChainedSqlOperatorTable.of(operatorTable, catalogReader); return new CalciteSqlValidator(opTab, catalogReader, typeFactory, sqlValidatorConfig .withDefaultNullCollation(connectionConfig.defaultNullCollation()) .withLenientOperatorLookup(connectionConfig.lenientOperatorLookup()) .withSqlConformance(connectionConfig.conformance()) .withIdentifierExpansion(true)); }
Example 6
Source File: PlannerTest.java From calcite with Apache License 2.0 | 5 votes |
@Test void testValidateUserDefinedAggregate() throws Exception { final SqlStdOperatorTable stdOpTab = SqlStdOperatorTable.instance(); SqlOperatorTable opTab = ChainedSqlOperatorTable.of(stdOpTab, new ListSqlOperatorTable( ImmutableList.of(new MyCountAggFunction()))); final SchemaPlus rootSchema = Frameworks.createRootSchema(true); final FrameworkConfig config = Frameworks.newConfigBuilder() .defaultSchema( CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.HR)) .operatorTable(opTab) .build(); final Planner planner = Frameworks.getPlanner(config); SqlNode parse = planner.parse("select \"deptno\", my_count(\"empid\") from \"emps\"\n" + "group by \"deptno\""); assertThat(Util.toLinux(parse.toString()), equalTo("SELECT `deptno`, `MY_COUNT`(`empid`)\n" + "FROM `emps`\n" + "GROUP BY `deptno`")); // MY_COUNT is recognized as an aggregate function, and therefore it is OK // that its argument empid is not in the GROUP BY clause. SqlNode validate = planner.validate(parse); assertThat(validate, notNullValue()); // The presence of an aggregate function in the SELECT clause causes it // to become an aggregate query. Non-aggregate expressions become illegal. planner.close(); planner.reset(); parse = planner.parse("select \"deptno\", count(1) from \"emps\""); try { validate = planner.validate(parse); fail("expected exception, got " + validate); } catch (ValidationException e) { assertThat(e.getCause().getCause().getMessage(), containsString("Expression 'deptno' is not being grouped")); } }
Example 7
Source File: PlannerContext.java From flink with Apache License 2.0 | 4 votes |
/** * Returns builtin the operator table and external the operator for this environment. */ private SqlOperatorTable getBuiltinSqlOperatorTable(FunctionCatalog functionCatalog) { return ChainedSqlOperatorTable.of( new FunctionCatalogOperatorTable(functionCatalog, typeFactory), FlinkSqlOperatorTable.instance()); }
Example 8
Source File: TableEnv.java From marble with Apache License 2.0 | 4 votes |
public TableEnv(TableConfig tableConfig) { try { this.tableConfig = tableConfig; SqlParser.Config sqlParserConfig = tableConfig.getSqlParserConfig() != null ? tableConfig.getSqlParserConfig() : SqlParser .configBuilder().setCaseSensitive(false) .build(); SqlOperatorTable sqlStdOperatorTable = tableConfig .getSqlOperatorTable() != null ? tableConfig.getSqlOperatorTable() : ChainedSqlOperatorTable.of(SqlStdOperatorTable.instance()); CalciteConnectionConfig calciteConnectionConfig = tableConfig .getCalciteConnectionConfig() != null ? tableConfig.getCalciteConnectionConfig() : createDefaultConnectionConfig(sqlParserConfig); RelDataTypeSystem typeSystem = tableConfig.getRelDataTypeSystem() != null ? tableConfig.getRelDataTypeSystem() : calciteConnectionConfig.typeSystem(RelDataTypeSystem.class, RelDataTypeSystem.DEFAULT); SqlRexConvertletTable convertletTable = tableConfig .getConvertletTable() != null ? tableConfig .getConvertletTable() : StandardConvertletTable.INSTANCE; RexExecutor rexExecutor = tableConfig.getRexExecutor() != null ? tableConfig.getRexExecutor() : RexUtil.EXECUTOR; this.calciteCatalogReader = new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(rootSchema).path(null), new JavaTypeFactoryImpl(typeSystem), calciteConnectionConfig); this.frameworkConfig = createFrameworkConfig(sqlParserConfig, ChainedSqlOperatorTable.of(sqlStdOperatorTable, calciteCatalogReader), convertletTable, calciteConnectionConfig, typeSystem, rexExecutor); } catch (Exception e) { throw new RuntimeException(e); } }