-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-46629] Fix for STRUCT type DDL not picking up nullability and comment #44644
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
|
cc @MaxGekk |
| case s: StructType => | ||
| val fieldsDDL = s.fields.map { f => | ||
| val nullString = if (f.nullable) "" else " NOT NULL" | ||
| s"${QuotingUtils.quoteIfNeeded(f.name)}: " + | ||
| s"${getDataTypeDDL(f.dataType)}$nullString${f.getDDLComment}" | ||
| } | ||
| s"STRUCT<${fieldsDDL.mkString(", ")}>" |
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.
Can't we incapsulate the logic inside of the method StructType.sql()?
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.
great idea, done!
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.
@vitaliili-db BTW, is the output of toDDL() with NOT NULL parseable back by fromDDL()? Could you add such test to StructTypeSuite.
| "protobufType" -> "FieldMissingInProto", | ||
| "toType" -> toSQLType(CATALYST_STRUCT))) | ||
|
|
||
| assertFailedConversionMessage(protoFile, |
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.
Why did you remove this?
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.
Reverted and fixed.
|
BTW, here is a similar PR #41016 |
|
@vitaliili-db Could you change PR's title, it is too much specific. |
|
+1, LGTM. Merging to master. |
What changes were proposed in this pull request?
This change adds logic to generate correct DDL for nested fields in STRUCT. In particular instead of generating list of fields with data type names it will add
NOT NULLqualifier when necessary and field comment when present.For a table:
Before:
After
Closes #41016
Why are the changes needed?
Generate correct DDL.
Does this PR introduce any user-facing change?
No, we do not document behavior of this command for struct case.
How was this patch tested?
New unit test.
Was this patch authored or co-authored using generative AI tooling?
No