This is an automated email from the ASF dual-hosted git repository.
wlo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/gobblin.git
The following commit(s) were added to refs/heads/master by this push:
new e47aef7f8 [GOBBLIN-1826] Change isAssignableFrom() to isSuperTypeOf()
per Guava 20 javadocs to… (#3688)
e47aef7f8 is described below
commit e47aef7f8eeba3b6d52901cab299048a467eaf24
Author: William Lo <[email protected]>
AuthorDate: Thu Apr 27 14:09:42 2023 -0400
[GOBBLIN-1826] Change isAssignableFrom() to isSuperTypeOf() per Guava 20
javadocs to… (#3688)
* Change isAssignableFrom() to isSuperTypeOf() per Guava 20 javadocs to fix
bug in Hive registration where classes can escape type casts
* Fix checkstyle
---
.../apache/gobblin/hive/HiveRegistrationUnit.java | 9 ++--
.../org/apache/gobblin/hive/HiveTableTest.java | 61 ++++++++++++++++++++++
2 files changed, 65 insertions(+), 5 deletions(-)
diff --git
a/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveRegistrationUnit.java
b/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveRegistrationUnit.java
index 841d4161d..8e06eda65 100644
---
a/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveRegistrationUnit.java
+++
b/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveRegistrationUnit.java
@@ -125,14 +125,13 @@ public class HiveRegistrationUnit {
protected static <T> Optional<T> populateField(State state, String key,
TypeToken<T> token) {
if (state.contains(key)) {
Optional<T> fieldValue;
-
- if (new TypeToken<Boolean>()
{}.getRawType().isAssignableFrom(token.getClass())) {
+ if (new TypeToken<Boolean>(){}.isSupertypeOf(token)) {
fieldValue = (Optional<T>) Optional.of(state.getPropAsBoolean(key));
- } else if (new TypeToken<Integer>()
{}.getRawType().isAssignableFrom(token.getClass())) {
+ } else if (new TypeToken<Integer>(){}.isSupertypeOf(token)) {
fieldValue = (Optional<T>) Optional.of(state.getPropAsInt(key));
- } else if (new TypeToken<Long>()
{}.getRawType().isAssignableFrom(token.getClass())) {
+ } else if (new TypeToken<Long>(){}.isSupertypeOf(token)) {
fieldValue = (Optional<T>) Optional.of(state.getPropAsLong(key));
- } else if (new TypeToken<List<String>>()
{}.getRawType().isAssignableFrom(token.getClass())) {
+ } else if (new TypeToken<List<String>>(){}.isSupertypeOf(token)) {
fieldValue = (Optional<T>) Optional.of(state.getPropAsList(key));
} else {
fieldValue = (Optional<T>) Optional.of(state.getProp(key));
diff --git
a/gobblin-hive-registration/src/test/java/org/apache/gobblin/hive/HiveTableTest.java
b/gobblin-hive-registration/src/test/java/org/apache/gobblin/hive/HiveTableTest.java
new file mode 100644
index 000000000..68b9bad9c
--- /dev/null
+++
b/gobblin-hive-registration/src/test/java/org/apache/gobblin/hive/HiveTableTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.gobblin.hive;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.annotations.Test;
+
+import junit.framework.Assert;
+
+import org.apache.gobblin.configuration.State;
+
+public class HiveTableTest {
+
+ @Test
+ public void testPopulateFieldTypeCasting() throws Exception {
+ // Test one property of each type in HiveRegistrationUnit storageProps
+
+ State props = new State();
+ Long lastAccessTime = System.currentTimeMillis();
+ props.setProp(HiveConstants.LAST_ACCESS_TIME,
String.valueOf(lastAccessTime));
+ State storageProps = new State();
+ storageProps.setProp(HiveConstants.LOCATION, "/tmp");
+ storageProps.setProp(HiveConstants.COMPRESSED, "false");
+ storageProps.setProp(HiveConstants.NUM_BUCKETS, "1");
+ storageProps.setProp(HiveConstants.BUCKET_COLUMNS, "col1, col2");
+ HiveTable.Builder builder = new HiveTable.Builder();
+ builder.withTableName("tableName");
+ builder.withDbName("dbName");
+ builder.withProps(props);
+ builder.withStorageProps(storageProps);
+
+ HiveTable hiveTable = builder.build();
+
+ Assert.assertEquals(hiveTable.getLastAccessTime().get().longValue(),
lastAccessTime.longValue());
+ Assert.assertEquals(hiveTable.getLocation().get(), "/tmp");
+ Assert.assertEquals(hiveTable.isCompressed.get().booleanValue(), false);
+ Assert.assertEquals(hiveTable.getNumBuckets().get().intValue(), 1);
+ List<String> bucketColumns = new ArrayList<>();
+ bucketColumns.add("col1");
+ bucketColumns.add("col2");
+ Assert.assertEquals(hiveTable.getBucketColumns().get().get(0),
bucketColumns.get(0));
+ Assert.assertEquals(hiveTable.getBucketColumns().get().get(1),
bucketColumns.get(1));
+ }
+}