diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/HiveClientConfig.java b/presto-hive/src/main/java/com/facebook/presto/hive/HiveClientConfig.java index f0207269a59f0..afb7142ef558d 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/HiveClientConfig.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/HiveClientConfig.java @@ -1649,7 +1649,7 @@ public boolean isHudiMetadataEnabled() } @Config("hive.hudi-tables-use-merged-view") - @ConfigDescription("For Hudi tables prefer to fetch the list of files from the merged file system view") + @ConfigDescription("For Hudi tables, a comma-separated list in the form of . which should prefer to fetch the list of files from the merged file system view") public HiveClientConfig setHudiTablesUseMergedView(String hudiTablesUseMergedView) { this.hudiTablesUseMergedView = hudiTablesUseMergedView; diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/HiveSessionProperties.java b/presto-hive/src/main/java/com/facebook/presto/hive/HiveSessionProperties.java index 9231b1754ba49..0520cc375206f 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/HiveSessionProperties.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/HiveSessionProperties.java @@ -611,7 +611,7 @@ public HiveSessionProperties(HiveClientConfig hiveClientConfig, OrcFileWriterCon false), stringProperty( HUDI_TABLES_USE_MERGED_VIEW, - "For Hudi tables, use merged view to read data", + "For Hudi tables, a comma-separated list in the form of .
which should use merged view to read data", hiveClientConfig.getHudiTablesUseMergedView(), false), booleanProperty( diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/HudiDirectoryLister.java b/presto-hive/src/main/java/com/facebook/presto/hive/HudiDirectoryLister.java index aa8a70644b71e..e05b874449b82 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/HudiDirectoryLister.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/HudiDirectoryLister.java @@ -80,12 +80,22 @@ public HudiDirectoryLister(Configuration conf, ConnectorSession session, Table t .setConf(actualConfig) .setBasePath(table.getStorage().getLocation()) .build(); - this.latestInstant = metaClient.getActiveTimeline() + String latestCompactionInstantTime = metaClient.getActiveTimeline() .getCommitsAndCompactionTimeline() .filterCompletedInstants() - .filter(instant -> !HoodieTableType.MERGE_ON_READ.equals(metaClient.getTableType()) || instant.getAction().equals(HoodieTimeline.COMMIT_ACTION)) + .filter(instant -> HoodieTableType.MERGE_ON_READ.equals(metaClient.getTableType()) && instant.getAction().equals(HoodieTimeline.COMPACTION_ACTION)) .lastInstant() - .map(HoodieInstant::getTimestamp).orElseThrow(() -> new RuntimeException("No active instant found")); + .map(HoodieInstant::getTimestamp).orElse(null); + if (latestCompactionInstantTime != null) { + this.latestInstant = latestCompactionInstantTime; + } + else { + this.latestInstant = metaClient.getActiveTimeline() + .getCommitsTimeline() + .filterCompletedInstants() + .lastInstant() + .map(HoodieInstant::getTimestamp).orElseThrow(() -> new RuntimeException("No active instant found")); + } HoodieEngineContext engineContext = new HoodieLocalEngineContext(actualConfig); HoodieMetadataConfig metadataConfig = HoodieMetadataConfig.newBuilder() .enable(metadataEnabled) diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveClientConfig.java b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveClientConfig.java index 376884f805b7d..78c953e5cfcf9 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveClientConfig.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveClientConfig.java @@ -151,6 +151,7 @@ public void testDefaults() .setUseRecordPageSourceForCustomSplit(true) .setFileSplittable(true) .setHudiMetadataEnabled(false) + .setHudiTablesUseMergedView(null) .setThriftProtocol(Protocol.BINARY) .setThriftBufferSize(new DataSize(128, BYTE)) .setCopyOnFirstWriteConfigurationEnabled(true) @@ -279,6 +280,7 @@ public void testExplicitPropertyMappings() .put("hive.use-record-page-source-for-custom-split", "false") .put("hive.file-splittable", "false") .put("hive.hudi-metadata-enabled", "true") + .put("hive.hudi-tables-use-merged-view", "default.user") .put("hive.internal-communication.thrift-transport-protocol", "COMPACT") .put("hive.internal-communication.thrift-transport-buffer-size", "256B") .put("hive.copy-on-first-write-configuration-enabled", "false") @@ -403,6 +405,7 @@ public void testExplicitPropertyMappings() .setUseRecordPageSourceForCustomSplit(false) .setFileSplittable(false) .setHudiMetadataEnabled(true) + .setHudiTablesUseMergedView("default.user") .setThriftProtocol(Protocol.COMPACT) .setThriftBufferSize(new DataSize(256, BYTE)) .setCopyOnFirstWriteConfigurationEnabled(false)