You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/04/28 05:43:44 UTC

[GitHub] [arrow-datafusion] yahoNanJing opened a new issue, #2365: Add a built-in UDAF approx_sum_topn based on space saving algorithm

yahoNanJing opened a new issue, #2365:
URL: https://github.com/apache/arrow-datafusion/issues/2365

   **Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
   <!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 
   (This section helps Arrow developers understand the context and *why* for this feature, in addition to  the *what*) -->
   Suppose we want to get the top 5 _LO_SUPPKEY_ for each _LO_SHIPMODE_ based on _SUM(LO_EXTENDEDPRICE)_ in descending order, it can be achieved by the following SQL:
   ```
   select LO_SHIPMODE,
          collect(LO_SUPPKEY)
   from
     (select LO_SHIPMODE,
             LO_SUPPKEY,
             ROW_NUMBER() OVER (PARTITION BY LO_SHIPMODE
                                ORDER BY SUM_LO_EXTENDEDPRICE desc) as rank_num
      from
        (select LO_SHIPMODE,
                LO_SUPPKEY,
                SUM(LO_EXTENDEDPRICE) as SUM_LO_EXTENDEDPRICE
         from LINEORDER
         group by 1,
                  2) T0) T1
   where rank_num <= 5
   group by 1
   ```
   However, if the cardinality of _LO_SUPPKEY_ may be extremely large, like billions, it will be very resource consuming to finish the inner most subquery
   ```
   select LO_SHIPMODE,
          LO_SUPPKEY,
          SUM(LO_EXTENDEDPRICE) as SUM_LO_EXTENDEDPRICE
   from LINEORDER
   group by 1,
            2
   ```
   and the sort operation in the window function.
   
   **Describe the solution you'd like**
   A clear and concise description of what you want to happen.
   
   **Describe alternatives you've considered**
   A clear and concise description of any alternative solutions or features you've considered.
   
   **Additional context**
   Add any other context or screenshots about the feature request here.
   


-- 
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: github-unsubscribe@arrow.apache.org.apache.org

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