You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "yjshen (via GitHub)" <gi...@apache.org> on 2023/02/25 05:01:00 UTC

[GitHub] [arrow-datafusion] yjshen commented on issue #5325: Optimize Accumulator `size` function performance (fix regression on clickbench)

yjshen commented on issue #5325:
URL: https://github.com/apache/arrow-datafusion/issues/5325#issuecomment-1444994728

   We could rewrite an aggregate query with distinct aggregations into an expanded double aggregation, as Spark did:
   
   Before
   ```
   Aggregate(
      key = ['key]
      functions = [COUNT(DISTINCT 'cat1),
                   COUNT(DISTINCT 'cat2),
                   sum('value)]
      output = ['key, 'cat1_cnt, 'cat2_cnt, 'total])
     LocalTableScan [...]
   ```
   
   After rewrite:
   ```
   Aggregate(
      key = ['key]
      functions = [count('cat1) FILTER (WHERE 'gid = 1),
                   count('cat2) FILTER (WHERE 'gid = 2),
                   first('total) ignore nulls FILTER (WHERE 'gid = 0)]
      output = ['key, 'cat1_cnt, 'cat2_cnt, 'total])
     Aggregate(
        key = ['key, 'cat1, 'cat2, 'gid]
        functions = [sum('value)]
        output = ['key, 'cat1, 'cat2, 'gid, 'total])
       Expand(
          projections = [('key, null, null, 0, cast('value as bigint)),
                         ('key, 'cat1, null, 1, null),
                         ('key, null, 'cat2, 2, null)]
          output = ['key, 'cat1, 'cat2, 'gid, 'value])
         LocalTableScan [...]
   ```
   
   


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

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