You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "vladimirg-db (via GitHub)" <gi...@apache.org> on 2026/08/02 15:28:16 UTC

[PR] [SPARK-58503][SQL] Evaluate HAVING before window functions with generators [spark]

vladimirg-db opened a new pull request, #57704:
URL: https://github.com/apache/spark/pull/57704

   ### What changes were proposed in this pull request?
   
   Place a resolved HAVING filter below the complete Window chain when generator extraction has
   inserted Project and Generate operators above it. If the condition's attributes are not available
   below every Window, retain the existing fallback placement.
   
   Add regression coverage for HAVING conditions on grouping columns and aggregate aliases, including
   multiple window specifications, and document the corrected behavior in the SQL migration guide.
   
   
   ### Why are the changes needed?
   
   Generator extraction can hide the Window chain from the analyzer's normal HAVING handling. The
   remaining fallback then places HAVING above Window, so window functions see groups that HAVING
   removes.
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. Window functions are now evaluated after HAVING for queries that also select generators. For
   example, the window count from this query changes from 4 to the correct value 3:
   
   ```sql
   SELECT explode(array(a)), count(*) OVER (), a
   FROM VALUES (1), (2), (3), (NULL) AS t(a)
   GROUP BY a
   HAVING a IS NOT NULL;
   ```
   
   
   ### How was this patch tested?
   
   Added regression tests and ran:
   
   ```
   build/sbt 'sql/testOnly org.apache.spark.sql.GeneratorFunctionSuite'
   ```
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: OpenAI Codex (GPT-5)
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-58503][SQL] Evaluate HAVING before window functions with generators [spark]

Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on PR #57704:
URL: https://github.com/apache/spark/pull/57704#issuecomment-5160547369

   **Merge Summary:**
   - merged into master https://github.com/apache/spark/commit/22bffbbf0b7a1a15c3aec8b79dffce2f0afd87fa
   - merged into branch-4.x https://github.com/apache/spark/commit/69b205825c9d1f729945091fb1d585e7bc5ac670
   
   *Posted by `merge_spark_pr.py`*


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-58503][SQL] Evaluate HAVING before window functions with generators [spark]

Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b commented on PR #57704:
URL: https://github.com/apache/spark/pull/57704#issuecomment-5160543448

   Thank you @vladimirg-db!


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-58503][SQL] Evaluate HAVING before window functions with generators [spark]

Posted by "uros-b (via GitHub)" <gi...@apache.org>.
uros-b closed pull request #57704: [SPARK-58503][SQL] Evaluate HAVING before window functions with generators
URL: https://github.com/apache/spark/pull/57704


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Re: [PR] [SPARK-58503][SQL] Evaluate HAVING before window functions with generators [spark]

Posted by "vladimirg-db (via GitHub)" <gi...@apache.org>.
vladimirg-db commented on PR #57704:
URL: https://github.com/apache/spark/pull/57704#issuecomment-5159713304

   @uros-b could you please help me merge this correctness issue fix? 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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org