This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new f1466945ff [common] Default missing variant shredding fields to the
unshredded index (#9616)
f1466945ff is described below
commit f1466945ffb4e04d56a49e3767a865bfe2b38b34
Author: YangJie <[email protected]>
AuthorDate: Thu Sep 10 02:31:09 2026 -0400
[common] Default missing variant shredding fields to the unshredded index
(#9616)
---
.../paimon/data/variant/BaseVariantReader.java | 5 +-
.../paimon/data/variant/BaseVariantReaderTest.java | 66 ++++++++++++++++++++++
2 files changed, 70 insertions(+), 1 deletion(-)
diff --git
a/paimon-common/src/main/java/org/apache/paimon/data/variant/BaseVariantReader.java
b/paimon-common/src/main/java/org/apache/paimon/data/variant/BaseVariantReader.java
index 9b7a7dd5fc..ce3c4036aa 100644
---
a/paimon-common/src/main/java/org/apache/paimon/data/variant/BaseVariantReader.java
+++
b/paimon-common/src/main/java/org/apache/paimon/data/variant/BaseVariantReader.java
@@ -195,9 +195,12 @@ public class BaseVariantReader {
List<DataField> targetFields = targetType.getFields();
this.fieldInputIndices = new int[targetFields.size()];
for (int i = 0; i < targetFields.size(); i++) {
+ // A target field may live in the untyped value under partial
shredding;
+ // Map.get returns null for it and unboxing would NPE.
fieldInputIndices[i] =
schema.objectSchemaMap != null
- ?
schema.objectSchemaMap.get(targetFields.get(i).name())
+ ? schema.objectSchemaMap.getOrDefault(
+ targetFields.get(i).name(), -1)
: -1;
}
diff --git
a/paimon-common/src/test/java/org/apache/paimon/data/variant/BaseVariantReaderTest.java
b/paimon-common/src/test/java/org/apache/paimon/data/variant/BaseVariantReaderTest.java
new file mode 100644
index 0000000000..e3f0b558bf
--- /dev/null
+++
b/paimon-common/src/test/java/org/apache/paimon/data/variant/BaseVariantReaderTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.paimon.data.variant;
+
+import org.apache.paimon.data.BinaryString;
+import org.apache.paimon.data.GenericRow;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.types.DataType;
+import org.apache.paimon.types.DataTypes;
+import org.apache.paimon.types.RowType;
+
+import org.junit.jupiter.api.Test;
+
+import java.time.ZoneOffset;
+
+import static
org.apache.paimon.data.variant.PaimonShreddingUtils.buildVariantSchema;
+import static org.apache.paimon.data.variant.PaimonShreddingUtils.castShredded;
+import static
org.apache.paimon.data.variant.PaimonShreddingUtils.variantShreddingSchema;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Test for {@link BaseVariantReader}. */
+public class BaseVariantReaderTest {
+
+ @Test
+ void testRowReaderWithUnshreddedTargetField() {
+ VariantCastArgs castArgs = new VariantCastArgs(true, ZoneOffset.UTC);
+
+ // The file shreds only field "a" of the object, so a target asking
for "b" as well
+ // has to pick "b" up from the untyped value.
+ RowType shreddedType = RowType.of(new DataType[] {DataTypes.INT()},
new String[] {"a"});
+ VariantSchema schema =
buildVariantSchema(variantShreddingSchema(shreddedType));
+
assertThat(schema.objectSchemaMap).containsKey("a").doesNotContainKey("b");
+
+ RowType targetType =
+ RowType.of(
+ new DataType[] {DataTypes.INT(), DataTypes.STRING()},
+ new String[] {"a", "b"});
+ BaseVariantReader reader = BaseVariantReader.create(schema,
targetType, castArgs, false);
+
+ InternalRow shredded =
+ castShredded(GenericVariant.fromJson("{\"a\": 1, \"b\":
\"hello\"}"), schema);
+ assertThat(reader.read(shredded,
shredded.getBinary(schema.topLevelMetadataIdx)))
+ .isEqualTo(GenericRow.of(1, BinaryString.fromString("hello")));
+
+ // "b" absent from both the shredded object and the untyped value
reads back as null.
+ shredded = castShredded(GenericVariant.fromJson("{\"a\": 27}"),
schema);
+ assertThat(reader.read(shredded,
shredded.getBinary(schema.topLevelMetadataIdx)))
+ .isEqualTo(GenericRow.of(27, null));
+ }
+}