This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/master/pr-20645-e4c229dab66ecfc7f7a51dd114482f9d0c09c674
in repository https://gitbox.apache.org/repos/asf/hudi.git

commit 4add869563117e5e3c048c0a27939c05bce2282a
Author: Alexander Narsudinov <[email protected]>
AuthorDate: Mon Nov 23 04:57:06 2026 +0000

    fix(trino): skip log-only file groups in read-optimized scans (#20645)
    
    Trino treats merge-on-read tables exposed through the read-optimized
    input format as COPY_ON_WRITE. A log-only file group then reaches the
    base-file split builder and fails its base-file precondition.
    
    Skip log-only groups during read-optimized planning and retain them
    for merge-on-read snapshot scans.
    
    Cover both planning modes in TestHudiSplitFactory. In TestHudiSmokeTest,
    add a synthetic log to stock_ticks_mor and verify that the read-optimized
    row count stays at 99. Hold the query runner's exclusive lock until the
    synthetic log is removed.
    
    All 85 tests passed in a local JUnit run with Trino 483 and Hudi 1.2.1
    dependencies, using the Trino 483 Alluxio setup in a temporary copy of
    the smoke test. Both regression tests reproduced the base-file failure
    with the previous split factory.
---
 .../trino/plugin/hudi/split/HudiSplitFactory.java  |  3 +
 .../io/trino/plugin/hudi/TestHudiSmokeTest.java    | 64 +++++++++++++++++++++-
 .../plugin/hudi/split/TestHudiSplitFactory.java    | 28 ++++++++--
 3 files changed, 88 insertions(+), 7 deletions(-)

diff --git 
a/hudi-trino/src/main/java/io/trino/plugin/hudi/split/HudiSplitFactory.java 
b/hudi-trino/src/main/java/io/trino/plugin/hudi/split/HudiSplitFactory.java
index ece6472473c0..72a28356cb0e 100644
--- a/hudi-trino/src/main/java/io/trino/plugin/hudi/split/HudiSplitFactory.java
+++ b/hudi-trino/src/main/java/io/trino/plugin/hudi/split/HudiSplitFactory.java
@@ -82,6 +82,9 @@ public class HudiSplitFactory
         if (isCopyOnWriteOrReadOptimized(hudiTableHandle, fileSlice)) {
             // Handle MERGE_ON_READ tables to be read in read_optimized mode
             // IMPORTANT: These tables will have a COPY_ON_WRITE table type 
due to how `HudiTableTypeUtils#fromInputFormat`
+            if (fileSlice.getBaseFile().isEmpty()) {
+                return ImmutableList.of();
+            }
             return createSplitsForBaseFile(hudiTableHandle, partitionKeys, 
fileSlice, commitTime, hudiSplitWeightProvider, targetSplitSize);
         }
         return createSplitForMergeOnRead(hudiTableHandle, partitionKeys, 
fileSlice, commitTime, hudiSplitWeightProvider);
diff --git 
a/hudi-trino/src/test/java/io/trino/plugin/hudi/TestHudiSmokeTest.java 
b/hudi-trino/src/test/java/io/trino/plugin/hudi/TestHudiSmokeTest.java
index 70da4b1249cd..e93c08f0eede 100644
--- a/hudi-trino/src/test/java/io/trino/plugin/hudi/TestHudiSmokeTest.java
+++ b/hudi-trino/src/test/java/io/trino/plugin/hudi/TestHudiSmokeTest.java
@@ -19,9 +19,11 @@ import com.google.common.io.Resources;
 import io.trino.Session;
 import io.trino.blob.cache.alluxio.AlluxioBlobCachePlugin;
 import io.trino.filesystem.Location;
+import io.trino.filesystem.TrinoFileSystem;
 import io.trino.filesystem.TrinoFileSystemFactory;
 import io.trino.filesystem.TrinoInputFile;
 import io.trino.filesystem.local.LocalInputFile;
+import io.trino.metastore.HiveMetastoreFactory;
 import io.trino.parquet.ParquetReaderOptions;
 import io.trino.plugin.base.metrics.FileFormatDataSourceStats;
 import io.trino.plugin.hive.HiveTimestampPrecision;
@@ -43,6 +45,7 @@ import io.trino.testing.MaterializedResult;
 import io.trino.testing.MaterializedRow;
 import io.trino.testing.QueryRunner;
 import io.trino.testing.TestingConnectorSession;
+import org.apache.hudi.common.table.HoodieTableMetaClient;
 import org.apache.hudi.common.table.HoodieTableVersion;
 import org.apache.hudi.common.util.Option;
 import org.intellij.lang.annotations.Language;
@@ -57,6 +60,7 @@ import org.junit.jupiter.params.provider.MethodSource;
 import org.junit.jupiter.params.provider.ValueSource;
 
 import java.io.File;
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.time.ZonedDateTime;
 import java.util.Iterator;
@@ -64,12 +68,14 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.OptionalLong;
+import java.util.concurrent.locks.Lock;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
 
+import static com.google.common.collect.Iterables.getOnlyElement;
 import static io.trino.metastore.HiveType.HIVE_TIMESTAMP;
 import static io.trino.plugin.hive.HiveColumnHandle.ColumnType.REGULAR;
 import static io.trino.plugin.hive.HiveColumnHandle.createBaseColumn;
@@ -162,6 +168,49 @@ public class TestHudiSmokeTest
                 "SELECT * FROM VALUES ('2018-08-31', '99')");
     }
 
