@Override public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) { ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle); SchemaTableName tableName = getTableName(tableHandle); ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder(); columns.addAll(tableMetadata.getColumns()); columns.add(column); tables.put(tableName, new ConnectorTableMetadata(tableName, columns.build(), tableMetadata.getProperties(), tableMetadata.getComment())); }
public MemoryTableHandle( String connectorId, Long tableId, ConnectorTableMetadata tableMetadata) { this(connectorId, tableMetadata.getTable().getSchemaName(), tableMetadata.getTable().getTableName(), tableId, MemoryColumnHandle.extractColumnHandles(tableMetadata.getColumns())); }
@Override public TableStatisticsMetadata getStatisticsCollectionMetadata(ConnectorSession session, ConnectorTableMetadata tableMetadata) { List<String> partitionedBy = firstNonNull(getPartitionedBy(tableMetadata.getProperties()), ImmutableList.of()); return getStatisticsCollectionMetadata(tableMetadata.getColumns(), partitionedBy, true); }
@Override public ConnectorTableMetadata getTableMetadata() { return new ConnectorTableMetadata(tableName, partitionSystemTableColumns); }
static List<ColumnMetadata> informationSchemaTableColumns(SchemaTableName tableName) { checkArgument(TABLES.containsKey(tableName), "table does not exist: %s", tableName); return TABLES.get(tableName).getColumns(); }
@Override public String toString() { return catalog + "." + tableMetadata.getTable(); } }
public KuduTable createTable(ConnectorTableMetadata tableMetadata, boolean ignoreExisting) { try { String rawName = schemaEmulation.toRawName(tableMetadata.getTable()); if (ignoreExisting) { if (client.tableExists(rawName)) { return null; } } if (!schemaEmulation.existsSchema(client, tableMetadata.getTable().getSchemaName())) { throw new SchemaNotFoundException(tableMetadata.getTable().getSchemaName()); } List<ColumnMetadata> columns = tableMetadata.getColumns(); Map<String, Object> properties = tableMetadata.getProperties(); Schema schema = buildSchema(columns, properties); CreateTableOptions options = buildCreateTableOptions(schema, properties); return client.createTable(rawName, schema, options); } catch (KuduException e) { throw new PrestoException(GENERIC_INTERNAL_ERROR, e); } }
List<TableElement> columns = connectorTableMetadata.getColumns().stream() .filter(column -> !column.isHidden()) .map(column -> { .collect(toImmutableList()); Map<String, Object> properties = connectorTableMetadata.getProperties(); Map<String, PropertyMetadata<?>> allTableProperties = metadata.getTablePropertyManager().getAllProperties().get(tableHandle.get().getConnectorId()); List<Property> propertyNodes = buildProperties(objectName, Optional.empty(), INVALID_TABLE_PROPERTY, properties, allTableProperties); false, propertyNodes, connectorTableMetadata.getComment()); return singleValueQuery("Create Table", formatSql(createTable, Optional.of(parameters)).trim());
@Override public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) checkSchemaExists(tableMetadata.getTable().getSchemaName()); int splitCount = (Integer) tableMetadata.getProperties().get(SPLIT_COUNT_PROPERTY); int pagesPerSplit = (Integer) tableMetadata.getProperties().get(PAGES_PER_SPLIT_PROPERTY); int rowsPerPage = (Integer) tableMetadata.getProperties().get(ROWS_PER_PAGE_PROPERTY); int fieldsLength = (Integer) tableMetadata.getProperties().get(FIELD_LENGTH_PROPERTY); Duration pageProcessingDelay = (Duration) tableMetadata.getProperties().get(PAGE_PROCESSING_DELAY);
@Test public void testBucketedCatalog() { String bucketedCatalog = bucketedSession.getCatalog().get(); String bucketedSchema = bucketedSession.getSchema().get(); TableMetadata ordersTableMetadata = getTableMetadata(bucketedCatalog, bucketedSchema, "orders"); assertEquals(ordersTableMetadata.getMetadata().getProperties().get(BUCKETED_BY_PROPERTY), ImmutableList.of("custkey")); assertEquals(ordersTableMetadata.getMetadata().getProperties().get(BUCKET_COUNT_PROPERTY), 11); TableMetadata customerTableMetadata = getTableMetadata(bucketedCatalog, bucketedSchema, "customer"); assertEquals(customerTableMetadata.getMetadata().getProperties().get(BUCKETED_BY_PROPERTY), ImmutableList.of("custkey")); assertEquals(customerTableMetadata.getMetadata().getProperties().get(BUCKET_COUNT_PROPERTY), 11); }
private Map<String, String> getEmptyTableProperties(ConnectorTableMetadata tableMetadata, boolean partitioned, HdfsContext hdfsContext) { Builder<String, String> tableProperties = ImmutableMap.builder(); // Hook point for extended versions of the Hive Plugin tableProperties.putAll(tableParameterCodec.encode(tableMetadata.getProperties())); // ORC format specific properties List<String> columns = getOrcBloomFilterColumns(tableMetadata.getProperties()); if (columns != null && !columns.isEmpty()) { tableProperties.put(ORC_BLOOM_FILTER_COLUMNS_KEY, Joiner.on(",").join(columns)); tableProperties.put(ORC_BLOOM_FILTER_FPP_KEY, String.valueOf(getOrcBloomFilterFpp(tableMetadata.getProperties()))); } // Avro specific properties String avroSchemaUrl = getAvroSchemaUrl(tableMetadata.getProperties()); if (avroSchemaUrl != null) { HiveStorageFormat hiveStorageFormat = getHiveStorageFormat(tableMetadata.getProperties()); if (hiveStorageFormat != HiveStorageFormat.AVRO) { throw new PrestoException(INVALID_TABLE_PROPERTY, format("Cannot specify %s table property for storage format: %s", AVRO_SCHEMA_URL, hiveStorageFormat)); } tableProperties.put(AVRO_SCHEMA_URL_KEY, validateAndNormalizeAvroSchemaUrl(avroSchemaUrl, hdfsContext)); } // Table comment property tableMetadata.getComment().ifPresent(value -> tableProperties.put(TABLE_COMMENT, value)); return tableProperties.build(); }
public ConnectorTableMetadata toConnectorTableMetadata() { return new ConnectorTableMetadata( schemaTableName, columns, ImmutableMap.of(), comment); }
private static int getColumnIndex(ConnectorTableMetadata tableMetadata, String columnName) { List<ColumnMetadata> columns = tableMetadata.getColumns(); for (int i = 0; i < columns.size(); i++) { if (columns.get(i).getName().equals(columnName)) { return i; } } throw new IllegalArgumentException(format("Column %s not found", columnName)); }
@Override public Optional<ConnectorNewTableLayout> getNewTableLayout(ConnectorSession connectorSession, ConnectorTableMetadata tableMetadata) { List<String> distributeColumns = (List<String>) tableMetadata.getProperties().get(DISTRIBUTED_ON); if (distributeColumns.isEmpty()) { return Optional.empty(); } Set<String> undefinedColumns = Sets.difference( ImmutableSet.copyOf(distributeColumns), tableMetadata.getColumns().stream() .map(ColumnMetadata::getName) .collect(toSet())); if (!undefinedColumns.isEmpty()) { throw new PrestoException(INVALID_TABLE_PROPERTY, "Distribute columns not defined on table: " + undefinedColumns); } return Optional.of(new ConnectorNewTableLayout(BlackHolePartitioningHandle.INSTANCE, distributeColumns)); }
@Override public String toString() { return catalog + "." + tableMetadata.getTable(); } }
private static void assertTableEqual(ConnectorTableMetadata actual, ConnectorTableMetadata expected) { assertEquals(actual.getTable(), expected.getTable()); List<ColumnMetadata> actualColumns = actual.getColumns().stream() .filter(columnMetadata -> !columnMetadata.isHidden()) .collect(Collectors.toList()); List<ColumnMetadata> expectedColumns = expected.getColumns(); assertEquals(actualColumns.size(), expectedColumns.size()); for (int i = 0; i < actualColumns.size(); i++) { ColumnMetadata actualColumn = actualColumns.get(i); ColumnMetadata expectedColumn = expectedColumns.get(i); assertEquals(actualColumn.getName(), expectedColumn.getName()); assertEquals(actualColumn.getType(), expectedColumn.getType()); } assertEquals(actual.getProperties(), expected.getProperties()); }
List<TableElement> columns = connectorTableMetadata.getColumns().stream() .filter(column -> !column.isHidden()) .map(column -> { .collect(toImmutableList()); Map<String, Object> properties = connectorTableMetadata.getProperties(); Map<String, PropertyMetadata<?>> allTableProperties = metadata.getTablePropertyManager().getAllProperties().get(tableHandle.get().getConnectorId()); List<Property> propertyNodes = buildProperties(objectName, Optional.empty(), INVALID_TABLE_PROPERTY, properties, allTableProperties); false, propertyNodes, connectorTableMetadata.getComment()); return singleValueQuery("Create Table", formatSql(createTable, Optional.of(parameters)).trim());
@Override public ConnectorTableHandle getTableHandleForStatisticsCollection(ConnectorSession session, SchemaTableName tableName, Map<String, Object> analyzeProperties) { HiveTableHandle handle = getTableHandle(session, tableName); if (handle == null) { return null; } Optional<List<List<String>>> partitionValuesList = getPartitionList(analyzeProperties); ConnectorTableMetadata tableMetadata = getTableMetadata(handle.getSchemaTableName()); handle = handle.withAnalyzePartitionValues(partitionValuesList); List<String> partitionedBy = getPartitionedBy(tableMetadata.getProperties()); if (partitionValuesList.isPresent() && partitionedBy.isEmpty()) { throw new PrestoException(INVALID_ANALYZE_PROPERTY, "Only partitioned table can be analyzed with a partition list"); } return handle; }
@Override public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) { ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle); SchemaTableName tableName = getTableName(tableHandle); ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder(); columns.addAll(tableMetadata.getColumns()); columns.add(column); tables.put(tableName, new ConnectorTableMetadata(tableName, columns.build(), tableMetadata.getProperties(), tableMetadata.getComment())); }
public ConnectorTableMetadata getTableMetadata() { return new ConnectorTableMetadata( tableName, ImmutableList.copyOf(transform(columnHandles, JmxColumnHandle::getColumnMetadata))); } }