lyne7-sc opened a new pull request, #20243:
URL: https://github.com/apache/datafusion/pull/20243

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax. For example `Closes #123` 
indicates that this PR will close issue #123.
   -->
   
   - Closes #.
   
   ## Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.  
   -->
   
   The current implementation of `array_union` and `array_intersect` performs 
`RowConverter::convert_columns()` on a per-row basis, which introduces 
avoidable overhead due to repeated conversions and intermediate allocations.
   
   This PR improves performance by:
   1. converting all list values to rows in a batch
   2. reusing hash sets across iterations
   3. removing the `sorted().dedup()` pattern in favor of hash-based set 
operations
   
   ## What changes are included in this PR?
   
   Refactored the internal set operation implementation to use batch row 
conversion and a single-pass construction of result arrays.
   
   ### Benchmarks
   ```
   group                               before                                  
optimized
   -----                               ------                                  
---------
   array_intersect/high_overlap/10     2.99  1442.0±99.94µs        ? ?/sec     
1.00   481.6±21.45µs        ? ?/sec
   array_intersect/high_overlap/100    1.90      9.5±0.63ms        ? ?/sec     
1.00      5.0±0.09ms        ? ?/sec
   array_intersect/high_overlap/50     2.01      5.3±0.41ms        ? ?/sec     
1.00      2.6±0.05ms        ? ?/sec
   array_intersect/low_overlap/10      3.47  1288.1±72.39µs        ? ?/sec     
1.00   371.4±14.08µs        ? ?/sec
   array_intersect/low_overlap/100     2.35      9.2±0.43ms        ? ?/sec     
1.00      3.9±0.08ms        ? ?/sec
   array_intersect/low_overlap/50      2.45      5.1±0.41ms        ? ?/sec     
1.00      2.1±0.07ms        ? ?/sec
   array_union/high_overlap/10         4.01  1593.1±292.17µs        ? ?/sec    
1.00   396.9±13.43µs        ? ?/sec
   array_union/high_overlap/100        2.54      9.8±0.18ms        ? ?/sec     
1.00      3.9±0.11ms        ? ?/sec
   array_union/high_overlap/50         2.65      5.4±0.10ms        ? ?/sec     
1.00      2.0±0.07ms        ? ?/sec
   array_union/low_overlap/10          3.74  1622.7±96.50µs        ? ?/sec     
1.00   434.3±17.87µs        ? ?/sec
   array_union/low_overlap/100         2.39     10.3±0.92ms        ? ?/sec     
1.00      4.3±0.11ms        ? ?/sec
   array_union/low_overlap/50          2.63      5.8±0.27ms        ? ?/sec     
1.00      2.2±0.11ms        ? ?/sec
   ```
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   
   Yes. Existing SQL logic tests updated to reflect new output order.
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   4. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   
   Yes. The output order may differ from the previous implementation.
   
   Previously, results were implicitly sorted due to the use of 
`sorted().dedup()`. The new implementation preserves the order of first 
appearance within each list.
   
   This is a user-visible behavioral change, but it is consistent with typical 
SQL set operation semantics, which do not guarantee a specific output order.
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   


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