-
Notifications
You must be signed in to change notification settings - Fork 3k
Add schema validation before table import #2736
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
Conversation
flyrain
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Out of curiosity, in which scenario, method importSparkTable will hit unmatched schema? In the other words, why do we need to check schema? Can we add a test case for that?
| try { | ||
| CatalogTable sourceCatalogTable = catalog.getTableMetadata(sourceTableIdent); | ||
| Preconditions.checkArgument(validateSchema(sourceCatalogTable.schema(), targetTable.schema()), | ||
| "The schemas of source table and target table dont match"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont -> don't
| } | ||
| } | ||
|
|
||
| static boolean validateSchema(StructType srcSchema, Schema tgtSchema) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it more suitable to put into SparkSchemaUtil?
|
|
||
| import static org.apache.iceberg.types.Types.NestedField.optional; | ||
|
|
||
| public class TestSparkTableUtil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some test cases are more suitable for the method SparkSchemaUtil.convert since the method validateSchema didn't do a lot except invoking SparkSchemaUtil.convert() and StructType.equals().
| } | ||
|
|
||
| static boolean validateSchema(StructType srcSchema, Schema tgtSchema) { | ||
| StructType convertSchem = SparkSchemaUtil.convert(tgtSchema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: convertSchema - missing last a in variable name.
|
This PR requires more changes, closing it for now. |
No description provided.