public ThriftColumnHandle(ColumnMetadata columnMetadata) { this(columnMetadata.getName(), columnMetadata.getType(), columnMetadata.getComment(), columnMetadata.isHidden()); }
@Override public void renameColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle source, String target) { ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle); SchemaTableName tableName = getTableName(tableHandle); ColumnMetadata columnMetadata = getColumnMetadata(session, tableHandle, source); List<ColumnMetadata> columns = new ArrayList<>(tableMetadata.getColumns()); columns.set(columns.indexOf(columnMetadata), new ColumnMetadata(target, columnMetadata.getType(), columnMetadata.getComment(), columnMetadata.isHidden())); tables.put(tableName, new ConnectorTableMetadata(tableName, ImmutableList.copyOf(columns), tableMetadata.getProperties(), tableMetadata.getComment())); }
private static List<HiveColumnHandle> getColumnHandles(ConnectorTableMetadata tableMetadata, Set<String> partitionColumnNames, TypeTranslator typeTranslator) { validatePartitionColumns(tableMetadata); validateBucketColumns(tableMetadata); ImmutableList.Builder<HiveColumnHandle> columnHandles = ImmutableList.builder(); int ordinal = 0; for (ColumnMetadata column : tableMetadata.getColumns()) { HiveColumnHandle.ColumnType columnType; if (partitionColumnNames.contains(column.getName())) { columnType = PARTITION_KEY; } else if (column.isHidden()) { columnType = SYNTHESIZED; } else { columnType = REGULAR; } columnHandles.add(new HiveColumnHandle( column.getName(), toHiveType(typeTranslator, column.getType()), column.getType().getTypeSignature(), ordinal, columnType, Optional.ofNullable(column.getComment()))); ordinal++; } return columnHandles.build(); }
@Override public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) { HiveTableHandle handle = (HiveTableHandle) tableHandle; failIfAvroSchemaIsSet(handle); metastore.addColumn(handle.getSchemaName(), handle.getTableName(), column.getName(), toHiveType(typeTranslator, column.getType()), column.getComment()); }
private InternalTable buildColumns(Session session, Set<QualifiedTablePrefix> prefixes) { InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_COLUMNS)); for (QualifiedTablePrefix prefix : prefixes) { for (Entry<SchemaTableName, List<ColumnMetadata>> entry : listTableColumns(session, metadata, accessControl, prefix).entrySet()) { SchemaTableName tableName = entry.getKey(); int ordinalPosition = 1; for (ColumnMetadata column : entry.getValue()) { if (column.isHidden()) { continue; } table.add( prefix.getCatalogName(), tableName.getSchemaName(), tableName.getTableName(), column.getName(), ordinalPosition, null, "YES", column.getType().getDisplayName(), column.getComment(), column.getExtraInfo()); ordinalPosition++; } } } return table.build(); }
.map(column -> { List<Property> propertyNodes = buildProperties(objectName, Optional.of(column.getName()), INVALID_COLUMN_PROPERTY, column.getProperties(), allColumnProperties); return new ColumnDefinition(new Identifier(column.getName()), column.getType().getDisplayName(), propertyNodes, Optional.ofNullable(column.getComment())); }) .collect(toImmutableList());
column.getName(), column.getType(), column.getComment(), columnExtraInfo(partitionedBy.contains(column.getName())), false))
numPrecRadix(column.getType()), DatabaseMetaData.columnNullableUnknown, column.getComment(), null, null,
private static void assertPrimitiveField(Map<String, ColumnMetadata> map, String name, Type type, boolean partitionKey) { assertTrue(map.containsKey(name)); ColumnMetadata column = map.get(name); assertEquals(column.getType(), type, name); assertEquals(column.getComment(), annotateColumnComment(null, partitionKey)); }
@Override public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) { if (!allowAddColumn) { throw new PrestoException(PERMISSION_DENIED, "Adding Columns is disabled in this Hive catalog"); } HiveTableHandle handle = checkType(tableHandle, HiveTableHandle.class, "tableHandle"); Optional<Table> tableMetadata = metastore.getTable(handle.getSchemaName(), handle.getTableName()); if (!tableMetadata.isPresent()) { throw new TableNotFoundException(handle.getSchemaTableName()); } Table table = tableMetadata.get(); StorageDescriptor sd = table.getSd(); ImmutableList.Builder<FieldSchema> columns = ImmutableList.builder(); columns.addAll(sd.getCols()); columns.add(new FieldSchema(column.getName(), toHiveType(column.getType()).getHiveTypeName(), column.getComment())); sd.setCols(columns.build()); table.setSd(sd); metastore.alterTable(handle.getSchemaName(), handle.getTableName(), table); }
@Override public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) { checkNoRollback(); //采用乐观锁 设计 SchemaTableName tableName = tableMetadata.getTable(); client.createTable(tableMetadata); //--- es column is sort ---- List<ElasticsearchColumnHandle> columns = tableMetadata.getColumns().stream() .map(columnMetadata -> new ElasticsearchColumnHandle( columnMetadata.getName(), columnMetadata.getType(), columnMetadata.getComment(), true, columnMetadata.isHidden())).collect(Collectors.toList()); ElasticsearchOutputTableHandle handle = new ElasticsearchOutputTableHandle( connectorId, tableName.getSchemaName(), tableName.getTableName(), columns); setRollback(() -> client.dropTable(tableMetadata.getTable())); //回滚操作 return handle; }
private InternalTable buildColumns(Session session, String catalogName, Map<String, NullableValue> filters) { InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_COLUMNS)); for (Entry<QualifiedObjectName, List<ColumnMetadata>> entry : getColumnsList(session, catalogName, filters).entrySet()) { QualifiedObjectName tableName = entry.getKey(); int ordinalPosition = 1; for (ColumnMetadata column : entry.getValue()) { if (column.isHidden()) { continue; } table.add( tableName.getCatalogName(), tableName.getSchemaName(), tableName.getObjectName(), column.getName(), ordinalPosition, null, "YES", column.getType().getDisplayName(), column.getComment()); ordinalPosition++; } } return table.build(); }
@Override protected FieldDto toFieldDto(ColumnMetadata column) { if ( column == null ) { return null; } FieldDto fieldDto = new FieldDto(); fieldDto.setPartition_key( column.isPartitionKey() ); fieldDto.setName( column.getName() ); fieldDto.setComment( column.getComment() ); fieldDto.setType( toString( column.getType() ) ); return fieldDto; }
public void createPartitionedTableAs(HiveStorageFormat storageFormat) throws Exception { @Language("SQL") String createTable = "" + "CREATE TABLE test_create_partitioned_table_as " + "WITH (" + "format = '" + storageFormat + "', " + "partitioned_by = ARRAY[ 'SHIP_PRIORITY', 'ORDER_STATUS' ]" + ") " + "AS " + "SELECT orderkey AS order_key, shippriority AS ship_priority, orderstatus AS order_status " + "FROM tpch.tiny.orders"; assertUpdate(createTable, "SELECT count(*) from orders"); TableMetadata tableMetadata = getTableMetadata("test_create_partitioned_table_as"); assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat); List<String> partitionedBy = ImmutableList.of("ship_priority", "order_status"); assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), partitionedBy); for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) { boolean partitionKey = partitionedBy.contains(columnMetadata.getName()); assertEquals(columnMetadata.getComment(), annotateColumnComment(null, partitionKey)); } List<HivePartition> partitions = getPartitions("test_create_partitioned_table_as"); assertEquals(partitions.size(), 3); assertQuery("SELECT * from test_create_partitioned_table_as", "SELECT orderkey, shippriority, orderstatus FROM orders"); assertUpdate("DROP TABLE test_create_partitioned_table_as"); assertFalse(queryRunner.tableExists(getSession(), "test_create_partitioned_table_as")); }
for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) { boolean partitionKey = partitionedBy.contains(columnMetadata.getName()); assertEquals(columnMetadata.getComment(), annotateColumnComment(null, partitionKey));
/** * Converts from column metadata to field. * @param column column * @return field */ public Field toField(final ColumnMetadata column) { final Field result = new Field(); result.setName(column.getName()); result.setPartitionKey(column.isPartitionKey()); result.setComment(column.getComment()); result.setSourceType(column.getType().getDisplayName()); result.setType(toTypeString(column.getType())); return result; }
column.getName(), column.getType(), annotateColumnComment(column.getComment(), partitionedBy.contains(column.getName())), false)) .collect(toList());
column.getName(), column.getType(), column.getComment(), columnExtraInfo(partitionedBy.contains(column.getName())), false))
10, DatabaseMetaData.columnNullableUnknown, column.getComment(), null, null,