EnricoMi commented on code in PR #37407:
URL: https://github.com/apache/spark/pull/37407#discussion_r988687537
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -869,26 +869,52 @@ class Analyzer(override val catalogManager:
CatalogManager)
def apply(plan: LogicalPlan): LogicalPlan =
plan.resolveOperatorsWithPruning(
_.containsPattern(UNPIVOT), ruleId) {
- // once children and ids are resolved, we can determine values, if non
were given
- case up: Unpivot if up.childrenResolved && up.ids.forall(_.resolved) &&
up.values.isEmpty =>
- up.copy(values = up.child.output.diff(up.ids))
-
- case up: Unpivot if !up.childrenResolved || !up.ids.forall(_.resolved) ||
- up.values.isEmpty || !up.values.forall(_.resolved) ||
!up.valuesTypeCoercioned => up
+ // once children are resolved, we can determine values from ids and vice
versa
+ // if only either is given, and only AttributeReference are given
+ case up @Unpivot(Some(ids), None, _, _, _, _) if up.childrenResolved &&
Review Comment:
fixed
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -869,26 +869,52 @@ class Analyzer(override val catalogManager:
CatalogManager)
def apply(plan: LogicalPlan): LogicalPlan =
plan.resolveOperatorsWithPruning(
_.containsPattern(UNPIVOT), ruleId) {
- // once children and ids are resolved, we can determine values, if non
were given
- case up: Unpivot if up.childrenResolved && up.ids.forall(_.resolved) &&
up.values.isEmpty =>
- up.copy(values = up.child.output.diff(up.ids))
-
- case up: Unpivot if !up.childrenResolved || !up.ids.forall(_.resolved) ||
- up.values.isEmpty || !up.values.forall(_.resolved) ||
!up.valuesTypeCoercioned => up
+ // once children are resolved, we can determine values from ids and vice
versa
+ // if only either is given, and only AttributeReference are given
+ case up @Unpivot(Some(ids), None, _, _, _, _) if up.childrenResolved &&
+ ids.forall(_.resolved) &&
+ ids.forall(_.isInstanceOf[AttributeReference]) =>
+ val idAttrs = AttributeSet(up.ids.get)
+ val values = up.child.output.filterNot(idAttrs.contains)
+ up.copy(values = Some(values.map(Seq(_))))
+ case up @Unpivot(None, Some(values), _, _, _, _) if up.childrenResolved
&&
Review Comment:
fixed
--
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]