Search in sources :

Example 1 with HiveBucketHandle

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

the class HiveBucketing method getHiveBucketHandle.

public static Optional<HiveBucketHandle> getHiveBucketHandle(ConnectorSession session, Table table, TypeManager typeManager) {
    if (table.getParameters().containsKey(SPARK_TABLE_PROVIDER_KEY)) {
        return Optional.empty();
    }
    Optional<HiveBucketProperty> hiveBucketProperty = table.getStorage().getBucketProperty();
    if (hiveBucketProperty.isEmpty()) {
        return Optional.empty();
    }
    if (!isSupportedBucketing(table)) {
        return Optional.empty();
    }
    HiveTimestampPrecision timestampPrecision = getTimestampPrecision(session);
    Map<String, HiveColumnHandle> map = getRegularColumnHandles(table, typeManager, timestampPrecision).stream().collect(Collectors.toMap(HiveColumnHandle::getName, identity()));
    ImmutableList.Builder<HiveColumnHandle> bucketColumns = ImmutableList.builder();
    for (String bucketColumnName : hiveBucketProperty.get().getBucketedBy()) {
        HiveColumnHandle bucketColumnHandle = map.get(bucketColumnName);
        if (bucketColumnHandle == null) {
            throw new TrinoException(HIVE_INVALID_METADATA, format("Table '%s.%s' is bucketed on non-existent column '%s'", table.getDatabaseName(), table.getTableName(), bucketColumnName));
        }
        bucketColumns.add(bucketColumnHandle);
    }
    BucketingVersion bucketingVersion = hiveBucketProperty.get().getBucketingVersion();
    int bucketCount = hiveBucketProperty.get().getBucketCount();
    List<SortingColumn> sortedBy = hiveBucketProperty.get().getSortedBy();
    return Optional.of(new HiveBucketHandle(bucketColumns.build(), bucketingVersion, bucketCount, bucketCount, sortedBy));
}
Also used : SortingColumn(io.trino.plugin.hive.metastore.SortingColumn) HiveTimestampPrecision(io.trino.plugin.hive.HiveTimestampPrecision) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) HiveBucketProperty(io.trino.plugin.hive.HiveBucketProperty) HiveBucketHandle(io.trino.plugin.hive.HiveBucketHandle) TrinoException(io.trino.spi.TrinoException) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 HiveBucketHandle (io.trino.plugin.hive.HiveBucketHandle)1 HiveBucketProperty (io.trino.plugin.hive.HiveBucketProperty)1 HiveColumnHandle (io.trino.plugin.hive.HiveColumnHandle)1 HiveTimestampPrecision (io.trino.plugin.hive.HiveTimestampPrecision)1 SortingColumn (io.trino.plugin.hive.metastore.SortingColumn)1 TrinoException (io.trino.spi.TrinoException)1