+    @Test
+    public void testReadOptimizedSkipsLogOnlyFileGroup()
+            throws IOException
+    {
+        Session session = SessionBuilder.from(getSession())
+                .withMdtEnabled(false)
+                .withTableStatisticsEnabled(false)
+                .withResolveColumnNameCasingEnabled(false)
+                .build();
+        String schemaName = session.getSchema().orElseThrow();
+        String tableName = STOCK_TICKS_MOR.getTableName();
+        String query = "SELECT count(*) FROM " + tableName;
+        String basePath = hudiConnector().getInjector()
+                .getInstance(HiveMetastoreFactory.class)
+                .createMetastore(Optional.empty())
+                .getTable(schemaName, tableName).orElseThrow()
+                .getStorage().getLocation();
+
+        TrinoFileSystem fileSystem = fileSystem();
+        HoodieTableMetaClient metaClient = 
HudiUtil.buildTableMetaClient(fileSystem, schemaName + "." + tableName, 
basePath);
+        String commit = 
metaClient.getActiveTimeline().getCommitsTimeline().filterCompletedInstants().lastInstant().get().requestedTime();
+        Location partition = 
Location.of(basePath).appendPath(getOnlyElement(STOCK_TICKS_MOR.getPartitions().values()));
+        Location log = partition.appendPath(".logonly_" + commit + 
".log.1_0-0-0");
+
+        // Keep the temporary file out of other queries that use this fixture.
+        Lock lock = getQueryRunner().getExclusiveLock();
+        lock.lock();
+        try {
+            assertThat(computeScalar(session, query)).isEqualTo(99L);
+            try {
+                // Read-optimized planning skips the file group before it 
opens the synthetic log.
+                fileSystem.newOutputFile(log).createOrOverwrite(new byte[100]);
+                assertThat(computeScalar(session, query)).isEqualTo(99L);
+            }
+            finally {
+                fileSystem.deleteFile(log);
+            }
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
     @Test
     public void testReadNonExtractablePartitionPathTable()
     {
@@ -1441,10 +1490,19 @@ public class TestHudiSmokeTest
 
     private TrinoInputFile toInputFile(String path)
     {
-        return ((HudiConnector) 
getDistributedQueryRunner().getCoordinator().getConnector("hudi")).getInjector()
+        return fileSystem().newInputFile(Location.of(path));
+    }
+
+    private TrinoFileSystem fileSystem()
+    {
+        return hudiConnector().getInjector()
                 .getInstance(TrinoFileSystemFactory.class)
-                .create(ConnectorIdentity.ofUser("test"))
-                .newInputFile(Location.of(path));
+                .create(ConnectorIdentity.ofUser("test"));
+    }
+
+    private HudiConnector hudiConnector()
+    {
+        return (HudiConnector) 
getDistributedQueryRunner().getCoordinator().getConnector("hudi");
     }
 
     public static <K, V> Map<K, V> listsToMap(List<K> keys, List<V> values)
diff --git 
a/hudi-trino/src/test/java/io/trino/plugin/hudi/split/TestHudiSplitFactory.java 
b/hudi-trino/src/test/java/io/trino/plugin/hudi/split/TestHudiSplitFactory.java
index 067c0f7b3dbd..5b17ee371593 100644
--- 
a/hudi-trino/src/test/java/io/trino/plugin/hudi/split/TestHudiSplitFactory.java
+++ 
b/hudi-trino/src/test/java/io/trino/plugin/hudi/split/TestHudiSplitFactory.java
@@ -154,7 +154,7 @@ public class TestHudiSplitFactory
         // A zero target split size must be rejected on construction, before 
any file slice is seen,
         // instead of looping forever once split generation reaches a 
non-empty base file
         assertThatThrownBy(() -> new HudiSplitFactory(
-                createTableHandle(),
+                createTableHandle(HoodieTableType.MERGE_ON_READ),
                 new SizeBasedSplitWeightProvider(0.05, DataSize.of(128, 
MEGABYTE)),
                 DataSize.ofBytes(0)))
                 .isInstanceOf(IllegalArgumentException.class)
@@ -174,6 +174,26 @@ public class TestHudiSplitFactory
                         Pair.of(0L, DataSize.of(65, MEGABYTE))));
     }
 
