Skip to content

Commit 3c4c2ee

Browse files
committed
[SPARK-53240][SQL] Ban com.google.common.collect.(ArrayList)?Multimap
### What changes were proposed in this pull request? This PR aims to ban `com.google.common.collect.Multimap` and `com.google.common.collect.ArrayListMultimap` because we use very primitive usage with only two elements. We can simply do this like the following in native Java way. ```java - private final Multimap<String, String> clientToHiveMap = ArrayListMultimap.create(); + private final Map<String, List<String>> clientToHiveMap = new HashMap<>(); ``` ```java - clientToHiveMap.putAll(ClassicTableTypes.TABLE.name(), - Arrays.asList(TableType.MANAGED_TABLE.name(), TableType.EXTERNAL_TABLE.name())); + clientToHiveMap.put(ClassicTableTypes.TABLE.name(), + List.of(TableType.MANAGED_TABLE.name(), TableType.EXTERNAL_TABLE.name())); ``` ### Why are the changes needed? To simplify the code. ### Does this PR introduce _any_ user-facing change? No behavior change. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #51967 from dongjoon-hyun/SPARK-53240. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
1 parent d2dc055 commit 3c4c2ee

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

dev/checkstyle.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@
193193
<property name="illegalClasses" value="org.apache.hadoop.io.IOUtils" />
194194
<property name="illegalClasses" value="com.google.common.base.Objects" />
195195
<property name="illegalClasses" value="com.google.common.base.Strings" />
196+
<property name="illegalClasses" value="com.google.common.collect.ArrayListMultimap" />
197+
<property name="illegalClasses" value="com.google.common.collect.Multimap" />
196198
<property name="illegalClasses" value="com.google.common.collect.Sets" />
197199
<property name="illegalClasses" value="com.google.common.io.BaseEncoding" />
198200
<property name="illegalClasses" value="com.google.common.io.Files" />

sql/hive-thriftserver/src/main/java/org/apache/hive/service/cli/operation/ClassicTableTypeMapping.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717

1818
package org.apache.hive.service.cli.operation;
1919

20-
import java.util.Arrays;
21-
import java.util.Collection;
2220
import java.util.HashMap;
2321
import java.util.HashSet;
22+
import java.util.List;
2423
import java.util.Map;
2524
import java.util.Set;
2625

27-
import com.google.common.collect.ArrayListMultimap;
28-
import com.google.common.collect.Iterables;
29-
import com.google.common.collect.Multimap;
3026
import org.apache.hadoop.hive.metastore.TableType;
3127

3228
import org.apache.spark.internal.SparkLogger;
@@ -52,7 +48,7 @@ public enum ClassicTableTypes {
5248
}
5349

5450
private final Map<String, String> hiveToClientMap = new HashMap<String, String>();
55-
private final Multimap<String, String> clientToHiveMap = ArrayListMultimap.create();
51+
private final Map<String, List<String>> clientToHiveMap = new HashMap<>();
5652

5753
public ClassicTableTypeMapping() {
5854
hiveToClientMap.put(TableType.MANAGED_TABLE.name(), ClassicTableTypes.TABLE.name());
@@ -61,22 +57,23 @@ public ClassicTableTypeMapping() {
6157
hiveToClientMap.put(TableType.MATERIALIZED_VIEW.toString(),
6258
ClassicTableTypes.MATERIALIZED_VIEW.toString());
6359

64-
clientToHiveMap.putAll(ClassicTableTypes.TABLE.name(), Arrays.asList(
65-
TableType.MANAGED_TABLE.name(), TableType.EXTERNAL_TABLE.name()));
66-
clientToHiveMap.put(ClassicTableTypes.VIEW.name(), TableType.VIRTUAL_VIEW.name());
60+
clientToHiveMap.put(ClassicTableTypes.TABLE.name(),
61+
List.of(TableType.MANAGED_TABLE.name(), TableType.EXTERNAL_TABLE.name()));
62+
clientToHiveMap.put(ClassicTableTypes.VIEW.name(),
63+
List.of(TableType.VIRTUAL_VIEW.name()));
6764
clientToHiveMap.put(ClassicTableTypes.MATERIALIZED_VIEW.toString(),
68-
TableType.MATERIALIZED_VIEW.toString());
65+
List.of(TableType.MATERIALIZED_VIEW.toString()));
6966
}
7067

7168
@Override
7269
public String[] mapToHiveType(String clientTypeName) {
73-
Collection<String> hiveTableType = clientToHiveMap.get(clientTypeName.toUpperCase());
70+
List<String> hiveTableType = clientToHiveMap.get(clientTypeName.toUpperCase());
7471
if (hiveTableType == null) {
7572
LOG.warn("Not supported client table type {}",
7673
MDC.of(LogKeys.TABLE_TYPE, clientTypeName));
7774
return new String[] {clientTypeName};
7875
}
79-
return Iterables.toArray(hiveTableType, String.class);
76+
return hiveTableType.toArray(new String[0]);
8077
}
8178

8279
@Override

0 commit comments

Comments
 (0)