use of alluxio.grpc.table.FieldSchema in project presto by prestodb.
the class AlluxioProtoUtils method fromProto.
public static Table fromProto(alluxio.grpc.table.TableInfo table) {
if (!table.hasLayout()) {
throw new UnsupportedOperationException("Unsupported table metadata. missing layout.");
}
Layout layout = table.getLayout();
if (!alluxio.table.ProtoUtils.isHiveLayout(layout)) {
throw new UnsupportedOperationException("Unsupported table layout: " + layout);
}
try {
PartitionInfo partitionInfo = alluxio.table.ProtoUtils.toHiveLayout(layout);
// compute the data columns
Set<String> partitionColumns = table.getPartitionColsList().stream().map(FieldSchema::getName).collect(toImmutableSet());
List<FieldSchema> dataColumns = table.getSchema().getColsList().stream().filter((field) -> !partitionColumns.contains(field.getName())).collect(toImmutableList());
Table.Builder builder = Table.builder().setDatabaseName(table.getDbName()).setTableName(table.getTableName()).setOwner(table.getOwner()).setTableType(PrestoTableType.OTHER).setDataColumns(dataColumns.stream().map(AlluxioProtoUtils::fromProto).collect(toImmutableList())).setPartitionColumns(table.getPartitionColsList().stream().map(AlluxioProtoUtils::fromProto).collect(toImmutableList())).setParameters(table.getParametersMap()).setViewOriginalText(Optional.empty()).setViewExpandedText(Optional.empty());
alluxio.grpc.table.layout.hive.Storage storage = partitionInfo.getStorage();
// TODO: We should also set storage parameters here when they are available in alluxio.grpc.table.layout.hive.Storage
builder.getStorageBuilder().setSkewed(storage.getSkewed()).setStorageFormat(fromProto(storage.getStorageFormat())).setLocation(storage.getLocation()).setBucketProperty(storage.hasBucketProperty() ? fromProto(storage.getBucketProperty()) : Optional.empty()).setSerdeParameters(storage.getStorageFormat().getSerdelibParametersMap());
return builder.build();
} catch (InvalidProtocolBufferException e) {
throw new IllegalArgumentException("Failed to extract PartitionInfo from TableInfo", e);
}
}
Aggregations