This is an automated email from the ASF dual-hosted git repository.
danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 9ac06ec5f8e [HUDI-7213] When using wrong tabe.type value in hudi
catalog happends npe (#10300)
9ac06ec5f8e is described below
commit 9ac06ec5f8ebde698e411f212698e3671bd3d82e
Author: leixin <[email protected]>
AuthorDate: Thu Dec 21 10:07:54 2023 +0800
[HUDI-7213] When using wrong tabe.type value in hudi catalog happends npe
(#10300)
---
.../org/apache/hudi/table/catalog/TableOptionProperties.java | 12 +++++++++++-
.../org/apache/hudi/table/catalog/TestHoodieHiveCatalog.java | 10 ++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git
a/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/catalog/TableOptionProperties.java
b/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/catalog/TableOptionProperties.java
index 6e327bdc612..8f3e88417be 100644
---
a/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/catalog/TableOptionProperties.java
+++
b/hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/catalog/TableOptionProperties.java
@@ -24,6 +24,7 @@ import org.apache.hudi.common.model.HoodieTableType;
import org.apache.hudi.common.table.TableSchemaResolver;
import org.apache.hudi.configuration.FlinkOptions;
import org.apache.hudi.exception.HoodieIOException;
+import org.apache.hudi.exception.HoodieValidationException;
import org.apache.hudi.sync.common.util.SparkDataSourceTableUtils;
import org.apache.hudi.util.AvroSchemaConverter;
@@ -189,7 +190,16 @@ public class TableOptionProperties {
return properties.entrySet().stream()
.filter(e -> KEY_MAPPING.containsKey(e.getKey()) &&
!catalogTable.getOptions().containsKey(KEY_MAPPING.get(e.getKey())))
.collect(Collectors.toMap(e -> KEY_MAPPING.get(e.getKey()),
- e -> e.getKey().equalsIgnoreCase(FlinkOptions.TABLE_TYPE.key()) ?
VALUE_MAPPING.get(e.getValue()) : e.getValue()));
+ e -> {
+ if (e.getKey().equalsIgnoreCase(FlinkOptions.TABLE_TYPE.key())) {
+ String sparkTableType = VALUE_MAPPING.get(e.getValue());
+ if (sparkTableType == null) {
+ throw new HoodieValidationException(String.format("%s's
value is invalid", e.getKey()));
+ }
+ return sparkTableType;
+ }
+ return e.getValue();
+ }));
}
private static RowType supplementMetaFields(RowType rowType, boolean
withOperationField) {
diff --git
a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/catalog/TestHoodieHiveCatalog.java
b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/catalog/TestHoodieHiveCatalog.java
index af1549498ed..8af557c4b64 100644
---
a/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/catalog/TestHoodieHiveCatalog.java
+++
b/hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/table/catalog/TestHoodieHiveCatalog.java
@@ -270,6 +270,16 @@ public class TestHoodieHiveCatalog {
}
}
+ @Test
+ public void testCreateHoodieTableWithWrongTableType() {
+ HashMap<String,String> properties = new HashMap<>();
+ properties.put(FactoryUtil.CONNECTOR.key(), "hudi");
+ properties.put("table.type","wrong type");
+ CatalogTable table =
+ new CatalogTableImpl(schema, properties, "hudi table");
+ assertThrows(HoodieCatalogException.class, () ->
hoodieCatalog.createTable(tablePath, table, false));
+ }
+
@ParameterizedTest
@ValueSource(booleans = {true, false})
public void testDropTable(boolean external) throws
TableAlreadyExistException, DatabaseNotExistException, TableNotExistException,
IOException {