Search in sources :

Example 61 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project druid by druid-io.

the class SystemSchemaTest method testGetTableMap.

@Test
public void testGetTableMap() {
    Assert.assertEquals(ImmutableSet.of("segments", "servers", "server_segments", "tasks", "supervisors"), schema.getTableNames());
    final Map<String, Table> tableMap = schema.getTableMap();
    Assert.assertEquals(ImmutableSet.of("segments", "servers", "server_segments", "tasks", "supervisors"), tableMap.keySet());
    final SystemSchema.SegmentsTable segmentsTable = (SystemSchema.SegmentsTable) schema.getTableMap().get("segments");
    final RelDataType rowType = segmentsTable.getRowType(new JavaTypeFactoryImpl());
    final List<RelDataTypeField> fields = rowType.getFieldList();
    Assert.assertEquals(17, fields.size());
    final SystemSchema.TasksTable tasksTable = (SystemSchema.TasksTable) schema.getTableMap().get("tasks");
    final RelDataType sysRowType = tasksTable.getRowType(new JavaTypeFactoryImpl());
    final List<RelDataTypeField> sysFields = sysRowType.getFieldList();
    Assert.assertEquals(14, sysFields.size());
    Assert.assertEquals("task_id", sysFields.get(0).getName());
    Assert.assertEquals(SqlTypeName.VARCHAR, sysFields.get(0).getType().getSqlTypeName());
    final SystemSchema.ServersTable serversTable = (SystemSchema.ServersTable) schema.getTableMap().get("servers");
    final RelDataType serverRowType = serversTable.getRowType(new JavaTypeFactoryImpl());
    final List<RelDataTypeField> serverFields = serverRowType.getFieldList();
    Assert.assertEquals(9, serverFields.size());
    Assert.assertEquals("server", serverFields.get(0).getName());
    Assert.assertEquals(SqlTypeName.VARCHAR, serverFields.get(0).getType().getSqlTypeName());
}
Also used : SegmentsTable(org.apache.druid.sql.calcite.schema.SystemSchema.SegmentsTable) Table(org.apache.calcite.schema.Table) SegmentsTable(org.apache.druid.sql.calcite.schema.SystemSchema.SegmentsTable) RelDataType(org.apache.calcite.rel.type.RelDataType) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SegmentsTable(org.apache.druid.sql.calcite.schema.SystemSchema.SegmentsTable) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) Test(org.junit.Test)

Example 62 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project storm by apache.

the class TridentModifyRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final TableModify tableModify = (TableModify) rel;
    final RelNode input = tableModify.getInput();
    final RelOptCluster cluster = tableModify.getCluster();
    final RelTraitSet traitSet = tableModify.getTraitSet().replace(TridentLogicalConvention.INSTANCE);
    final RelOptTable relOptTable = tableModify.getTable();
    final Prepare.CatalogReader catalogReader = tableModify.getCatalogReader();
    final RelNode convertedInput = convert(input, input.getTraitSet().replace(TridentLogicalConvention.INSTANCE));
    final TableModify.Operation operation = tableModify.getOperation();
    final List<String> updateColumnList = tableModify.getUpdateColumnList();
    final List<RexNode> sourceExpressionList = tableModify.getSourceExpressionList();
    final boolean flattened = tableModify.isFlattened();
    final Table table = tableModify.getTable().unwrap(Table.class);
    switch(table.getJdbcTableType()) {
        case STREAM:
            if (operation != TableModify.Operation.INSERT) {
                throw new UnsupportedOperationException(String.format("Streams doesn't support %s modify operation", operation));
            }
            return new TridentStreamInsertRel(cluster, traitSet, relOptTable, catalogReader, convertedInput, operation, updateColumnList, sourceExpressionList, flattened);
        default:
            throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType()));
    }
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) Table(org.apache.calcite.schema.Table) RelOptTable(org.apache.calcite.plan.RelOptTable) RelTraitSet(org.apache.calcite.plan.RelTraitSet) RelNode(org.apache.calcite.rel.RelNode) TridentStreamInsertRel(org.apache.storm.sql.planner.trident.rel.TridentStreamInsertRel) Prepare(org.apache.calcite.prepare.Prepare) RelOptTable(org.apache.calcite.plan.RelOptTable) LogicalTableModify(org.apache.calcite.rel.logical.LogicalTableModify) TableModify(org.apache.calcite.rel.core.TableModify) RexNode(org.apache.calcite.rex.RexNode)

Example 63 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project storm by apache.

