use of org.apache.calcite.sql.util.ChainedSqlOperatorTable in project streamline by hortonworks.
the class StreamlineSqlImpl method buildFrameWorkConfig.
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();
}
}
use of org.apache.calcite.sql.util.ChainedSqlOperatorTable in project apex-malhar by apache.
the class SQLExecEnvironment method buildFrameWorkConfig.
/**
* Method method build a calcite framework configuration for calcite to parse SQL and generate relational tree
* out of it.
* @return FrameworkConfig
*/
private FrameworkConfig buildFrameWorkConfig() {
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).parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build()).operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).build();
}
use of org.apache.calcite.sql.util.ChainedSqlOperatorTable in project storm by apache.
the class StormSqlContext method buildFrameWorkConfig.
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();
}
}
use of org.apache.calcite.sql.util.ChainedSqlOperatorTable in project samza by apache.
the class QueryPlanner method getPlanner.
private Planner getPlanner() {
Planner planner = null;
try {
Connection connection = DriverManager.getConnection("jdbc:calcite:");
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
registerSourceSchemas(rootSchema);
List<SamzaSqlScalarFunctionImpl> samzaSqlFunctions = udfMetadata.stream().map(SamzaSqlScalarFunctionImpl::new).collect(Collectors.toList());
final List<RelTraitDef> traitDefs = new ArrayList<>();
traitDefs.add(ConventionTraitDef.INSTANCE);
traitDefs.add(RelCollationTraitDef.INSTANCE);
List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>();
sqlOperatorTables.add(new SamzaSqlOperatorTable());
sqlOperatorTables.add(new SamzaSqlUdfOperatorTable(samzaSqlFunctions));
// TODO: Introduce a pluggable rule factory.
List<RelOptRule> rules = ImmutableList.of(FilterProjectTransposeRule.INSTANCE, ProjectMergeRule.INSTANCE, new SamzaSqlFilterRemoteJoinRule.SamzaSqlFilterIntoRemoteJoinRule(true, RelFactories.LOGICAL_BUILDER, systemStreamConfigBySource));
// Using lenient so that !=,%,- are allowed.
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder().parserConfig(SqlParser.configBuilder().setLex(Lex.JAVA).setConformance(SqlConformanceEnum.LENIENT).setCaseSensitive(// Make Udfs case insensitive
false).build()).defaultSchema(rootSchema).operatorTable(new ChainedSqlOperatorTable(sqlOperatorTables)).sqlToRelConverterConfig(SqlToRelConverter.Config.DEFAULT).traitDefs(traitDefs).programs(Programs.hep(rules, true, DefaultRelMetadataProvider.INSTANCE)).build();
planner = Frameworks.getPlanner(frameworkConfig);
return planner;
} catch (Exception e) {
String errorMsg = "Failed to create planner.";
LOG.error(errorMsg, e);
if (planner != null) {
planner.close();
}
throw new SamzaException(errorMsg, e);
}
}
Aggregations