From f4602b9f4e4c23d62b62509669cd85c3821acfc4 Mon Sep 17 00:00:00 2001 From: Arnav Balyan Date: Thu, 30 Jul 2026 21:42:01 +0530 Subject: [PATCH] update --- .../PaimonObjectInspectorFactory.java | 5 ++ .../PaimonObjectInspectorFactoryTest.java | 71 +++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/objectinspector/PaimonObjectInspectorFactoryTest.java diff --git a/paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/objectinspector/PaimonObjectInspectorFactory.java b/paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/objectinspector/PaimonObjectInspectorFactory.java index 1b81722d000f..09301cfd3230 100644 --- a/paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/objectinspector/PaimonObjectInspectorFactory.java +++ b/paimon-hive/paimon-hive-connector-common/src/main/java/org/apache/paimon/hive/objectinspector/PaimonObjectInspectorFactory.java @@ -24,7 +24,9 @@ import org.apache.paimon.types.DataField; import org.apache.paimon.types.DataType; import org.apache.paimon.types.DecimalType; +import org.apache.paimon.types.IntType; import org.apache.paimon.types.MapType; +import org.apache.paimon.types.MultisetType; import org.apache.paimon.types.RowType; import org.apache.paimon.types.TimeType; import org.apache.paimon.types.VarCharType; @@ -89,6 +91,9 @@ public static ObjectInspector create(DataType logicalType) { case MAP: MapType mapType = (MapType) logicalType; return new PaimonMapObjectInspector(mapType.getKeyType(), mapType.getValueType()); + case MULTISET: + MultisetType multisetType = (MultisetType) logicalType; + return new PaimonMapObjectInspector(multisetType.getElementType(), new IntType()); case ROW: List fieldComments = ((RowType) logicalType) diff --git a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/objectinspector/PaimonObjectInspectorFactoryTest.java b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/objectinspector/PaimonObjectInspectorFactoryTest.java new file mode 100644 index 000000000000..712382279e72 --- /dev/null +++ b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/objectinspector/PaimonObjectInspectorFactoryTest.java @@ -0,0 +1,71 @@ +/* + * 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.hive.objectinspector; + +import org.apache.paimon.data.BinaryString; +import org.apache.paimon.data.GenericMap; +import org.apache.paimon.types.DataTypes; + +import org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector; +import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +/** Tests for {@link PaimonObjectInspectorFactory}. */ +public class PaimonObjectInspectorFactoryTest { + + @Test + public void testCreateMultisetObjectInspector() { + ObjectInspector oi = + PaimonObjectInspectorFactory.create(DataTypes.MULTISET(DataTypes.STRING())); + + assertThat(oi.getCategory()).isEqualTo(ObjectInspector.Category.MAP); + assertThat(oi.getTypeName()).isEqualTo("map"); + + MapObjectInspector mapOi = (MapObjectInspector) oi; + Map javaMap = new HashMap<>(); + javaMap.put(BinaryString.fromString("apple"), 2); + javaMap.put(BinaryString.fromString("banana"), 1); + GenericMap multisetData = new GenericMap(javaMap); + + assertThat(mapOi.getMapSize(multisetData)).isEqualTo(2); + assertThat(mapOi.getMapValueElement(multisetData, BinaryString.fromString("apple"))) + .isEqualTo(2); + assertThat(mapOi.getMapValueElement(multisetData, BinaryString.fromString("banana"))) + .isEqualTo(1); + } + + @Test + public void testCreateRowInspectorContainingMultiset() { + PaimonInternalRowObjectInspector inspector = + new PaimonInternalRowObjectInspector( + Arrays.asList("id", "tags"), + Arrays.asList(DataTypes.INT(), DataTypes.MULTISET(DataTypes.STRING())), + Arrays.asList(null, null)); + + assertThat(inspector.getAllStructFieldRefs()).hasSize(2); + assertThat(inspector.getStructFieldRef("tags").getFieldObjectInspector().getTypeName()) + .isEqualTo("map"); + } +}