use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class AccumuloClient method validateLocalityGroups.
private static void validateLocalityGroups(ConnectorTableMetadata meta) {
// Validate any configured locality groups
Optional<Map<String, Set<String>>> groups = AccumuloTableProperties.getLocalityGroups(meta.getProperties());
if (!groups.isPresent()) {
return;
}
String rowIdColumn = getRowIdColumn(meta);
// For each locality group
for (Map.Entry<String, Set<String>> g : groups.get().entrySet()) {
if (g.getValue().contains(rowIdColumn)) {
throw new PrestoException(INVALID_TABLE_PROPERTY, "Row ID column cannot be in a locality group");
}
// Validate the specified column names exist in the table definition,
// incrementing a counter for each matching column
int matchingColumns = 0;
for (ColumnMetadata column : meta.getColumns()) {
if (g.getValue().contains(column.getName().toLowerCase(Locale.ENGLISH))) {
++matchingColumns;
// Break out early if all columns are found
if (matchingColumns == g.getValue().size()) {
break;
}
}
}
// (or there is a duplicate column in the table DDL, which is also an issue but has been checked before in validateColumns).
if (matchingColumns != g.getValue().size()) {
throw new PrestoException(INVALID_TABLE_PROPERTY, "Unknown Presto column defined for locality group " + g.getKey());
}
}
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class HiveMetadata method getColumnHandles.
private static List<HiveColumnHandle> getColumnHandles(String connectorId, 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 = HIDDEN;
} else {
columnType = REGULAR;
}
columnHandles.add(new HiveColumnHandle(connectorId, column.getName(), toHiveType(typeTranslator, column.getType()), column.getType().getTypeSignature(), ordinal, columnType, Optional.ofNullable(column.getComment())));
ordinal++;
}
return columnHandles.build();
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class HiveMetadata method getTableMetadata.
private ConnectorTableMetadata getTableMetadata(SchemaTableName tableName) {
Optional<Table> table = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
if (!table.isPresent() || table.get().getTableType().equals(TableType.VIRTUAL_VIEW.name())) {
throw new TableNotFoundException(tableName);
}
Function<HiveColumnHandle, ColumnMetadata> metadataGetter = columnMetadataGetter(table.get(), typeManager);
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
for (HiveColumnHandle columnHandle : hiveColumnHandles(connectorId, table.get())) {
columns.add(metadataGetter.apply(columnHandle));
}
ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
if (table.get().getTableType().equals(EXTERNAL_TABLE.name())) {
properties.put(EXTERNAL_LOCATION_PROPERTY, table.get().getStorage().getLocation());
}
try {
HiveStorageFormat format = extractHiveStorageFormat(table.get());
properties.put(STORAGE_FORMAT_PROPERTY, format);
} catch (PrestoException ignored) {
// todo fail if format is not known
}
List<String> partitionedBy = table.get().getPartitionColumns().stream().map(Column::getName).collect(toList());
if (!partitionedBy.isEmpty()) {
properties.put(PARTITIONED_BY_PROPERTY, partitionedBy);
}
Optional<HiveBucketProperty> bucketProperty = table.get().getStorage().getBucketProperty();
if (bucketProperty.isPresent()) {
properties.put(BUCKET_COUNT_PROPERTY, bucketProperty.get().getBucketCount());
properties.put(BUCKETED_BY_PROPERTY, bucketProperty.get().getBucketedBy());
}
properties.putAll(tableParameterCodec.decode(table.get().getParameters()));
return new ConnectorTableMetadata(tableName, columns.build(), properties.build());
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class ExampleMetadata method getColumnHandles.
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
ExampleTableHandle exampleTableHandle = (ExampleTableHandle) tableHandle;
checkArgument(exampleTableHandle.getConnectorId().equals(connectorId), "tableHandle is not for this connector");
ExampleTable table = exampleClient.getTable(exampleTableHandle.getSchemaName(), exampleTableHandle.getTableName());
if (table == null) {
throw new TableNotFoundException(exampleTableHandle.toSchemaTableName());
}
ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
int index = 0;
for (ColumnMetadata column : table.getColumnsMetadata()) {
columnHandles.put(column.getName(), new ExampleColumnHandle(connectorId, column.getName(), column.getType(), index));
index++;
}
return columnHandles.build();
}
use of com.facebook.presto.spi.ColumnMetadata in project presto by prestodb.
the class BlackHoleMetadata method getNewTableLayout.
@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));
}
Aggregations