From 6e5eb510be733ea92e3c7856fb472eb64ea0d63e Mon Sep 17 00:00:00 2001 From: James Duong Date: Thu, 26 Oct 2023 15:57:42 -0700 Subject: [PATCH] GH-14936: [Java] Remove netty dependency from arrow-vector Change use of IntObjectHashMap to come from Eclipse instead of Netty-common to remove the dependency on Netty from arrow-vector. --- java/vector/pom.xml | 9 +- .../arrow/vector/util/MapWithOrdinalImpl.java | 10 +- .../vector/util/MultiMapWithOrdinal.java | 2 +- .../arrow/vector/util/TestMapWithOrdinal.java | 97 +++++++++++++++++++ 4 files changed, 105 insertions(+), 13 deletions(-) create mode 100644 java/vector/src/test/java/org/apache/arrow/vector/util/TestMapWithOrdinal.java diff --git a/java/vector/pom.xml b/java/vector/pom.xml index 015d089e9d028..98d7e02126a98 100644 --- a/java/vector/pom.xml +++ b/java/vector/pom.xml @@ -61,10 +61,6 @@ arrow-memory-unsafe test - - io.netty - netty-common - com.google.flatbuffers flatbuffers-java @@ -74,6 +70,11 @@ org.slf4j slf4j-api + + org.eclipse.collections + eclipse-collections + 11.1.0 + diff --git a/java/vector/src/main/java/org/apache/arrow/vector/util/MapWithOrdinalImpl.java b/java/vector/src/main/java/org/apache/arrow/vector/util/MapWithOrdinalImpl.java index 3612d677ed5a9..7c9c0e9408860 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/util/MapWithOrdinalImpl.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/util/MapWithOrdinalImpl.java @@ -25,15 +25,11 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import java.util.stream.StreamSupport; -import org.apache.arrow.util.Preconditions; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.netty.util.collection.IntObjectHashMap; -import io.netty.util.collection.IntObjectMap; - /** * An implementation of map that supports constant time look-up by a generic key or an ordinal. * @@ -133,9 +129,7 @@ public Set keySet() { @Override public Collection values() { - return StreamSupport.stream(secondary.entries().spliterator(), false) - .map((IntObjectMap.PrimitiveEntry t) -> Preconditions.checkNotNull(t).value()) - .collect(Collectors.toList()); + return secondary.values(); } @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/util/MultiMapWithOrdinal.java b/java/vector/src/main/java/org/apache/arrow/vector/util/MultiMapWithOrdinal.java index 5fbb45a7ac6ac..f722a8a86772c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/util/MultiMapWithOrdinal.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/util/MultiMapWithOrdinal.java @@ -25,7 +25,7 @@ import java.util.Set; import java.util.stream.Collectors; -import io.netty.util.collection.IntObjectHashMap; +import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; /** * An implementation of a multimap that supports constant time look-up by a generic key or an ordinal. diff --git a/java/vector/src/test/java/org/apache/arrow/vector/util/TestMapWithOrdinal.java b/java/vector/src/test/java/org/apache/arrow/vector/util/TestMapWithOrdinal.java new file mode 100644 index 0000000000000..edd5221faf268 --- /dev/null +++ b/java/vector/src/test/java/org/apache/arrow/vector/util/TestMapWithOrdinal.java @@ -0,0 +1,97 @@ +/* + * 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.arrow.vector.util; + +import static junit.framework.TestCase.assertNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Collection; + +import org.junit.Before; +import org.junit.Test; + +public class TestMapWithOrdinal { + + private MapWithOrdinal map; + + @Before + public void setUp() { + map = new MapWithOrdinalImpl<>(); + } + + @Test + public void testGetByOrdinal() { + map.put("key0", "val0", true); + assertEquals("val0", map.getByOrdinal(0)); + + map.put("key1", "val1", true); + assertEquals("val1", map.getByOrdinal(1)); + assertEquals("val0", map.getByOrdinal(0)); + } + + @Test + public void testGetByKey() { + map.put("key0", "val0", true); + assertEquals("val0", map.get("key0")); + + map.put("key1", "val1", true); + assertEquals("val1", map.get("key1")); + assertEquals("val0", map.get("key0")); + } + + @Test + public void testInvalidOrdinal() { + map.put("key0", "val0", true); + assertNull(map.getByOrdinal(1)); + + map.removeAll("key0"); + assertNull(map.getByOrdinal(0)); + } + + @Test + public void testInvalidKey() { + MapWithOrdinalImpl map = new MapWithOrdinalImpl<>(); + map.put("key0", "val0", true); + assertNull(map.get("fake_key")); + + map.removeAll("key0"); + assertNull(map.get("key0")); + } + + @Test + public void testValues() { + map.put("key0", "val0", true); + map.put("key1", "val1", true); + + Collection values = map.values(); + assertTrue(values.contains("val0")); + assertTrue(values.contains("val1")); + + map.put("key1", "new_val1", true); + values = map.values(); + assertTrue(values.contains("val0")); + assertTrue(values.contains("new_val1")); + assertFalse(values.contains("val1")); + + map.removeAll("key0"); + assertTrue(values.contains("new_val1")); + assertFalse(values.contains("val0")); + } +}