andylam-db commented on code in PR #60634:
URL: https://github.com/apache/spark/pull/60634#discussion_r4648489232


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala:
##########
@@ -234,6 +234,11 @@ abstract class Optimizer(catalogManager: CatalogManager)
       ReplaceExceptWithFilter,
       ReplaceExceptWithAntiJoin,
       ReplaceDistinctWithAggregate),
+    // This batch must run after "Replace Operators", as that one turns 
Distinct and Deduplicate
+    // into Aggregate.
+    Batch("Insert Variant Canonicalization", FixedPoint(1),
+      InsertVariantCanonicalizationInAggregate,
+      InsertVariantCanonicalizationInRepartitionExpressions),

Review Comment:
   Another problem with this rewrite;
    
   Consider COUNT(DISTINCT v) FILTER (WHERE false), where v is a constant, 
valid Variant. Some valid Variants share storage internally. Rebuilding one 
into its canonical encoding can expand it past Spark’s size limit.
   
   • Base Spark removes the always-false aggregate and returns 0.
   • With the PR, the optimizer puts CanonicalizeVariant(v) in a separate 
projection below the aggregate.  Constant folding evaluates that projection 
before Spark removes the always-false aggregate, so it can  throw 
VARIANT_CONSTRUCTOR_SIZE_LIMIT.



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