stefankandic commented on code in PR #49147:
URL: https://github.com/apache/spark/pull/49147#discussion_r1881832315
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CollationTypeCoercion.scala:
##########
@@ -180,6 +184,36 @@ object CollationTypeCoercion {
}
}
+ /**
+ * Changes the data type of the expression in the subquery to the given
`newType`.
+ * Currently only supports subqueries with [[Project]] and [[Aggregate]]
plan.
+ */
+ private def changeTypeInSubquery(
+ subqueryExpression: SubqueryExpression,
+ newType: DataType): SubqueryExpression = {
+
+ def transformNamedExpressions(ex: NamedExpression): NamedExpression = {
+ changeType(ex, newType) match {
+ case named: NamedExpression => named
+ case other => Alias(other, ex.name)()
+ }
+ }
+
+ val newPlan = subqueryExpression.plan match {
+ case project: Project =>
+ val newProjectList = project.projectList.map(transformNamedExpressions)
+ project.copy(projectList = newProjectList)
+
+ case agg: Aggregate =>
+ val newAggregateExpressions =
agg.aggregateExpressions.map(transformNamedExpressions)
+ agg.copy(aggregateExpressions = newAggregateExpressions)
+
Review Comment:
<img width="570" alt="image"
src="https://github.com/user-attachments/assets/54645a39-edbd-4376-b95f-6b0d74d28bbc"
/>
I don't think so, this is how the plan will look like if we have an alias
for the subquery
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CollationTypeCoercion.scala:
##########
@@ -180,6 +184,36 @@ object CollationTypeCoercion {
}
}
+ /**
+ * Changes the data type of the expression in the subquery to the given
`newType`.
+ * Currently only supports subqueries with [[Project]] and [[Aggregate]]
plan.
+ */
+ private def changeTypeInSubquery(
+ subqueryExpression: SubqueryExpression,
+ newType: DataType): SubqueryExpression = {
+
+ def transformNamedExpressions(ex: NamedExpression): NamedExpression = {
+ changeType(ex, newType) match {
+ case named: NamedExpression => named
+ case other => Alias(other, ex.name)()
+ }
+ }
+
+ val newPlan = subqueryExpression.plan match {
+ case project: Project =>
+ val newProjectList = project.projectList.map(transformNamedExpressions)
+ project.copy(projectList = newProjectList)
+
+ case agg: Aggregate =>
+ val newAggregateExpressions =
agg.aggregateExpressions.map(transformNamedExpressions)
+ agg.copy(aggregateExpressions = newAggregateExpressions)
+
Review Comment:
<img width="570" alt="image"
src="https://github.com/user-attachments/assets/54645a39-edbd-4376-b95f-6b0d74d28bbc"
/>
I don't think so, this is how the plan will look like if we have an alias
for the subquery
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]