+    @Test
+    public void testReadOptimizedSkipsLogOnlyFileGroup()
+    {
+        FileSlice slice = new FileSlice("partition", COMMIT_TIME, "log-only");
+        slice.addLogFile(new HoodieLogFile(new StoragePathInfo(
+                new StoragePath("/test/path/.log-only_" + COMMIT_TIME + 
".log.1_0-0-0"), 100, false, (short) 0, 100, 1)));
+        HudiSplitWeightProvider weightProvider = 
HudiSplitWeightProvider.uniformStandardWeightProvider();
+        DataSize targetSplitSize = DataSize.of(128, MEGABYTE);
+
+        assertThat(new 
HudiSplitFactory(createTableHandle(HoodieTableType.COPY_ON_WRITE), 
weightProvider, targetSplitSize)
+                .createSplits(PARTITION_KEYS, slice, COMMIT_TIME)).isEmpty();
+
+        assertThat(new 
HudiSplitFactory(createTableHandle(HoodieTableType.MERGE_ON_READ), 
weightProvider, targetSplitSize)
+                .createSplits(PARTITION_KEYS, slice, COMMIT_TIME))
+                .singleElement().satisfies(split -> {
+                    assertThat(split.getBaseFile()).isEmpty();
+                    assertThat(split.getLogFiles()).hasSize(1);
+                });
+    }
+
     @Test
     public void testCreateHudiSplitsWithZeroSizeFile()
     {
@@ -191,7 +211,7 @@ public class TestHudiSplitFactory
             Option<DataSize> logFileSize,
             List<Pair<Long, DataSize>> expectedSplitInfo)
     {
-        HudiTableHandle tableHandle = createTableHandle();
+        HudiTableHandle tableHandle = 
createTableHandle(HoodieTableType.MERGE_ON_READ);
         HudiSplitWeightProvider weightProvider = new 
SizeBasedSplitWeightProvider(0.05, DataSize.of(128, MEGABYTE));
 
         FileSlice fileSlice = createFileSlice(baseFileSize, logFileSize);
@@ -217,13 +237,13 @@ public class TestHudiSplitFactory
         }
     }
 
-    private static HudiTableHandle createTableHandle()
+    private static HudiTableHandle createTableHandle(HoodieTableType tableType)
     {
         return new HudiTableHandle(
                 "test_schema",
                 "test_table",
                 "/test/path",
-                HoodieTableType.MERGE_ON_READ,
+                tableType,
                 ImmutableList.of(),
                 ImmutableList.of(),
                 TupleDomain.all(),

Reply via email to