-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
[SPARK-51310][SQL] Resolve the type of default string producing expressions #50053
base: master
Are you sure you want to change the base?
[SPARK-51310][SQL] Resolve the type of default string producing expressions #50053
Conversation
...yst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveDDLCommandStringTypes.scala
Outdated
Show resolved
Hide resolved
…out adding node tag
@cloud-fan @dejankrak-db please take a look, thanks! |
@@ -28,6 +28,7 @@ import org.apache.spark.sql.types.{DataType, StringType} | |||
* collation from the corresponding object (table/view -> schema -> catalog). | |||
*/ | |||
object ResolveDDLCommandStringTypes extends Rule[LogicalPlan] { | |||
|
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: you can remove this extra line now
|
||
plan.mapChildren { operator => | ||
operator.mapExpressions { expression => | ||
expression.mapChildren { |
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.
Does .mapChildren
transform the whole expression tree?
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.
Yes.
spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala
Line 706 in d8aca18
def mapChildren(f: BaseType => BaseType): BaseType = { |
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.
if (containsChild.nonEmpty) {
withNewChildren(children.map(f))
} else {
this
}
There is no recursion, how does it transform the full tree?
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.
Yeah, you are right, sorry I missed this. Changed the behavior to visit recursively and added new test to verify this behavior.
What changes were proposed in this pull request?
Add casts to
DefaultStringProducingExpression
to have the correct type based on the default string type.Currently, we can only test this on views, until we implement schema level collations when we will be able to test the behavior on newly created tables as well.
Why are the changes needed?
These expressions should return the default string type, which could be different in some DDL commands.
Does this PR introduce any user-facing change?
No.
How was this patch tested?
Added unit tests for view creation.
Was this patch authored or co-authored using generative AI tooling?
No.