Skip to content

Commit

Permalink
[HUDI-7213] When using wrong tabe.type value in hudi catalog happends…
Browse files Browse the repository at this point in the history
… npe (#10300)
  • Loading branch information
LXin96 authored and yihua committed Feb 27, 2024
1 parent 155a66c commit e1625b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;

Expand Down Expand Up @@ -189,7 +190,16 @@ public static Map<String, String> translateFlinkTableProperties2Spark(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,16 @@ public void testCreateNonHoodieTable() throws TableAlreadyExistException, Databa
}
}

@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 {
Expand Down

0 comments on commit e1625b1

Please sign in to comment.