rishvin opened a new pull request, #2221:
URL: https://github.com/apache/datafusion-comet/pull/2221

   ## 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 #1941 
   
   ## 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.  
   -->
   This PR introduces `CometMapSort` which is spark compatible `MapSort` 
function. Spark `MapSort`  was introduced in Spark-4.0 to allows grouping on 
`Map` type. It allows this by sorting the  map by keys before doing the group 
by.
   
   Today, DataFusion/Arrow does not support grouping on map type, as such 
executing `CometMapSort` as a grouping expression will fail. To make it work, 
this PR introduces additional changes to allow grouping on map type, however 
the support is limited at the moment. 
   
   
   ## What changes are included in this PR?
   
   <!--
   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.
   -->
   - Adds `map_sort` scalar function which sorts the Map type. This is 
compatible with Spark's `MapSort`.
   - Adds `map_to_list` scalar function which converts the `Map` type to 
`List<Struct<K, V>> `. The functions gets wrapped before passing the Map type 
to the hash aggregate for grouping.  This conversion from Map type to List 
should be cheap as the physical layout is maintained. 
   - Adds `map_from_list` scalar function which converts the `List<Struct<K, 
V>>` back to the Map type. This function is applied to the output of the hash 
aggregate, so that the grouping keys returned by the hash aggregate is still 
Map type. This is important to ensure the schema consistency. This conversion 
should also be cheap.
   - The above 3 function are integrated with with the hash aggregate using a 
helper class called `HashAggregateMapConverter`. It provides helpers to wrap 
grouping expressions with `map_to_list` and wrap the output of the hash 
aggregate with `map_from_list` to get the map type back.
   
   **Limitations (Future work)**
   - `Partial` aggregation is executed natively, however `Final` aggregation 
falls back to the Spark. This is due to unsupported map-type in 
[result-expression](https://github.com/apache/datafusion-comet/blob/0050ed81eedff8681016b5c1b3383e3c23ee9ec4/spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala#L1999).
 Result expression is sent for final aggregation only. This work can be 
extended to support `Final` aggregation in the future.
   - Nested map type seems to fallback to Spark. In the future, this will be 
supported.
   
   ## How are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. 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)?
   -->
   - Added unit tests for all mentioned scalar functions.
   - Added integration tests for grouping on map type.
   


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