Search in sources :

Example 1 with InternalHiveSplit

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

the class InternalHiveSplitFactory method createInternalHiveSplit.

private Optional<InternalHiveSplit> createInternalHiveSplit(Path path, BlockLocation[] blockLocations, long start, long length, // Estimated because, for example, encrypted S3 files may be padded, so reported size may not reflect actual size
long estimatedFileSize, long fileModificationTime, OptionalInt bucketNumber, boolean splittable, Optional<AcidInfo> acidInfo) {
    String pathString = path.toString();
    if (!pathMatchesPredicate(pathDomain, pathString)) {
        return Optional.empty();
    }
    // per HIVE-13040 empty files are allowed
    if (estimatedFileSize == 0) {
        return Optional.empty();
    }
    // but it might be ready when splits are enumerated lazily.
    if (!partitionMatchSupplier.getAsBoolean()) {
        return Optional.empty();
    }
    if (maxSplitFileSize.isPresent() && estimatedFileSize > maxSplitFileSize.get()) {
        return Optional.empty();
    }
    ImmutableList.Builder<InternalHiveBlock> blockBuilder = ImmutableList.builder();
    for (BlockLocation blockLocation : blockLocations) {
        // clamp the block range
        long blockStart = Math.max(start, blockLocation.getOffset());
        long blockEnd = Math.min(start + length, blockLocation.getOffset() + blockLocation.getLength());
        if (blockStart > blockEnd) {
            // block is outside split range
            continue;
        }
        if (blockStart == blockEnd && !(blockStart == start && blockEnd == start + length)) {
            // skip zero-width block, except in the special circumstance: slice is empty, and the block covers the empty slice interval.
            continue;
        }
        blockBuilder.add(new InternalHiveBlock(blockStart, blockEnd, getHostAddresses(blockLocation)));
    }
    List<InternalHiveBlock> blocks = blockBuilder.build();
    checkBlocks(path, blocks, start, length);
    if (!splittable) {
        // not splittable, use the hosts from the first block if it exists
        blocks = ImmutableList.of(new InternalHiveBlock(start, start + length, blocks.get(0).getAddresses()));
    }
    int bucketNumberIndex = bucketNumber.orElse(0);
    return Optional.of(new InternalHiveSplit(partitionName, pathString, start, start + length, estimatedFileSize, fileModificationTime, schema, partitionKeys, blocks, bucketNumber, () -> bucketStatementCounters.computeIfAbsent(bucketNumberIndex, index -> new AtomicInteger()).getAndIncrement(), splittable, forceLocalScheduling && allBlocksHaveAddress(blocks), tableToPartitionMapping, bucketConversion, bucketValidation, s3SelectPushdownEnabled && S3SelectPushdown.isCompressionCodecSupported(inputFormat, path), acidInfo, partitionMatchSupplier));
}
Also used : Arrays(java.util.Arrays) InternalHiveBlock(io.trino.plugin.hive.InternalHiveSplit.InternalHiveBlock) BlockLocation(org.apache.hadoop.fs.BlockLocation) FileSystem(org.apache.hadoop.fs.FileSystem) FileStatus(org.apache.hadoop.fs.FileStatus) OptionalInt(java.util.OptionalInt) BooleanSupplier(java.util.function.BooleanSupplier) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) FileSplit(org.apache.hadoop.mapred.FileSplit) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) InputFormat(org.apache.hadoop.mapred.InputFormat) Path(org.apache.hadoop.fs.Path) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) HiveColumnHandle.isPathColumnHandle(io.trino.plugin.hive.HiveColumnHandle.isPathColumnHandle) BucketConversion(io.trino.plugin.hive.HiveSplit.BucketConversion) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle) InternalHiveSplit(io.trino.plugin.hive.InternalHiveSplit) AcidTransaction(io.trino.plugin.hive.acid.AcidTransaction) Properties(java.util.Properties) HivePartitionKey(io.trino.plugin.hive.HivePartitionKey) Domain(io.trino.spi.predicate.Domain) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) HiveSplit(io.trino.plugin.hive.HiveSplit) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HiveUtil.isSplittable(io.trino.plugin.hive.util.HiveUtil.isSplittable) IOException(java.io.IOException) TupleDomain(io.trino.spi.predicate.TupleDomain) AcidInfo(io.trino.plugin.hive.AcidInfo) UncheckedIOException(java.io.UncheckedIOException) DataSize(io.airlift.units.DataSize) List(java.util.List) TableToPartitionMapping(io.trino.plugin.hive.TableToPartitionMapping) S3SelectPushdown(io.trino.plugin.hive.s3select.S3SelectPushdown) Optional(java.util.Optional) HostAddress(io.trino.spi.HostAddress) InternalHiveBlock(io.trino.plugin.hive.InternalHiveSplit.InternalHiveBlock) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) InternalHiveSplit(io.trino.plugin.hive.InternalHiveSplit) BlockLocation(org.apache.hadoop.fs.BlockLocation)

Aggregations

Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 DataSize (io.airlift.units.DataSize)1 AcidInfo (io.trino.plugin.hive.AcidInfo)1 HiveColumnHandle (io.trino.plugin.hive.HiveColumnHandle)1 HiveColumnHandle.isPathColumnHandle (io.trino.plugin.hive.HiveColumnHandle.isPathColumnHandle)1 HivePartitionKey (io.trino.plugin.hive.HivePartitionKey)1 HiveSplit (io.trino.plugin.hive.HiveSplit)1 BucketConversion (io.trino.plugin.hive.HiveSplit.BucketConversion)1 InternalHiveSplit (io.trino.plugin.hive.InternalHiveSplit)1 InternalHiveBlock (io.trino.plugin.hive.InternalHiveSplit.InternalHiveBlock)1 TableToPartitionMapping (io.trino.plugin.hive.TableToPartitionMapping)1 AcidTransaction (io.trino.plugin.hive.acid.AcidTransaction)1 S3SelectPushdown (io.trino.plugin.hive.s3select.S3SelectPushdown)1 HiveUtil.isSplittable (io.trino.plugin.hive.util.HiveUtil.isSplittable)1 HostAddress (io.trino.spi.HostAddress)1 Domain (io.trino.spi.predicate.Domain)1 TupleDomain (io.trino.spi.predicate.TupleDomain)1