/** * Creates a planner. * * @param config Planner configuration * @return Planner */ public static Planner getPlanner(FrameworkConfig config) { return new PlannerImpl(config); }
@Override void from(PlannerImpl planner) { planner.close(); } },
public void reset() { ensure(State.STATE_0_CLOSED); open = true; state = State.STATE_1_RESET; }
@Override public RelRoot expandView(RelDataType rowType, String queryString, List<String> schemaPath, List<String> viewPath) { if (planner == null) { ready(); final SqlConformance conformance = conformance(); final CalciteCatalogReader catalogReader = createCatalogReader().withSchemaPath(schemaPath); final SqlValidator validator = new CalciteSqlValidator(operatorTable, catalogReader, typeFactory, validator.setIdentifierExpansion(true); final RexBuilder rexBuilder = createRexBuilder(); final RelOptCluster cluster = RelOptCluster.create(planner, rexBuilder); final SqlToRelConverter.Config config = SqlToRelConverter
public SqlNode validate(SqlNode sqlNode) throws ValidationException { ensure(State.STATE_3_PARSED); final SqlConformance conformance = conformance(); final CalciteCatalogReader catalogReader = createCatalogReader(); this.validator = new CalciteSqlValidator(operatorTable, catalogReader, typeFactory, conformance); this.validator.setIdentifierExpansion(true); try { validatedSqlNode = validator.validate(sqlNode); } catch (RuntimeException e) { throw new ValidationException(e); } state = State.STATE_4_VALIDATED; return validatedSqlNode; }
public RelRoot rel(SqlNode sql) throws RelConversionException { ensure(State.STATE_4_VALIDATED); assert validatedSqlNode != null; final RexBuilder rexBuilder = createRexBuilder(); final RelOptCluster cluster = RelOptCluster.create(planner, rexBuilder); final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder() .withConfig(sqlToRelConverterConfig) .withTrimUnusedFields(false) .withConvertTableAccess(false) .build(); final SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(this, validator, createCatalogReader(), cluster, convertletTable, config); root = sqlToRelConverter.convertQuery(validatedSqlNode, false, true); root = root.withRel(sqlToRelConverter.flattenTypes(root.rel, true)); final RelBuilder relBuilder = config.getRelBuilderFactory().create(cluster, null); root = root.withRel( RelDecorrelator.decorrelateQuery(root.rel, relBuilder)); state = State.STATE_5_CONVERTED; return root; }
public SqlNode parse(final String sql) throws SqlParseException { switch (state) { case STATE_0_CLOSED: case STATE_1_RESET: ready(); } ensure(State.STATE_2_READY); SqlParser parser = SqlParser.create(sql, parserConfig); SqlNode sqlNode = parser.parseStmt(); state = State.STATE_3_PARSED; return sqlNode; }
private void ready() { switch (state) { case STATE_0_CLOSED: reset(); } ensure(State.STATE_1_RESET); Frameworks.withPlanner( (cluster, relOptSchema, rootSchema) -> { Util.discard(rootSchema); // use our own defaultSchema typeFactory = (JavaTypeFactory) cluster.getTypeFactory(); planner = cluster.getPlanner(); planner.setExecutor(executor); return null; }, config); state = State.STATE_2_READY; // If user specify own traitDef, instead of default default trait, // first, clear the default trait def registered with planner // then, register the trait def specified in traitDefs. if (this.traitDefs != null) { planner.clearRelTraitDefs(); for (RelTraitDef def : this.traitDefs) { planner.addRelTraitDef(def); } } }
@Override void from(PlannerImpl planner) { planner.ensure(STATE_0_CLOSED); planner.reset(); } },
@SuppressWarnings("deprecation") public final RelNode convert(SqlNode sql) throws RelConversionException { return rel(sql).rel; }
private CalciteCatalogReader createCatalogReader() { final SchemaPlus rootSchema = rootSchema(defaultSchema); final Context context = config.getContext(); final CalciteConnectionConfig connectionConfig; if (context != null) { connectionConfig = context.unwrap(CalciteConnectionConfig.class); } else { Properties properties = new Properties(); properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive())); connectionConfig = new CalciteConnectionConfigImpl(properties); } return new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(defaultSchema).path(null), typeFactory, connectionConfig); }
public SqlNode validate(SqlNode sqlNode) throws ValidationException { ensure(State.STATE_3_PARSED); final SqlConformance conformance = conformance(); final CalciteCatalogReader catalogReader = createCatalogReader(); this.validator = new CalciteSqlValidator(operatorTable, catalogReader, typeFactory, conformance); this.validator.setIdentifierExpansion(true); try { validatedSqlNode = validator.validate(sqlNode); } catch (RuntimeException e) { throw new ValidationException(e); } state = State.STATE_4_VALIDATED; return validatedSqlNode; }
public RelRoot rel(SqlNode sql) throws RelConversionException { ensure(State.STATE_4_VALIDATED); assert validatedSqlNode != null; final RexBuilder rexBuilder = createRexBuilder(); final RelOptCluster cluster = RelOptCluster.create(planner, rexBuilder); final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder() .withConfig(sqlToRelConverterConfig) .withTrimUnusedFields(false) .withConvertTableAccess(false) .build(); final SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(new ViewExpanderImpl(), validator, createCatalogReader(), cluster, convertletTable, config); root = sqlToRelConverter.convertQuery(validatedSqlNode, false, true); root = root.withRel(sqlToRelConverter.flattenTypes(root.rel, true)); final RelBuilder relBuilder = config.getRelBuilderFactory().create(cluster, null); root = root.withRel( RelDecorrelator.decorrelateQuery(root.rel, relBuilder)); state = State.STATE_5_CONVERTED; return root; }
public SqlNode parse(final Reader reader) throws SqlParseException { switch (state) { case STATE_0_CLOSED: case STATE_1_RESET: ready(); } ensure(State.STATE_2_READY); SqlParser parser = SqlParser.create(reader, parserConfig); SqlNode sqlNode = parser.parseStmt(); state = State.STATE_3_PARSED; return sqlNode; }
private void ready() { switch (state) { case STATE_0_CLOSED: reset(); } ensure(State.STATE_1_RESET); Frameworks.withPlanner( (cluster, relOptSchema, rootSchema) -> { Util.discard(rootSchema); // use our own defaultSchema typeFactory = (JavaTypeFactory) cluster.getTypeFactory(); planner = cluster.getPlanner(); planner.setExecutor(executor); return null; }, config); state = State.STATE_2_READY; // If user specify own traitDef, instead of default default trait, // first, clear the default trait def registered with planner // then, register the trait def specified in traitDefs. if (this.traitDefs != null) { planner.clearRelTraitDefs(); for (RelTraitDef def : this.traitDefs) { planner.addRelTraitDef(def); } } }
@Override void from(PlannerImpl planner) { planner.ensure(STATE_0_CLOSED); planner.reset(); } },
@SuppressWarnings("deprecation") public final RelNode convert(SqlNode sql) throws RelConversionException { return rel(sql).rel; }
private CalciteCatalogReader createCatalogReader() { final SchemaPlus rootSchema = rootSchema(defaultSchema); final Context context = config.getContext(); final CalciteConnectionConfig connectionConfig; if (context != null) { connectionConfig = context.unwrap(CalciteConnectionConfig.class); } else { Properties properties = new Properties(); properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(), String.valueOf(parserConfig.caseSensitive())); connectionConfig = new CalciteConnectionConfigImpl(properties); } return new CalciteCatalogReader( CalciteSchema.from(rootSchema), CalciteSchema.from(defaultSchema).path(null), typeFactory, connectionConfig); }
/** * Creates a planner. * * @param config Planner configuration * @return Planner */ public static Planner getPlanner(FrameworkConfig config) { return new PlannerImpl(config); }
public void reset() { ensure(State.STATE_0_CLOSED); open = true; state = State.STATE_1_RESET; }