-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
-Array
variants of aggregates in schema_array_transformer
(v2) (
#1226) Review fixes for: #1152 `schema_array_transformer` transforms the SQL query for `Array` columns. Before this change, if an aggregation was performed on a `Array` column, e.g. `sum(myArrayColumn)`, the transformer would change it into `sum(arrayJoin(myArrayColumn))`. However using `arrayJoin` function has problems - `arrayJoin` modifies the result set of SQL query introducing additional rows. If there are many `arrayJoin`s, a Cartesian product many rows will be performed: this causes query slowdown and makes the result invalid (we don't actually want to do a Cartesian product!). Solve the problem by using `-Array` variants of aggregates (e.g. `sumArray` instead of `sum(arrayJoin())`), which does not inflate the number of result rows. Note that this PR does NOT get rid of `arrayJoin()` fully in all cases. There are panels that actually need it, such as "Top products this week" in eCommerce dashboard, where we `GROUP BY` an array column. <img width="1350" alt="Screenshot 2025-01-07 at 11 20 42" src="https://github.com/user-attachments/assets/214890d5-c04a-4a6a-a683-5bffaf944d80" /> This remaining case should use the `ARRAY JOIN` operator, but this is out-of-scope of this PR. Closes #1152 --------- Co-authored-by: Piotr Grabowski <[email protected]>
- Loading branch information
1 parent
9bf027a
commit 2661385
Showing
3 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters