TableResolution { public static Table resolveCalciteTable(SchemaPlus schemaPlus, List<String> tablePath) { Schema subSchema = schemaPlus; for (int i = 0; i < tablePath.size() - 1; i++) { subSchema = subSchema.getSubSchema(tablePath.get(i)); if (subSchema == null) { throw new IllegalStateException( String.format( "While resolving table path %s, no sub-schema found for component %s (\"%s\")", tablePath, i, tablePath.get(i))); } } return subSchema.getTable(Iterables.getLast(tablePath)); }  static Table resolveCalciteTable(SchemaPlus schemaPlus, List<String> tablePath); static void registerTables(SchemaPlus schemaPlus, List<List<String>> tables);  }
@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)); }
@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)); }
@Test public void testMissingFlat() { String tableName = "fake_table"; when(mockSchemaPlus.getTable(tableName)).thenReturn(null); Table table = TableResolution.resolveCalciteTable(mockSchemaPlus, ImmutableList.of(tableName)); assertThat(table, Matchers.nullValue()); }
@Test public void testResolveNested() { 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)); }
@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)); }
@Test public void testMissingSubschema() { String subSchema = "fake_schema"; String tableName = "fake_table"; when(mockSchemaPlus.getSubSchema(subSchema)).thenReturn(null); Assert.assertThrows( IllegalStateException.class, () -> { TableResolution.resolveCalciteTable( mockSchemaPlus, ImmutableList.of(subSchema, tableName)); }); }
@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()); }