mihailoale-db commented on code in PR #53729:
URL: https://github.com/apache/spark/pull/53729#discussion_r2675915249


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -1301,29 +1301,43 @@ object Expand {
    * @param groupByAttrs The attributes of aliased group by expressions
    * @param gid Attribute of the grouping id
    * @param child Child operator
+   * @param childOutputOpt Optional child output. If not provided, then 
`child.output` is used
    */
   def apply(
     groupingSetsAttrs: Seq[Seq[Attribute]],
     groupByAliases: Seq[Alias],
     groupByAttrs: Seq[Attribute],
     gid: Attribute,
-    child: LogicalPlan): Expand = {
+    child: LogicalPlan,
+    childOutputOpt: Option[Seq[Attribute]] = None): Expand = {
+    val childOutput = childOutputOpt.getOrElse(child.output)
+
     val attrMap = Utils.toMapWithIndex(groupByAttrs)
 
     val hasDuplicateGroupingSets = groupingSetsAttrs.size !=
       groupingSetsAttrs.map(_.map(_.exprId).toSet).distinct.size
 
+    // Compute nullabilities from childOutput ++ groupByAliases to fix the 
nullable field
+    val nullabilities = (childOutput ++ 
groupByAliases.map(_.toAttribute)).groupBy(_.exprId).map {

Review Comment:
   In the `GroupingAnalyticsTransformer.constructExpand` we change the 
nullability of some attributes using `aliasAttribute.withNullability(true)`. 
Instead of waiting for `UpdateAttributeNullability` to update nullability of 
those attributes we do that in the proposed way (you can't do it in place since 
you sometimes use those attributes to create `Literal`s, `Literal.create(null, 
attr.dataType)` for example, we update it only in case those are returned as 
they are). I'll update the doc. Thanks!



-- 
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]

Reply via email to