@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); List<SchemaTableName> tableNames = prefix.getSchemaName() == null ? listTables(session, null) : ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName())); for (SchemaTableName tableName : tableNames) { ConnectorTableMetadata tableMetadata = getTableMetadata(tableName); // table can disappear during listing operation if (tableMetadata != null) { columns.put(tableName, tableMetadata.getColumns()); } } return columns.build(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); KuduClient kuduClient = kuduClientManager.getClient(); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); for (SchemaTableName tableName : listTables(session, prefix)) { KuduTableHandle tableHandle = kuduTables.getTables(kuduClient).get(tableName); if (tableHandle != null) { columns.put(tableName, kuduTables.getColumns(kuduClient, tableHandle)); } } kuduClientManager.close(kuduClient); return columns.build(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); List<SchemaTableName> tableNames; if (prefix.getSchemaName() == null) { tableNames = listTables(session, null); } else { tableNames = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName())); } for (SchemaTableName tableName : tableNames) { ConnectorTableMetadata tableMetadata = getTableMetadata(tableName); // table can disappear during listing operation if (tableMetadata != null) { columns.put(tableName, tableMetadata.getColumns()); } } return columns.build(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); if (prefix.getSchemaName() != null && !prefix.getSchemaName().equals(SCHEMA_NAME)) { return ImmutableMap.of(); } ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); List<SchemaTableName> tableNames; if (prefix.getTableName() == null) { tableNames = listTables(session, prefix.getSchemaName()); } else { tableNames = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName())); } for (SchemaTableName tableName : tableNames) { JmxTableHandle tableHandle = getTableHandle(session, tableName); columns.put(tableName, tableHandle.getTableMetadata().getColumns()); } return columns.build(); }
@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(); }
@Override public Map<QualifiedObjectName, ViewDefinition> getViews(Session session, QualifiedTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); SchemaTablePrefix tablePrefix = prefix.asSchemaTablePrefix(); Map<QualifiedObjectName, ViewDefinition> views = new LinkedHashMap<>(); for (ConnectorEntry connectorEntry : allConnectorsFor(prefix.getCatalogName())) { ConnectorMetadata metadata = connectorEntry.getMetadata(session); ConnectorSession connectorSession = session.toConnectorSession(connectorEntry.getCatalog()); for (Entry<SchemaTableName, ConnectorViewDefinition> entry : metadata.getViews(connectorSession, tablePrefix).entrySet()) { QualifiedObjectName viewName = new QualifiedObjectName( prefix.getCatalogName(), entry.getKey().getSchemaName(), entry.getKey().getTableName()); views.put(viewName, deserializeView(entry.getValue().getViewData())); } } return ImmutableMap.copyOf(views); }
@Override public Map<SchemaTableName, ConnectorViewDefinition> getViews(ConnectorSession session, SchemaTablePrefix prefix) { ImmutableMap.Builder<SchemaTableName, ConnectorViewDefinition> views = ImmutableMap.builder(); List<SchemaTableName> tableNames; if (prefix.getTableName() != null) { tableNames = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName())); } else { tableNames = listViews(session, prefix.getSchemaName()); } for (SchemaTableName schemaTableName : tableNames) { Optional<Table> table = metastore.getTable(schemaTableName.getSchemaName(), schemaTableName.getTableName()); if (table.isPresent() && HiveUtil.isPrestoView(table.get())) { views.put(schemaTableName, new ConnectorViewDefinition( schemaTableName, Optional.ofNullable(table.get().getOwner()), decodeViewData(table.get().getViewOriginalText()))); } } return views.build(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { checkNotNull(prefix, "prefix is null"); log.debug("Called listTableColumns on %s.%s", prefix.getSchemaName(), prefix.getTableName()); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); // NOTE: prefix.getTableName or prefix.getSchemaName can be null List<SchemaTableName> tableNames; if (prefix.getSchemaName() != null && prefix.getTableName() != null) { tableNames = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName())); } else { tableNames = listTables(session, null); } for (SchemaTableName tableName : tableNames) { ConnectorTableMetadata tableMetadata = getTableMetadata(tableName); if (tableMetadata != null) { columns.put(tableName, tableMetadata.getColumns()); } } return columns.build(); }
public List<SchemaTableName> listTables(SchemaTablePrefix prefix) { log.info("List all tables with prefix " + prefix.toString()); List<SchemaTableName> tables = new ArrayList<>(); String dbPrefix = prefix.getSchemaName(); log.debug("listTables dbPrefix: " + dbPrefix); String tblPrefix = prefix.getTableName(); log.debug("listTables tblPrefix: " + tblPrefix); // if dbPrefix not mean to match all String tblName; String dbName; if (dbPrefix != null) { if (tblPrefix != null) { tblName = tblPrefix; dbName = dbPrefix; } else { MetaProto.StringListType stringListType = metaClient.listTables(dbPrefix); log.info("record size: " + stringListType.getStrCount()); if (stringListType.getStrCount() == 0) { return tables; } for (int i = 0; i < stringListType.getStrCount(); i++) { tblName = stringListType.getStr(0); dbName = dbPrefix; log.debug("listTables tableName: " + formName(dbName, tblName)); tables.add(new SchemaTableName(dbName, tblName)); } } } return tables; }
/** * List table names, possibly filtered by schema. An empty list is returned if none match. * * @param session session * @param schemaNameOrNull schema name */ @Override public List<SchemaTableName> listTables(ConnectorSession session, String schemaNameOrNull) { if (schemaNameOrNull == null) { return new ArrayList<>(); } return metaDataQuery.listTables(new SchemaTablePrefix(schemaNameOrNull)); }
/** * Gets the metadata for all columns that match the specified table prefix. * * @param session session * @param prefix prefix */ @Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { Map<SchemaTableName, List<ColumnMetadata>> tableColumns = new HashMap<>(); List<SchemaTableName> tableNames = metaDataQuery.listTables(prefix); for (SchemaTableName table : tableNames) { List<ColumnMetadata> columnMetadatas = metaDataQuery.getTableColMetadata(connectorId, table.getSchemaName(), table.getTableName()).orElse(new ArrayList<>()); tableColumns.putIfAbsent(table, columnMetadatas); } return tableColumns; }
private List<SchemaTableName> listTables(ConnectorSession session, SchemaTablePrefix prefix) { if (prefix.getSchemaName() == null) { return listTables(session, prefix.getSchemaName()); } return ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName())); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); for (SchemaTableName tableName : listTables(session, prefix)) { ConnectorTableMetadata tableMetadata = getTableMetadata(tableName); // table can disappear during listing operation if (tableMetadata != null) { columns.put(tableName, tableMetadata.getColumns()); } } return columns.build(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableListMultimap.Builder<SchemaTableName, ColumnMetadata> columns = ImmutableListMultimap.builder(); for (TableColumn tableColumn : dao.listTableColumns(prefix.getSchemaName(), prefix.getTableName())) { if (tableColumn.getColumnName().equals(SAMPLE_WEIGHT_COLUMN_NAME)) { continue; } ColumnMetadata columnMetadata = new ColumnMetadata(tableColumn.getColumnName(), tableColumn.getDataType(), false); columns.put(tableColumn.getTable(), columnMetadata); } return Multimaps.asMap(columns.build()); }
@Override public Map<SchemaTableName, ConnectorViewDefinition> getViews(ConnectorSession session, SchemaTablePrefix prefix) { ImmutableMap.Builder<SchemaTableName, ConnectorViewDefinition> map = ImmutableMap.builder(); for (ViewResult view : dao.getViews(prefix.getSchemaName(), prefix.getTableName())) { map.put(view.getName(), new ConnectorViewDefinition(view.getName(), Optional.empty(), view.getData())); } return map.build(); }
@Test public void testListTableColumns() { metadata.createTable(SESSION, getOrdersTable()); Map<SchemaTableName, List<ColumnMetadata>> columns = metadata.listTableColumns(SESSION, new SchemaTablePrefix()); assertEquals(columns, ImmutableMap.of(DEFAULT_TEST_ORDERS, getOrdersTable().getColumns())); }
@Test public void testListTableColumnsFiltering() { metadata.createTable(SESSION, getOrdersTable()); Map<SchemaTableName, List<ColumnMetadata>> filterCatalog = metadata.listTableColumns(SESSION, new SchemaTablePrefix()); Map<SchemaTableName, List<ColumnMetadata>> filterSchema = metadata.listTableColumns(SESSION, new SchemaTablePrefix("test")); Map<SchemaTableName, List<ColumnMetadata>> filterTable = metadata.listTableColumns(SESSION, new SchemaTablePrefix("test", "orders")); assertEquals(filterCatalog, filterSchema); assertEquals(filterCatalog, filterTable); }
@Test public void testViews() { SchemaTableName test1 = new SchemaTableName("test", "test_view1"); SchemaTableName test2 = new SchemaTableName("test", "test_view2"); // create views metadata.createView(SESSION, test1, "test1", false); metadata.createView(SESSION, test2, "test2", false); // verify listing List<SchemaTableName> list = metadata.listViews(SESSION, "test"); assertEqualsIgnoreOrder(list, ImmutableList.of(test1, test2)); // verify getting data Map<SchemaTableName, ConnectorViewDefinition> views = metadata.getViews(SESSION, new SchemaTablePrefix("test")); assertEquals(views.keySet(), ImmutableSet.of(test1, test2)); assertEquals(views.get(test1).getViewData(), "test1"); assertEquals(views.get(test2).getViewData(), "test2"); // drop first view metadata.dropView(SESSION, test1); views = metadata.getViews(SESSION, new SchemaTablePrefix("test")); assertEquals(views.keySet(), ImmutableSet.of(test2)); // drop second view metadata.dropView(SESSION, test2); views = metadata.getViews(SESSION, new SchemaTablePrefix("test")); assertTrue(views.isEmpty()); // verify listing everything views = metadata.getViews(SESSION, new SchemaTablePrefix()); assertTrue(views.isEmpty()); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { return tables.values().stream() .filter(table -> prefix.matches(table.toSchemaTableName())) .collect(toMap(BlackHoleTableHandle::toSchemaTableName, handle -> handle.toTableMetadata().getColumns())); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> builder = ImmutableMap.builder(); for (Entry<SchemaTableName, ConnectorTableMetadata> entry : TABLES.entrySet()) { if (prefix.matches(entry.getKey())) { builder.put(entry.getKey(), entry.getValue().getColumns()); } } return builder.build(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> builder = ImmutableMap.builder(); for (Entry<SchemaTableName, ConnectorTableMetadata> entry : tables.entrySet()) { if (prefix.matches(entry.getKey())) { builder.put(entry.getKey(), entry.getValue().getColumns()); } } return builder.build(); }
public SchemaTablePrefix asSchemaTablePrefix() { if (!schemaName.isPresent()) { return new SchemaTablePrefix(); } else if (!tableName.isPresent()) { return new SchemaTablePrefix(schemaName.get()); } else { return new SchemaTablePrefix(schemaName.get(), tableName.get()); } }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder(); for (SchemaTableName tableName : listTables(session, prefix.getSchemaName())) { ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder(); for (ColumnMetadata column : tables.get(tableName).getColumns()) { columns.add(new ColumnMetadata(column.getName(), column.getType(), false)); } tableColumns.put(tableName, columns.build()); } return tableColumns.build(); }
@Override public Map<SchemaTableName, ConnectorViewDefinition> getViews(ConnectorSession session, SchemaTablePrefix prefix) { ImmutableMap.Builder<SchemaTableName, ConnectorViewDefinition> map = ImmutableMap.builder(); for (Map.Entry<SchemaTableName, String> entry : views.entrySet()) { if (prefix.matches(entry.getKey())) { map.put(entry.getKey(), new ConnectorViewDefinition(entry.getKey(), Optional.empty(), entry.getValue())); } } return map.build(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder(); for (String schemaName : getSchemaNames(session, prefix.getSchemaName())) { for (TpchTable<?> tpchTable : TpchTable.getTables()) { if (prefix.getTableName() == null || tpchTable.getTableName().equals(prefix.getTableName())) { ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpchTable); tableColumns.put(new SchemaTableName(schemaName, tpchTable.getTableName()), tableMetadata.getColumns()); } } } return tableColumns.build(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) { return delegate.listTableColumns(session, prefix); } }
@Override public Map<SchemaTableName, ConnectorViewDefinition> getViews(ConnectorSession session, SchemaTablePrefix prefix) { try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) { return delegate.getViews(session, prefix); } }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { requireNonNull(prefix, "prefix is null"); ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder(); for (SchemaTableName tableName : listTables(session, prefix)) { try { columns.put(tableName, getTableMetadata(session, tableName).getColumns()); } catch (NotFoundException e) { // table disappeared during listing operation } } return columns.build(); }
@Test public void testListUnknownSchema() { assertNull(metadata.getTableHandle(SESSION, new SchemaTableName("totally_invalid_database_name", "dual"))); assertEquals(metadata.listTables(SESSION, "totally_invalid_database_name"), ImmutableList.of()); assertEquals(metadata.listTableColumns(SESSION, new SchemaTablePrefix("totally_invalid_database_name", "dual")), ImmutableMap.of()); }
private List<SchemaTableName> listTables(ConnectorSession session, SchemaTablePrefix prefix) { if (prefix.getSchemaName() == null || prefix.getTableName() == null) { return listTables(session, prefix.getSchemaName()); } return ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName())); }
@Test public void testGetAllTableColumns() { Map<SchemaTableName, List<ColumnMetadata>> allColumns = metadata.listTableColumns(newSession(), new SchemaTablePrefix()); assertTrue(allColumns.containsKey(tablePartitionFormat)); assertTrue(allColumns.containsKey(tableUnpartitioned)); }
@Test public void testGetAllTableColumnsInSchema() { Map<SchemaTableName, List<ColumnMetadata>> allColumns = metadata.listTableColumns(newSession(), new SchemaTablePrefix(database)); assertTrue(allColumns.containsKey(tablePartitionFormat)); assertTrue(allColumns.containsKey(tableUnpartitioned)); }
@Test public void testListUnknownSchema() { ConnectorSession session = newSession(); assertNull(metadata.getTableHandle(session, new SchemaTableName(INVALID_DATABASE, INVALID_TABLE))); assertEquals(metadata.listTables(session, INVALID_DATABASE), ImmutableList.of()); assertEquals(metadata.listTableColumns(session, new SchemaTablePrefix(INVALID_DATABASE, INVALID_TABLE)), ImmutableMap.of()); assertEquals(metadata.listViews(session, INVALID_DATABASE), ImmutableList.of()); assertEquals(metadata.getViews(session, new SchemaTablePrefix(INVALID_DATABASE, INVALID_TABLE)), ImmutableMap.of()); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession connectorSession, SchemaTablePrefix schemaTablePrefix) { return null; }
@Override public Map<SchemaTableName, ConnectorViewDefinition> getViews(ConnectorSession session, SchemaTablePrefix prefix) { return emptyMap(); }
@Override public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) { return metadata.listTableColumns(session, prefix); }
@Override public Map<SchemaTableName, ConnectorViewDefinition> getViews(ConnectorSession session, SchemaTablePrefix prefix) { return metadata.getViews(session, prefix); }