Search in sources :

Example 61 with Table

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

the class TableResolutionTest method testResolveNestedWithDots.

/**
 * Unit test for resolving a table with dots in the subschema names and the table name.
 */
@Test
public void testResolveNestedWithDots() {
    String subSchema = "fake.schema";
    String tableName = "fake.table";
    when(mockSchemaPlus.getSubSchema(subSchema)).thenReturn(innerSchemaPlus);
    when(innerSchemaPlus.getTable(tableName)).thenReturn(mockTable);
    Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(subSchema, tableName));
    assertThat(table, Matchers.is(mockTable));
}
Also used : Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) Test(org.junit.Test)

Example 62 with Table

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

the class TableResolutionTest method testResolveFlat.

/**
 * Unit test for resolving a table with no hierarchy.
 */
@Test
public void testResolveFlat() {
    String tableName = "fake_table";
    when(mockSchemaPlus.getTable(tableName)).thenReturn(mockTable);
    Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(tableName));
    assertThat(table, Matchers.is(mockTable));
}
Also used : Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) Test(org.junit.Test)

Example 63 with Table

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

the class TableResolutionTest method testMissingTableInSubschema.

/**
 * Unit test for resolving a table with some hierarchy and the table is missing.
 */
@Test
public void testMissingTableInSubschema() {
    String subSchema = "fake_schema";
    String tableName = "fake_table";
    when(mockSchemaPlus.getSubSchema(subSchema)).thenReturn(innerSchemaPlus);
    when(innerSchemaPlus.getTable(tableName)).thenReturn(null);
    Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(subSchema, tableName));
    assertThat(table, Matchers.nullValue());
}
Also used : Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) Test(org.junit.Test)

Example 64 with Table

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

the class TableResolutionTest method testResolveWithDots.

/**
 * Unit test for resolving a table with no hierarchy but dots in its actual name.
 */
@Test
public void testResolveWithDots() {
    String tableName = "fake.table";
    when(mockSchemaPlus.getTable(tableName)).thenReturn(mockTable);
    Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(tableName));
    assertThat(table, Matchers.is(mockTable));
}
Also used : Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) Test(org.junit.Test)

Example 65 with Table

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

the class TableScanConverter method convert.

@Override
public RelNode convert(ResolvedTableScan zetaNode, List<RelNode> inputs) {
    List<String> tablePath = getTablePath(zetaNode.getTable());
    SchemaPlus defaultSchemaPlus = getConfig().getDefaultSchema();
    if (defaultSchemaPlus == null) {
        throw new AssertionError("Default schema is null.");
    }
    // TODO: reject incorrect top-level schema
    Table calciteTable = TableResolution.resolveCalciteTable(defaultSchemaPlus, tablePath);
    // we already resolved the table before passing the query to Analyzer, so it should be there
    checkNotNull(calciteTable, "Unable to resolve the table path %s in schema %s", tablePath, defaultSchemaPlus.getName());
    String defaultSchemaName = defaultSchemaPlus.getName();
    final CalciteCatalogReader catalogReader = new CalciteCatalogReader(CalciteSchema.from(defaultSchemaPlus), ImmutableList.of(defaultSchemaName), getCluster().getTypeFactory(), new CalciteConnectionConfigImpl(new Properties()));
    RelOptTableImpl relOptTable = RelOptTableImpl.create(catalogReader, calciteTable.getRowType(getCluster().getTypeFactory()), calciteTable, ImmutableList.<String>builder().add(defaultSchemaName).addAll(tablePath).build());
    if (calciteTable instanceof TranslatableTable) {
        return ((TranslatableTable) calciteTable).toRel(createToRelContext(), relOptTable);
    } else {
        throw new UnsupportedOperationException("Does not support non TranslatableTable type table!");
    }
}
Also used : CalciteConnectionConfigImpl(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.config.CalciteConnectionConfigImpl) RelOptTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.plan.RelOptTable) Table(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.Table) TranslatableTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable) CalciteCatalogReader(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.CalciteCatalogReader) SchemaPlus(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus) RelOptTableImpl(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.prepare.RelOptTableImpl) TranslatableTable(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.TranslatableTable) Properties(java.util.Properties)

Aggregations

Table (org.apache.calcite.schema.Table)104 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)38 RelOptTable (org.apache.calcite.plan.RelOptTable)33 Test (org.junit.Test)27 RelDataType (org.apache.calcite.rel.type.RelDataType)22 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)22 SchemaPlus (org.apache.calcite.schema.SchemaPlus)20 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 StreamableTable (org.apache.calcite.schema.StreamableTable)14 ArrayList (java.util.ArrayList)13 ModifiableViewTable (org.apache.calcite.schema.impl.ModifiableViewTable)13 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)12 RelNode (org.apache.calcite.rel.RelNode)12 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)10 BitString (org.apache.calcite.util.BitString)10 ImmutableMap (com.google.common.collect.ImmutableMap)9