public FrameworkConfig buildFrameWorkConfig() { if (hasUdf) { List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>(); sqlOperatorTables.add(SqlStdOperatorTable.instance()); sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), Collections.emptyList(), typeFactory, new CalciteConnectionConfigImpl(new Properties()))); return Frameworks.newConfigBuilder().defaultSchema(schema) .operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build(); } else { return Frameworks.newConfigBuilder().defaultSchema(schema).build(); } }
public <T> T fun(Class<T> operatorTableClass, T defaultOperatorTable) { final String fun = CalciteConnectionProperty.FUN.wrap(properties).getString(); if (fun == null || fun.equals("") || fun.equals("standard")) { return defaultOperatorTable; } final Collection<SqlOperatorTable> tables = new LinkedHashSet<>(); for (String s : fun.split(",")) { operatorTable(s, tables); } tables.add(SqlStdOperatorTable.instance()); return operatorTableClass.cast( ChainedSqlOperatorTable.of( tables.toArray(new SqlOperatorTable[0]))); }
public <T> T fun(Class<T> operatorTableClass, T defaultOperatorTable) { final String fun = CalciteConnectionProperty.FUN.wrap(properties).getString(); if (fun == null || fun.equals("") || fun.equals("standard")) { return defaultOperatorTable; } final Collection<SqlOperatorTable> tables = new LinkedHashSet<>(); for (String s : fun.split(",")) { operatorTable(s, tables); } tables.add(SqlStdOperatorTable.instance()); return operatorTableClass.cast( ChainedSqlOperatorTable.of( tables.toArray(new SqlOperatorTable[0]))); }
public QueryPlanner(SchemaPlus schema) { final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>(); traitDefs.add(ConventionTraitDef.INSTANCE); traitDefs.add(RelCollationTraitDef.INSTANCE); List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>(); sqlOperatorTables.add(SqlStdOperatorTable.instance()); sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), Collections.emptyList(), typeFactory, new CalciteConnectionConfigImpl(new Properties()))); FrameworkConfig config = Frameworks.newConfigBuilder() .defaultSchema(schema) .operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)) .traitDefs(traitDefs) .context(Contexts.EMPTY_CONTEXT) .ruleSets(StreamsStormRuleSets.getRuleSets()) .costFactory(null) .typeSystem(StormRelDataTypeSystem.STORM_REL_DATATYPE_SYSTEM) .build(); this.planner = Frameworks.getPlanner(config); }
private SqlValidator createSqlValidator(Context context, CalciteCatalogReader catalogReader) { final SqlOperatorTable opTab0 = context.config().fun(SqlOperatorTable.class, SqlStdOperatorTable.instance()); final SqlOperatorTable opTab = ChainedSqlOperatorTable.of(opTab0, catalogReader); final JavaTypeFactory typeFactory = context.getTypeFactory(); final SqlConformance conformance = context.config().conformance(); return new CalciteSqlValidator(opTab, catalogReader, typeFactory, conformance); }
/** Creates a {@code ChainedSqlOperatorTable}. */ public static SqlOperatorTable of(SqlOperatorTable... tables) { return new ChainedSqlOperatorTable(ImmutableList.copyOf(tables)); }
private SqlValidator createSqlValidator(Context context, CalciteCatalogReader catalogReader) { final SqlOperatorTable opTab0 = context.config().fun(SqlOperatorTable.class, SqlStdOperatorTable.instance()); final SqlOperatorTable opTab = ChainedSqlOperatorTable.of(opTab0, catalogReader); final JavaTypeFactory typeFactory = context.getTypeFactory(); final SqlConformance conformance = context.config().conformance(); return new CalciteSqlValidator(opTab, catalogReader, typeFactory, conformance); }
/** Creates a {@code ChainedSqlOperatorTable}. */ public static SqlOperatorTable of(SqlOperatorTable... tables) { return new ChainedSqlOperatorTable(ImmutableList.copyOf(tables)); }
private SqlValidator createSqlValidator(Context context, CalciteCatalogReader catalogReader) { final SqlOperatorTable opTab0 = context.config().fun(SqlOperatorTable.class, SqlStdOperatorTable.instance()); final SqlOperatorTable opTab = ChainedSqlOperatorTable.of(opTab0, catalogReader); final JavaTypeFactory typeFactory = context.getTypeFactory(); final SqlConformance conformance = context.config().conformance(); return new CalciteSqlValidator(opTab, catalogReader, typeFactory, conformance); }
private FrameworkConfig buildFrameWorkConfig() { if (hasUdf) { List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>(); sqlOperatorTables.add(SqlStdOperatorTable.instance()); sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), false, Collections.<String>emptyList(), typeFactory)); return Frameworks.newConfigBuilder().defaultSchema(schema) .operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build(); } else { return Frameworks.newConfigBuilder().defaultSchema(schema).build(); } } }
public FlinkPlannerImpl(FrameworkConfig frameworkConfig) { this.relBuilder = BlinkRelBuilder.create(frameworkConfig); this.planner = relBuilder.getPlanner(); this.typeFactory = relBuilder.getTypeFactory(); this.traitDefs = frameworkConfig.getTraitDefs(); this.parserConfig = frameworkConfig.getParserConfig(); this.convertletTable = frameworkConfig.getConvertletTable(); this.defaultSchema = frameworkConfig.getDefaultSchema(); SqlOperatorTable builtinOperatorTable = frameworkConfig.getOperatorTable(); CalciteCatalogReader catalogReader = this.createCatalogReader(); this.operatorTable = ChainedSqlOperatorTable.of(builtinOperatorTable, catalogReader); this.validator = new FlinkSqlValidator(this.operatorTable, catalogReader, this.typeFactory); this.validator.setIdentifierExpansion(true); }
.parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).build()) .defaultSchema(rootSchema) .operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)) .traitDefs(traitDefs) .context(Contexts.EMPTY_CONTEXT)
protected SqlTester oracleTester() { return tester.withOperatorTable( ChainedSqlOperatorTable.of(OracleSqlOperatorTable.instance(), SqlStdOperatorTable.instance())) .withConnectionFactory( CalciteAssert.EMPTY_CONNECTION_FACTORY .with(new CalciteAssert .AddSchemaSpecPostProcessor(CalciteAssert.SchemaSpec.HR)) .with(CalciteConnectionProperty.FUN, "oracle")); }
.parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).build()) .defaultSchema(rootSchema) .operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)) .traitDefs(traitDefs) .context(Contexts.EMPTY_CONTEXT)
protected SqlTester oracleTester() { return tester.withOperatorTable( ChainedSqlOperatorTable.of(OracleSqlOperatorTable.instance(), SqlStdOperatorTable.instance())) .withConnectionFactory( CalciteAssert.EMPTY_CONNECTION_FACTORY .with(new CalciteAssert .AddSchemaSpecPostProcessor(CalciteAssert.SchemaSpec.HR)) .with(CalciteConnectionProperty.FUN, "oracle")); }
private Planner buildPlanner(QueryContext context) { final List<RelTraitDef> traitDefs = new ArrayList<RelTraitDef>(); traitDefs.add(ConventionTraitDef.INSTANCE); traitDefs.add(RelCollationTraitDef.INSTANCE); final ChainedSqlOperatorTable opTab = new ChainedSqlOperatorTable( ImmutableList.of(SqlStdOperatorTable.instance(), HiveSqlOperatorTable.instance(), catalogReader)); FrameworkConfig config = Frameworks.newConfigBuilder() // .parserConfig(SqlParser.configBuilder() .setQuotedCasing(Casing.UNCHANGED) .setUnquotedCasing(Casing.TO_UPPER) .setQuoting(Quoting.DOUBLE_QUOTE) .build()) // .defaultSchema(context.getDefaultSchema()) // .operatorTable(opTab) // .traitDefs(traitDefs) // .convertletTable(StandardConvertletTable.INSTANCE)// .programs(getPrograms()) // .typeSystem(RelDataTypeSystem.DEFAULT) // .build(); return Frameworks.getPlanner(config); }
@Test public void testTranslate3() { // TRANSLATE3 is not in the standard operator table checkWholeExpFails("translate('aabbcc', 'ab', '+-')", "No match found for function signature TRANSLATE3\\(<CHARACTER>, <CHARACTER>, <CHARACTER>\\)"); tester = tester.withOperatorTable( ChainedSqlOperatorTable.of(OracleSqlOperatorTable.instance(), SqlStdOperatorTable.instance())); checkExpType("translate('aabbcc', 'ab', '+-')", "VARCHAR(6) NOT NULL"); checkWholeExpFails("translate('abc', 'ab')", "Invalid number of arguments to function 'TRANSLATE3'. Was expecting 3 arguments"); checkWholeExpFails("translate('abc', 'ab', 123)", "(?s)Cannot apply 'TRANSLATE3' to arguments of type 'TRANSLATE3\\(<CHAR\\(3\\)>, <CHAR\\(2\\)>, <INTEGER>\\)'\\. .*"); checkWholeExpFails("translate('abc', 'ab', '+-', 'four')", "Invalid number of arguments to function 'TRANSLATE3'. Was expecting 3 arguments"); }
this.typeFactory = JavaTypeFactoryImpl.INSTANCE; this.catalogReader = new DremioCatalogReader(catalog, typeFactory); this.opTab = new ChainedSqlOperatorTable(ImmutableList.<SqlOperatorTable>of(operatorTable, this.catalogReader)); this.costFactory = (settings.useDefaultCosting()) ? null : new DremioCost.Factory(); this.validator = new SqlValidatorImpl(flattenCounter, opTab, this.catalogReader, typeFactory, DremioSqlConformance.INSTANCE);
protected SqlTester oracleTester(SqlConformance conformance) { if (conformance == null) { conformance = SqlConformanceEnum.DEFAULT; } return tester .withConformance(conformance) .withOperatorTable( ChainedSqlOperatorTable.of(OracleSqlOperatorTable.instance(), SqlStdOperatorTable.instance())) .withConnectionFactory( CalciteAssert.EMPTY_CONNECTION_FACTORY .with(new CalciteAssert .AddSchemaSpecPostProcessor(CalciteAssert.SchemaSpec.HR)) .with("fun", "oracle") .with("conformance", conformance)); }
public SqlConverter(QueryContext context) { this.settings = context.getPlannerSettings(); this.util = context; this.functions = context.getFunctionRegistry(); this.parserConfig = new DrillParserConfig(settings); this.sqlToRelConverterConfig = new SqlToRelConverterConfig(); this.isInnerQuery = false; this.typeFactory = new JavaTypeFactoryImpl(DRILL_TYPE_SYSTEM); this.defaultSchema = context.getNewDefaultSchema(); this.rootSchema = rootSchema(defaultSchema); this.temporarySchema = context.getConfig().getString(ExecConstants.DEFAULT_TEMPORARY_WORKSPACE); this.session = context.getSession(); this.drillConfig = context.getConfig(); this.catalog = new DrillCalciteCatalogReader( rootSchema, parserConfig.caseSensitive(), DynamicSchema.from(defaultSchema).path(null), typeFactory, drillConfig, session); this.opTab = new ChainedSqlOperatorTable(Arrays.asList(context.getDrillOperatorTable(), catalog)); this.costFactory = (settings.useDefaultCosting()) ? null : new DrillCostBase.DrillCostFactory(); this.validator = new DrillValidator(opTab, catalog, typeFactory, parserConfig.conformance()); validator.setIdentifierExpansion(true); cluster = null; }