Search in sources :

Example 6 with HiveBucketProperty

use of io.trino.plugin.hive.HiveBucketProperty in project trino by trinodb.

the class ThriftMetastoreUtil method makeStorageDescriptor.

private static StorageDescriptor makeStorageDescriptor(String tableName, List<Column> columns, Storage storage) {
    SerDeInfo serdeInfo = new SerDeInfo();
    serdeInfo.setName(tableName);
    serdeInfo.setSerializationLib(storage.getStorageFormat().getSerDeNullable());
    serdeInfo.setParameters(storage.getSerdeParameters());
    StorageDescriptor sd = new StorageDescriptor();
    sd.setLocation(emptyToNull(storage.getOptionalLocation().orElse(null)));
    sd.setCols(columns.stream().map(ThriftMetastoreUtil::toMetastoreApiFieldSchema).collect(toImmutableList()));
    sd.setSerdeInfo(serdeInfo);
    sd.setInputFormat(storage.getStorageFormat().getInputFormatNullable());
    sd.setOutputFormat(storage.getStorageFormat().getOutputFormatNullable());
    sd.setSkewedInfoIsSet(storage.isSkewed());
    sd.setParameters(ImmutableMap.of());
    Optional<HiveBucketProperty> bucketProperty = storage.getBucketProperty();
    if (bucketProperty.isPresent()) {
        sd.setNumBuckets(bucketProperty.get().getBucketCount());
        sd.setBucketCols(bucketProperty.get().getBucketedBy());
        if (!bucketProperty.get().getSortedBy().isEmpty()) {
            sd.setSortCols(bucketProperty.get().getSortedBy().stream().map(column -> new Order(column.getColumnName(), column.getOrder().getHiveOrder())).collect(toImmutableList()));
        }
    }
    return sd;
}
Also used : Order(org.apache.hadoop.hive.metastore.api.Order) HiveBucketProperty(io.trino.plugin.hive.HiveBucketProperty) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor)

Example 7 with HiveBucketProperty

use of io.trino.plugin.hive.HiveBucketProperty in project trino by trinodb.

the class ProtoUtils method fromProto.

static Optional<HiveBucketProperty> fromProto(Map<String, String> tableParameters, alluxio.grpc.table.layout.hive.HiveBucketProperty property) {
    // must return empty if buckets <= 0
    if (!property.hasBucketCount() || property.getBucketCount() <= 0) {
        return Optional.empty();
    }
    List<SortingColumn> sortedBy = property.getSortedByList().stream().map(ProtoUtils::fromProto).collect(toImmutableList());
    HiveBucketing.BucketingVersion bucketingVersion = HiveBucketing.getBucketingVersion(tableParameters);
    return Optional.of(new HiveBucketProperty(property.getBucketedByList(), bucketingVersion, (int) property.getBucketCount(), sortedBy));
}
Also used : HiveBucketProperty(io.trino.plugin.hive.HiveBucketProperty) SortingColumn(io.trino.plugin.hive.metastore.SortingColumn) HiveBucketing(io.trino.plugin.hive.util.HiveBucketing)

Example 8 with HiveBucketProperty

use of io.trino.plugin.hive.HiveBucketProperty in project trino by trinodb.

the class GlueInputConverter method convertStorage.

private static StorageDescriptor convertStorage(Storage storage, List<Column> columns) {
    if (storage.isSkewed()) {
        throw new IllegalArgumentException("Writing to skewed table/partition is not supported");
    }
    SerDeInfo serdeInfo = new SerDeInfo().withSerializationLibrary(storage.getStorageFormat().getSerDeNullable()).withParameters(storage.getSerdeParameters());
    StorageDescriptor sd = new StorageDescriptor();
    sd.setLocation(storage.getLocation());
    sd.setColumns(columns.stream().map(GlueInputConverter::convertColumn).collect(toImmutableList()));
    sd.setSerdeInfo(serdeInfo);
    sd.setInputFormat(storage.getStorageFormat().getInputFormatNullable());
    sd.setOutputFormat(storage.getStorageFormat().getOutputFormatNullable());
    sd.setParameters(ImmutableMap.of());
    Optional<HiveBucketProperty> bucketProperty = storage.getBucketProperty();
    if (bucketProperty.isPresent()) {
        sd.setNumberOfBuckets(bucketProperty.get().getBucketCount());
        sd.setBucketColumns(bucketProperty.get().getBucketedBy());
        if (!bucketProperty.get().getSortedBy().isEmpty()) {
            sd.setSortColumns(bucketProperty.get().getSortedBy().stream().map(column -> new Order().withColumn(column.getColumnName()).withSortOrder(column.getOrder().getHiveOrder())).collect(toImmutableList()));
        }
    }
    return sd;
}
Also used : Order(com.amazonaws.services.glue.model.Order) HiveBucketProperty(io.trino.plugin.hive.HiveBucketProperty) SerDeInfo(com.amazonaws.services.glue.model.SerDeInfo) StorageDescriptor(com.amazonaws.services.glue.model.StorageDescriptor)

Aggregations

HiveBucketProperty (io.trino.plugin.hive.HiveBucketProperty)8 SortingColumn (io.trino.plugin.hive.metastore.SortingColumn)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 HiveBucketHandle (io.trino.plugin.hive.HiveBucketHandle)3 HiveColumnHandle (io.trino.plugin.hive.HiveColumnHandle)3 HiveTimestampPrecision (io.trino.plugin.hive.HiveTimestampPrecision)3 TrinoException (io.trino.spi.TrinoException)3 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Lists.cartesianProduct (com.google.common.collect.Lists.cartesianProduct)2 BUCKET_COLUMN_NAME (io.trino.plugin.hive.HiveColumnHandle.BUCKET_COLUMN_NAME)2 HIVE_INVALID_METADATA (io.trino.plugin.hive.HiveErrorCode.HIVE_INVALID_METADATA)2 HiveSessionProperties.getTimestampPrecision (io.trino.plugin.hive.HiveSessionProperties.getTimestampPrecision)2 HiveTableHandle (io.trino.plugin.hive.HiveTableHandle)2 HiveType (io.trino.plugin.hive.HiveType)2 Column (io.trino.plugin.hive.metastore.Column)2 Table (io.trino.plugin.hive.metastore.Table)2