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

rui-mo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new ac318c33c2 [GLUTEN-13698][CORE] Build the file schema once per split 
in LocalFilesNode (#13699)
ac318c33c2 is described below

commit ac318c33c25f47a9c67d73711cc4da350e4b792b
Author: YangJie <[email protected]>
AuthorDate: Mon Nov 23 14:01:23 2026 -0500

    [GLUTEN-13698][CORE] Build the file schema once per split in LocalFilesNode 
(#13699)
---
 .../gluten/substrait/rel/LocalFilesNode.java       |  8 ++-
 .../gluten/substrait/rel/LocalFilesNodeSuite.scala | 69 ++++++++++++++++++++++
 2 files changed, 74 insertions(+), 3 deletions(-)

diff --git 
a/gluten-substrait/src/main/java/org/apache/gluten/substrait/rel/LocalFilesNode.java
 
b/gluten-substrait/src/main/java/org/apache/gluten/substrait/rel/LocalFilesNode.java
index 3179896985..5d47a3ab50 100644
--- 
a/gluten-substrait/src/main/java/org/apache/gluten/substrait/rel/LocalFilesNode.java
+++ 
b/gluten-substrait/src/main/java/org/apache/gluten/substrait/rel/LocalFilesNode.java
@@ -201,6 +201,9 @@ public class LocalFilesNode implements SplitInfo {
     if (paths.size() != starts.size() || paths.size() != lengths.size()) {
       throw new RuntimeException("Invalid parameters.");
     }
+    // Every file in the split has the same schema, so build it once.
+    final NamedStruct fileNamedStruct =
+        fileSchema != null && !paths.isEmpty() ? buildNamedStruct() : null;
     for (int i = 0; i < paths.size(); i++) {
       ReadRel.LocalFiles.FileOrFiles.Builder fileBuilder =
           ReadRel.LocalFiles.FileOrFiles.newBuilder();
@@ -249,9 +252,8 @@ public class LocalFilesNode implements SplitInfo {
         fileBuilder.addMetadataColumns(mcBuilder.build());
       }
 
-      if (fileSchema != null) {
-        NamedStruct namedStruct = buildNamedStruct();
-        fileBuilder.setSchema(namedStruct);
+      if (fileNamedStruct != null) {
+        fileBuilder.setSchema(fileNamedStruct);
       }
 
       if (!otherMetadataColumns.isEmpty()) {
diff --git 
a/gluten-substrait/src/test/scala/org/apache/gluten/substrait/rel/LocalFilesNodeSuite.scala
 
b/gluten-substrait/src/test/scala/org/apache/gluten/substrait/rel/LocalFilesNodeSuite.scala
new file mode 100644
index 0000000000..4794fa3316
--- /dev/null
+++ 
b/gluten-substrait/src/test/scala/org/apache/gluten/substrait/rel/LocalFilesNodeSuite.scala
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.substrait.rel
+
+import org.apache.spark.sql.types.{LongType, StringType, StructField, 
StructType}
+
+import io.substrait.proto.Type
+import org.scalatest.funsuite.AnyFunSuite
+
+import java.util.{Collections, Map => JMap}
+
+import scala.collection.JavaConverters._
+
+class LocalFilesNodeSuite extends AnyFunSuite {
+
+  private def orcSplit(numFiles: Int): LocalFilesNode = {
+    LocalFilesBuilder.makeLocalFiles(
+      Integer.valueOf(0),
+      (0 until numFiles).map(i => s"file:///tmp/part-$i.orc").asJava,
+      Collections.nCopies(numFiles, java.lang.Long.valueOf(0L)),
+      Collections.nCopies(numFiles, java.lang.Long.valueOf(100L)),
+      Collections.emptyList[java.lang.Long](),
+      Collections.emptyList[java.lang.Long](),
+      Collections.nCopies[JMap[String, String]](numFiles, 
Collections.emptyMap[String, String]()),
+      Collections.emptyList[JMap[String, String]](),
+      LocalFilesNode.ReadFileFormat.OrcReadFormat,
+      Collections.emptyList[String](),
+      Collections.emptyMap[String, String](),
+      Collections.emptyList[JMap[String, Object]]()
+    )
+  }
+
+  test("every file of a split carries the file schema") {
+    val node = orcSplit(3)
+    node.setFileSchema(
+      StructType(Seq(StructField("Id", LongType), StructField("name", 
StringType, false))))
+
+    val items = node.toProtobuf.getItemsList.asScala
+    assert(items.size == 3)
+    items.foreach {
+      item =>
+        assert(item.hasSchema)
+        val schema = item.getSchema
+        assert(schema.getNamesList.asScala == Seq("id", "name"))
+        val types = schema.getStruct.getTypesList.asScala
+        assert(types.map(_.getKindCase) == Seq(Type.KindCase.I64, 
Type.KindCase.STRING))
+        assert(types(0).getI64.getNullability == 
Type.Nullability.NULLABILITY_NULLABLE)
+        assert(types(1).getString.getNullability == 
Type.Nullability.NULLABILITY_REQUIRED)
+    }
+  }
+
+  test("no file schema is emitted when none is set") {
+    assert(orcSplit(2).toProtobuf.getItemsList.asScala.forall(!_.hasSchema))
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to