Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hive] Fix Hive DDL and paimon schema mismatched bug #4561

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,10 @@ private static void checkFieldsMatched(
}
}

if (schemaFieldNames.size() != hiveFieldNames.size()) {
// It is OK that hive is a subset of paimon
if (schemaFieldNames.size() < hiveFieldNames.size()) {
Copy link
Contributor

@ChaomingZhangCN ChaomingZhangCN Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking by List#size() is not precise, Set#containsAll() maybe a better choice. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code will be checked one by one, I think it is OK

throw new IllegalArgumentException(
"Hive DDL and paimon schema mismatched! "
"Hive DDL is a superset of paimon schema! "
+ "It is recommended not to write any column definition "
+ "as Paimon external table can read schema from the specified location.\n"
+ "There are "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,54 @@ public void testMismatchedColumnNameAndType() throws Exception {
.hasMessageContaining(expected);
}

@Test
public void testSubsetColumnNameAndType() throws Exception {
createSchema();
Properties properties = new Properties();
List<String> columns = Arrays.asList("a", "b");
properties.setProperty("columns", String.join(",", columns));
properties.setProperty(
"columns.types",
String.join(
":",
Arrays.asList(
TypeInfoFactory.intTypeInfo.getTypeName(),
TypeInfoFactory.stringTypeInfo.getTypeName(),
TypeInfoFactory.getDecimalTypeInfo(6, 3).getTypeName())));
properties.setProperty("columns.comments", "\0\0");
properties.setProperty("location", tempDir.toString());
List<String> fields = HiveSchema.extract(null, properties).fieldNames();
assertThat(fields).isEqualTo(columns);
}

@Test
public void testSupersetColumnNameAndType() throws Exception {
createSchema();
Properties properties = new Properties();
properties.setProperty("columns", "a,b,c,d");
properties.setProperty(
"columns.types",
String.join(
":",
Arrays.asList(
TypeInfoFactory.intTypeInfo.getTypeName(),
TypeInfoFactory.stringTypeInfo.getTypeName(),
TypeInfoFactory.decimalTypeInfo.getTypeName(),
TypeInfoFactory.stringTypeInfo.getTypeName(),
TypeInfoFactory.getDecimalTypeInfo(6, 3).getTypeName())));
properties.setProperty("columns.comments", "\0\0");
properties.setProperty("location", tempDir.toString());
String expected =
"Hive DDL is a superset of paimon schema! "
+ "It is recommended not to write any column definition "
+ "as Paimon external table can read schema from the specified location.\n"
+ "There are 4 fields in Hive DDL: a, b, c, d\n"
+ "There are 3 fields in Paimon schema: a, b, c\n";
assertThatThrownBy(() -> HiveSchema.extract(null, properties))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining(expected);
}

@Test
public void testTooFewColumns() throws Exception {
createSchema();
Expand Down
Loading