Cleanup code in HiveSplitManager
*/
package com.facebook.presto.hive;
+import com.facebook.presto.hive.HiveBucketing.HiveBucket;
import com.facebook.presto.hive.metastore.Column;
import com.facebook.presto.hive.metastore.Partition;
import com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore;
@@ -157,28 +158,37 @@ public class HiveSplitManager
HiveTableLayoutHandle layout = (HiveTableLayoutHandle) layoutHandle;
SchemaTableName tableName = layout.getSchemaTableName();
- List<HivePartition> partitions = layout.getPartitions().get();
+ // get table metadata
+ SemiTransactionalHiveMetastore metastore = metastoreProvider.apply((HiveTransactionHandle) transaction);
+ Table table = metastore.getTable(tableName.getSchemaName(), tableName.getTableName())
+ .orElseThrow(() -> new TableNotFoundException(tableName));
+
+ // get partitions
+ List<HivePartition> partitions = layout.getPartitions()
+ .orElseThrow(() -> new PrestoException(GENERIC_INTERNAL_ERROR, "Layout does not contain partitions"));
+ // short circuit if we don't have any partitions
HivePartition partition = Iterables.getFirst(partitions, null);
if (partition == null) {
return new FixedSplitSource(ImmutableList.of());
}
- List<HiveBucketing.HiveBucket> buckets = partition.getBuckets();
+
+ // get buckets from first partition (arbitrary)
+ List<HiveBucket> buckets = partition.getBuckets();
+
+ // validate bucket bucketed execution
Optional<HiveBucketHandle> bucketHandle = layout.getBucketHandle();
- checkArgument(splitSchedulingStrategy != GROUPED_SCHEDULING || bucketHandle.isPresent(), "SchedulingPolicy is bucketed, but BucketHandle is not present");
+ if ((splitSchedulingStrategy == GROUPED_SCHEDULING) && !bucketHandle.isPresent()) {
+ throw new PrestoException(GENERIC_INTERNAL_ERROR, "SchedulingPolicy is bucketed, but BucketHandle is not present");
+ }
// sort partitions
partitions = Ordering.natural().onResultOf(HivePartition::getPartitionId).reverse().sortedCopy(partitions);
- SemiTransactionalHiveMetastore metastore = metastoreProvider.apply((HiveTransactionHandle) transaction);
- Optional<Table> table = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
- if (!table.isPresent()) {
- throw new TableNotFoundException(tableName);
- }
- Iterable<HivePartitionMetadata> hivePartitions = getPartitionMetadata(metastore, table.get(), tableName, partitions, bucketHandle.map(HiveBucketHandle::toBucketProperty));
+ Iterable<HivePartitionMetadata> hivePartitions = getPartitionMetadata(metastore, table, tableName, partitions, bucketHandle.map(HiveBucketHandle::toBucketProperty));
HiveSplitLoader hiveSplitLoader = new BackgroundHiveSplitLoader(
- table.get(),
+ table,
hivePartitions,
layout.getCompactEffectivePredicate(),
createBucketSplitInfo(bucketHandle, buckets),
@@ -195,8 +205,8 @@ public class HiveSplitManager
case UNGROUPED_SCHEDULING:
splitSource = HiveSplitSource.allAtOnce(
session,
- table.get().getDatabaseName(),
- table.get().getTableName(),
+ table.getDatabaseName(),
+ table.getTableName(),
layout.getCompactEffectivePredicate(),
maxInitialSplits,
maxOutstandingSplits,
@@ -208,8 +218,8 @@ public class HiveSplitManager
case GROUPED_SCHEDULING:
splitSource = HiveSplitSource.bucketed(
session,
- table.get().getDatabaseName(),
- table.get().getTableName(),
+ table.getDatabaseName(),
+ table.getTableName(),
layout.getCompactEffectivePredicate(),
maxInitialSplits,
maxOutstandingSplits,
