Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
4a70e07c
Commit
4a70e07c
authored
10 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
use `reductions` instead of implementing cumulative sum myself
parent
93840af1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/driver/generic_sql/query_processor.clj
+1
-13
1 addition, 13 deletions
src/metabase/driver/generic_sql/query_processor.clj
test/metabase/driver/generic_sql/query_processor_test.clj
+1
-0
1 addition, 0 deletions
test/metabase/driver/generic_sql/query_processor_test.clj
with
2 additions
and
13 deletions
src/metabase/driver/generic_sql/query_processor.clj
+
1
−
13
View file @
4a70e07c
...
...
@@ -219,18 +219,6 @@
first
(
=
"cum_sum"
)))
(
defn-
cumulative-sum
"Recursively cumulative sum a sequence of VALUES."
([
values
]
{
:pre
[(
sequential?
values
)
(
every?
number?
values
)]}
(
cumulative-sum
0
[]
values
))
([
acc-sum
acc-values
[
value
&
more
]]
(
let
[
acc-sum
(
+
acc-sum
value
)
acc-values
(
conj
acc-values
acc-sum
)]
(
if-not
(
seq?
more
)
acc-values
(
recur
acc-sum
acc-values
more
)))))
(
defn-
apply-cumulative-sum
"Apply `cumulative-sum` to values of the aggregate `Field` in RESULTS."
{
:arglists
'
([
query
results
])}
...
...
@@ -238,7 +226,7 @@
(
let
[
field
(
field-id->kw
field-id
)
values
(
->>
results
; make a sequence of cumulative sum values for each row
(
map
field
)
cumulative-sum
)]
(
reductions
+
)
)]
(
map
(
fn
[
row
value
]
; replace the value for each row with the cumulative sum value
(
assoc
row
field
value
))
results
values
)))
...
...
This diff is collapsed.
Click to expand it.
test/metabase/driver/generic_sql/query_processor_test.clj
+
1
−
0
View file @
4a70e07c
...
...
@@ -387,6 +387,7 @@
;; # POST PROCESSING TESTS
;; ## CUMULATIVE SUM
;; ### Simple cumulative sum w/o any breakout
(
expect
{
:status
:completed
:row_count
15
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment