private List<FieldInfo> updateSchema(SqlCreateTable n) { CompilerUtil.TableBuilderInfo builder = new CompilerUtil.TableBuilderInfo(typeFactory); List<FieldInfo> fields = new ArrayList<>(); for (ColumnDefinition col : n.fieldList()) { builder.field(col.name(), col.type(), col.constraint()); RelDataType dataType = col.type().deriveType(typeFactory); Class<?> javaType = (Class<?>)typeFactory.getJavaClass(dataType); ColumnConstraint constraint = col.constraint(); boolean isPrimary = constraint != null && constraint instanceof ColumnConstraint.PrimaryKey; fields.add(new FieldInfo(col.name(), javaType, isPrimary)); } if (n.parallelism() != null) { builder.parallelismHint(n.parallelism()); } Table table = builder.build(); schema.add(n.tableName(), table); return fields; }
public static CalciteState sqlOverDummyTable(String sql) throws RelConversionException, ValidationException, SqlParseException { SchemaPlus schema = Frameworks.createRootSchema(true); JavaTypeFactory typeFactory = new JavaTypeFactoryImpl (RelDataTypeSystem.DEFAULT); StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory) .field("ID", SqlTypeName.INTEGER) .field("NAME", typeFactory.createType(String.class)) .field("ADDR", typeFactory.createType(String.class)) .build(); Table table = streamableTable.stream(); schema.add("FOO", table); schema.add("BAR", table); schema.add("MYPLUS", ScalarFunctionImpl.create(MyPlus.class, "eval")); List<SqlOperatorTable> sqlOperatorTables = new ArrayList<>(); sqlOperatorTables.add(SqlStdOperatorTable.instance()); sqlOperatorTables.add(new CalciteCatalogReader(CalciteSchema.from(schema), false, Collections.<String>emptyList(), typeFactory)); SqlOperatorTable chainedSqlOperatorTable = new ChainedSqlOperatorTable(sqlOperatorTables); FrameworkConfig config = Frameworks.newConfigBuilder().defaultSchema( schema).operatorTable(chainedSqlOperatorTable).build(); Planner planner = Frameworks.getPlanner(config); SqlNode parse = planner.parse(sql); SqlNode validate = planner.validate(parse); RelNode tree = planner.convert(validate); System.out.println(RelOptUtil.toString(tree, SqlExplainLevel.ALL_ATTRIBUTES)); return new CalciteState(schema, tree); }
(RelDataTypeSystem.DEFAULT); StreamableTable streamableTable = new CompilerUtil.TableBuilderInfo(typeFactory) .field("ID", SqlTypeName.INTEGER) .field("MAPFIELD",