the class TridentScanRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final TableScan scan = (TableScan) rel;
    int parallelismHint = DEFAULT_PARALLELISM_HINT;
    final ParallelStreamableTable parallelTable = scan.getTable().unwrap(ParallelStreamableTable.class);
    if (parallelTable != null && parallelTable.parallelismHint() != null) {
        parallelismHint = parallelTable.parallelismHint();
    }
    final Table table = scan.getTable().unwrap(Table.class);
    switch(table.getJdbcTableType()) {
        case STREAM:
            return new TridentStreamScanRel(scan.getCluster(), scan.getTraitSet().replace(TridentLogicalConvention.INSTANCE), scan.getTable(), parallelismHint);
        default:
            throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType()));
    }
}
Also used : ParallelStreamableTable(org.apache.storm.sql.calcite.ParallelStreamableTable) TableScan(org.apache.calcite.rel.core.TableScan) EnumerableTableScan(org.apache.calcite.adapter.enumerable.EnumerableTableScan) ParallelStreamableTable(org.apache.storm.sql.calcite.ParallelStreamableTable) Table(org.apache.calcite.schema.Table) TridentStreamScanRel(org.apache.storm.sql.planner.trident.rel.TridentStreamScanRel)

Example 64 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project storm by apache.

the class TestCompilerUtils method sqlOverNestedTable.

public static CalciteState sqlOverNestedTable(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("MAPFIELD", typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true)), true)).field("NESTEDMAPFIELD", typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createMapType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.VARCHAR), true), typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true)), true)), true)).field("ARRAYFIELD", typeFactory.createTypeWithNullability(typeFactory.createArrayType(typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.INTEGER), true), -1L), true)).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);
}
Also used : CompilerUtil(org.apache.storm.sql.compiler.CompilerUtil) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) Table(org.apache.calcite.schema.Table) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) StreamableTable(org.apache.calcite.schema.StreamableTable) SchemaPlus(org.apache.calcite.schema.SchemaPlus) ArrayList(java.util.ArrayList) StreamableTable(org.apache.calcite.schema.StreamableTable) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) CalciteCatalogReader(org.apache.calcite.prepare.CalciteCatalogReader) RelNode(org.apache.calcite.rel.RelNode) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) Planner(org.apache.calcite.tools.Planner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) SqlNode(org.apache.calcite.sql.SqlNode)

Example 65 with Table

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table in project druid by druid-io.

the class DruidSchemaTest method testGetTableMap.

@Test
public void testGetTableMap() {
    Assert.assertEquals(ImmutableSet.of("foo", "foo2"), schema.getTableNames());
    final Map<String, Table> tableMap = schema.getTableMap();
    Assert.assertEquals(ImmutableSet.of("foo", "foo2"), tableMap.keySet());
    final DruidTable fooTable = (DruidTable) tableMap.get("foo");
    final RelDataType rowType = fooTable.getRowType(new JavaTypeFactoryImpl());
    final List<RelDataTypeField> fields = rowType.getFieldList();
    Assert.assertEquals(6, fields.size());
    Assert.assertEquals("__time", fields.get(0).getName());
    Assert.assertEquals(SqlTypeName.TIMESTAMP, fields.get(0).getType().getSqlTypeName());
    Assert.assertEquals("cnt", fields.get(1).getName());
    Assert.assertEquals(SqlTypeName.BIGINT, fields.get(1).getType().getSqlTypeName());
    Assert.assertEquals("dim1", fields.get(2).getName());
    Assert.assertEquals(SqlTypeName.VARCHAR, fields.get(2).getType().getSqlTypeName());
    Assert.assertEquals("m1", fields.get(3).getName());
    Assert.assertEquals(SqlTypeName.BIGINT, fields.get(3).getType().getSqlTypeName());
    Assert.assertEquals("unique_dim1", fields.get(4).getName());
    Assert.assertEquals(SqlTypeName.OTHER, fields.get(4).getType().getSqlTypeName());
    Assert.assertEquals("dim2", fields.get(5).getName());
    Assert.assertEquals(SqlTypeName.VARCHAR, fields.get(5).getType().getSqlTypeName());
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) DruidTable(io.druid.sql.calcite.table.DruidTable) Table(org.apache.calcite.schema.Table) JavaTypeFactoryImpl(org.apache.calcite.jdbc.JavaTypeFactoryImpl) DruidTable(io.druid.sql.calcite.table.DruidTable) RelDataType(org.apache.calcite.rel.type.RelDataType) Test(org.junit.Test)

Aggregations

Table (org.apache.calcite.schema.Table)104 Test (org.junit.Test)43 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)38 RelOptTable (org.apache.calcite.plan.RelOptTable)33 RelDataType (org.apache.calcite.rel.type.RelDataType)22 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)22 SchemaPlus (org.apache.calcite.schema.SchemaPlus)20 ArrayList (java.util.ArrayList)19 List (java.util.List)19 ProjectableFilterableTable (org.apache.calcite.schema.ProjectableFilterableTable)17 ScannableTable (org.apache.calcite.schema.ScannableTable)17 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)16 FilterableTable (org.apache.calcite.schema.FilterableTable)15 AbstractTable (org.apache.calcite.schema.impl.AbstractTable)15 ResultSet (java.sql.ResultSet)14 Schema (org.apache.beam.sdk.schemas.Schema)14 Row (org.apache.beam.sdk.values.Row)14 StreamableTable (org.apache.calcite.schema.StreamableTable)14 CalciteConnection (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteConnection)13 Map (java.util.Map)12