@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); List<SchemaTableName> tables; if (prefix.getTableName() != null) { tables = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName())); } else { tables = listTables(session, prefix.getSchemaName()); } for (SchemaTableName tableName : tables) { try { JdbcTableHandle tableHandle = jdbcClient.getTableHandle(tableName); if (tableHandle == null) { continue; } columns.put(tableName, getTableMetadata(session, tableHandle).getColumns()); } catch (TableNotFoundException e) { // table disappeared during listing operation } } return columns.build(); }
@Test public void testListTables() { // all schemas assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.empty())), ImmutableSet.of( new SchemaTableName("example", "numbers"), new SchemaTableName("example", "view_source"), new SchemaTableName("example", "view"), new SchemaTableName("tpch", "orders"), new SchemaTableName("tpch", "lineitem"), new SchemaTableName("exa_ple", "table_with_float_col"), new SchemaTableName("exa_ple", "num_ers"))); // specific schema assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.of("example"))), ImmutableSet.of( new SchemaTableName("example", "numbers"), new SchemaTableName("example", "view_source"), new SchemaTableName("example", "view"))); assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.of("tpch"))), ImmutableSet.of( new SchemaTableName("tpch", "orders"), new SchemaTableName("tpch", "lineitem"))); assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.of("exa_ple"))), ImmutableSet.of( new SchemaTableName("exa_ple", "num_ers"), new SchemaTableName("exa_ple", "table_with_float_col"))); // unknown schema assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.of("unknown"))), ImmutableSet.of()); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); for (SchemaTableName tableName : listTables(session, prefix.getSchemaName())) { try { JdbcTableHandle tableHandle = jdbcClient.getTableHandle(tableName); if (tableHandle == null) { continue; } columns.put(tableName, getTableMetadata(session, tableHandle).getColumns()); } catch (TableNotFoundException e) { // table disappeared during listing operation } } return columns.build(); }
@Test public void testListTables() { // all schemas assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.empty())), ImmutableSet.of( new SchemaTableName("example", "numbers"), new SchemaTableName("example", "view_source"), new SchemaTableName("example", "view"), new SchemaTableName("tpch", "orders"), new SchemaTableName("tpch", "lineitem"), new SchemaTableName("exa_ple", "table_with_float_col"), new SchemaTableName("exa_ple", "num_ers"))); // specific schema assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.of("example"))), ImmutableSet.of( new SchemaTableName("example", "numbers"), new SchemaTableName("example", "view_source"), new SchemaTableName("example", "view"))); assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.of("tpch"))), ImmutableSet.of( new SchemaTableName("tpch", "orders"), new SchemaTableName("tpch", "lineitem"))); assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.of("exa_ple"))), ImmutableSet.of( new SchemaTableName("exa_ple", "num_ers"), new SchemaTableName("exa_ple", "table_with_float_col"))); // unknown schema assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, Optional.of("unknown"))), ImmutableSet.of()); }