Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

cumulative-aggregations-middleware => Lib (#63592)

Cam Saul0d1b4e253a81
diff --git a/src/metabase/lib/util.cljc b/src/metabase/lib/util.cljc
index 07964cb6fa5..9e8402b9e8f 100644
--- a/src/metabase/lib/util.cljc
+++ b/src/metabase/lib/util.cljc
@@ -129,7 +129,7 @@
(defmethod custom-name-method :default
[x]
;; We assume that clauses only get a :display-name option if the user explicitly specifies it.
- ;; Expressions from the :expressions clause of pMBQL queries have custom names by default.
+ ;; Expressions from the :expressions clause of MBQL 5 queries have custom names by default.
(when (clause? x)
((some-fn :display-name :lib/expression-name) (lib.options/options x))))
@@ -192,7 +192,7 @@
;;; the near future.
(defn- native-query->pipeline
- "Convert a `:type` `:native` QP MBQL query to a pMBQL query. See docstring for [[mbql-query->pipeline]] for an
+ "Convert a `:type` `:native` QP MBQL query to a MBQL 5 query. See docstring for [[mbql-query->pipeline]] for an
explanation of what this means."
[query]
(merge {:lib/type :mbql/query
@@ -205,14 +205,14 @@
(declare inner-query->stages)
(defn- update-legacy-boolean-expression->list
- "Updates m with a legacy boolean expression at `legacy-key` into a list with an implied and for pMBQL at `pMBQL-key`"
- [m legacy-key pMBQL-key]
+ "Updates m with a legacy boolean expression at `legacy-key` into a list with an implied and for MBQL 5 at `mbql5-key`"
+ [m legacy-key mbql5-key]
(cond-> m
(contains? m legacy-key) (update legacy-key #(if (and (vector? %)
(= (first %) :and))
(vec (drop 1 %))
[%]))
- (contains? m legacy-key) (set/rename-keys {legacy-key pMBQL-key})))
+ (contains? m legacy-key) (set/rename-keys {legacy-key mbql5-key})))
(defn ->stage-metadata
"Convert legacy `:source-metadata` to [[metabase.lib.metadata/StageMetadata]]."
@@ -272,10 +272,10 @@
(defn- mbql-query->pipeline
"Convert a `:type` `:query` QP MBQL (i.e., MBQL as currently understood by the Query Processor, or the JS MLv1) to a
- pMBQL query. The key difference is that instead of having a `:query` with a `:source-query` with a `:source-query`
+ MBQL 5 query. The key difference is that instead of having a `:query` with a `:source-query` with a `:source-query`
and so forth, you have a vector of `:stages` where each stage serves as the source query for the next stage.
Initially this was an implementation detail of a few functions, but it's easier to visualize and manipulate, so now
- all of MLv2 deals with pMBQL. See this Slack thread
+ all of MLv2 deals with MBQL 5. See this Slack thread
https://metaboat.slack.com/archives/C04DN5VRQM6/p1677118410961169?thread_ts=1677112778.742589&cid=C04DN5VRQM6 for
more information."
[query]
@@ -283,22 +283,26 @@
:stages (inner-query->stages (:query query))}
(dissoc query :type :query)))
-(def LegacyOrPMBQLQuery
- "Schema for a map that is either a legacy query OR a pMBQL query."
- [:or
- [:map
- {:error/message "legacy query"}
- [:type [:enum :native :query]]]
- [:map
- {:error/message "pMBQL query"}
- [:lib/type [:= :mbql/query]]]])
+(mr/def ::legacy-query
+ [:map
+ {:error/message "legacy query"}
+ [:type [:enum :native :query]]])
+
+(mr/def ::mbql5-query
+ [:map
+ {:error/message "MBQL 5 query"}
+ [:lib/type [:= :mbql/query]]])
+
+(mr/def ::legacy-or-mbql5-query
+ "Schema for a map that is either a legacy query OR a MBQL 5 query."
+ [:or ::legacy-query ::mbql5-query])
(mu/defn pipeline
- "Ensure that a `query` is in the general shape of a pMBQL query. This doesn't walk the query and fix everything! The
+ "Ensure that a `query` is in the general shape of a MBQL 5 query. This doesn't walk the query and fix everything! The
goal here is just to make sure we have `:stages` in the correct place and the like. See [[metabase.lib.convert]] for
- functions that actually ensure all parts of the query match the pMBQL schema (they use this function as part of that
+ functions that actually ensure all parts of the query match the MBQL 5 schema (they use this function as part of that
process.)"
- [query :- LegacyOrPMBQLQuery]
+ [query :- ::legacy-or-mbql5-query]
(if (= (:lib/type query) :mbql/query)
query
(case (:type query)
@@ -351,9 +355,9 @@
(mu/defn query-stage :- [:maybe ::lib.schema/stage]
"Fetch a specific `stage` of a query. This handles negative indices as well, e.g. `-1` will return the last stage of
the query."
- [query :- LegacyOrPMBQLQuery
+ [query :- ::mbql5-query
stage-number :- :int]
- (let [{:keys [stages], :as query} (pipeline query)]
+ (let [{:keys [stages], :as query} query]
(get (vec stages) (canonical-stage-index query stage-number))))
(mu/defn previous-stage :- [:maybe ::lib.schema/stage]
@@ -368,7 +372,7 @@
(apply f stage args)
`stage-number` can be a negative index, e.g. `-1` will update the last stage of the query."
- [query :- LegacyOrPMBQLQuery
+ [query :- ::legacy-or-mbql5-query
stage-number :- :int
f & args]
(let [{:keys [stages], :as query} (pipeline query)
@@ -378,7 +382,7 @@
(mu/defn drop-later-stages :- ::lib.schema/query
"Drop any stages in the `query` that come after `stage-number`."
- [query :- LegacyOrPMBQLQuery
+ [query :- ::legacy-or-mbql5-query
stage-number :- :int]
(cond-> (pipeline query)
(not (last-stage? query stage-number))
@@ -392,7 +396,7 @@
(native-stage? (query-stage query stage-number))))
(mu/defn ensure-mbql-final-stage :- ::lib.schema/query
- "Convert query to a pMBQL (pipeline) query, and make sure the final stage is an `:mbql` one."
+ "Convert query to a MBQL 5 (pipeline) query, and make sure the final stage is an `:mbql` one."
[query]
(let [query (pipeline query)]
(cond-> query
@@ -466,7 +470,7 @@
(mu/defn legacy-string-table-id->card-id :- [:maybe ::lib.schema.id/card]
"If `table-id` is a legacy `card__<id>`-style string, parse the `<id>` part to an integer Card ID. Only for legacy
- queries! You don't need to use this in pMBQL since this is converted automatically by [[metabase.lib.convert]] to
+ queries! You don't need to use this in MBQL 5 since this is converted automatically by [[metabase.lib.convert]] to
`:source-card`."
[table-id]
(when (string? table-id)
diff --git a/src/metabase/query_processor/middleware/cumulative_aggregations.clj b/src/metabase/query_processor/middleware/cumulative_aggregations.clj
index 224ffe7ff0c..5a2f1ffe186 100644
--- a/src/metabase/query_processor/middleware/cumulative_aggregations.clj
+++ b/src/metabase/query_processor/middleware/cumulative_aggregations.clj
@@ -17,15 +17,15 @@
Rather than doing a cumulative sum across the entire set of query results -- see #2862 and #42003 for more
information."
(:require
+ [medley.core :as m]
[metabase.driver :as driver]
[metabase.driver.util :as driver.u]
- ;; legacy usage -- don't use Legacy MBQL utils in QP code going forward, prefer Lib. This will be updated to use
- ;; Lib soon
- ^{:clj-kondo/ignore [:discouraged-namespace]}
- [metabase.legacy-mbql.schema :as mbql.s]
+ [metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
+ [metabase.lib.schema :as lib.schema]
[metabase.lib.util.match :as lib.util.match]
- [metabase.query-processor.store :as qp.store]
+ [metabase.lib.walk :as lib.walk]
+ [metabase.query-processor.schema :as qp.schema]
[metabase.util.malli :as mu]))
;;;; Pre-processing
@@ -39,39 +39,36 @@
i)))
(map not= coll-1 coll-2)))
-(mu/defn- replace-cumulative-ags :- mbql.s/Query
- "Replace `cum-count` and `cum-sum` aggregations in `query` with `count` and `sum` aggregations, respectively."
- [query]
- (lib.util.match/replace-in query [:query :aggregation]
- ;; cumulative count doesn't neccesarily have a field-id arg
- [:cum-count] [:count]
- [:cum-count field] [:count field]
- [:cum-sum field] [:sum field]))
+(defn- update-clause [clause]
+ (lib.util.match/match-lite clause
+ ;; cumulative count doesn't necessarily have a field-id arg
+ [:cum-count opts] [:count opts]
+ [:cum-count opts field] [:count opts field]
+ [:cum-sum opts field] [:sum opts field]))
+
+(defn- update-aggregations [aggregations]
+ (lib.walk/walk-clauses* aggregations update-clause))
+
+(defn- update-stage [{breakouts :breakout, :as stage}]
+ (when-let [updated-stage (m/update-existing stage :aggregation update-aggregations)]
+ ;; figure out which indexes are being changed in the results. Since breakouts always get included in
+ ;; results first we need to offset the indexes to change by the number of breakouts
+ (let [replaced-indexes (set (for [i (diff-indexes (:aggregation stage)
+ (:aggregation updated-stage))]
+ (+ (count breakouts) i)))]
+ (assoc updated-stage ::replaced-indexes replaced-indexes))))
-(defn rewrite-cumulative-aggregations
+(mu/defn rewrite-cumulative-aggregations :- ::lib.schema/query
"Pre-processing middleware. Rewrite `:cum-count` and `:cum-sum` aggregations as `:count` and `:sum` respectively. Add
information about the indecies of the replaced aggregations under the `::replaced-indexes` key."
- [{{breakouts :breakout, aggregations :aggregation} :query, :as query}]
- (cond
+ [query :- ::lib.schema/query]
+ (if (driver.u/supports? driver/*driver*
+ :window-functions/cumulative
+ (lib.metadata/database query))
;; no need to rewrite `:cum-sum` and `:cum-count` functions, this driver supports native window function versions
- (driver.u/supports? driver/*driver*
- :window-functions/cumulative
- (lib.metadata/database (qp.store/metadata-provider)))
- query
-
- ;; nothing to rewrite
- (not (lib.util.match/match aggregations #{:cum-count :cum-sum}))
query
-
- :else
- (let [query' (replace-cumulative-ags query)
- ;; figure out which indexes are being changed in the results. Since breakouts always get included in
- ;; results first we need to offset the indexes to change by the number of breakouts
- replaced-indexes (set (for [i (diff-indexes (-> query :query :aggregation)
- (-> query' :query :aggregation))]
- (+ (count breakouts) i)))]
- (cond-> query'
- (seq replaced-indexes) (assoc ::replaced-indexes replaced-indexes)))))
+ (lib.walk/walk-stages query (fn [_query _path stage]
+ (update-stage stage)))))
;;;; Post-processing
@@ -122,12 +119,14 @@
(let [row' (add-values-from-last-partition row)]
(rf result row'))))))
-(defn sum-cumulative-aggregation-columns
+(mu/defn sum-cumulative-aggregation-columns :- ::qp.schema/rff
"Post-processing middleware. Sum the cumulative count aggregations that were rewritten
by [[rewrite-cumulative-aggregations]] in Clojure-land."
- [{::keys [replaced-indexes] inner-query :query, :as _query} rff]
- (if (seq replaced-indexes)
- (fn sum-cumulative-aggregation-columns-rff* [metadata]
- (let [num-breakouts (count (:breakout inner-query))]
- (cumulative-ags-xform num-breakouts replaced-indexes (rff metadata))))
- rff))
+ [query :- ::lib.schema/query
+ rff :- ::qp.schema/rff]
+ (let [replaced-indexes (::replaced-indexes (lib/query-stage query -1))]
+ (if (seq replaced-indexes)
+ (fn sum-cumulative-aggregation-columns-rff* [metadata]
+ (let [num-breakouts (count (lib/breakouts query))]
+ (cumulative-ags-xform num-breakouts replaced-indexes (rff metadata))))
+ rff)))
diff --git a/src/metabase/query_processor/postprocess.clj b/src/metabase/query_processor/postprocess.clj
index 87413e7571a..8ea0c2f9e74 100644
--- a/src/metabase/query_processor/postprocess.clj
+++ b/src/metabase/query_processor/postprocess.clj
@@ -41,7 +41,7 @@
[::mbql5 #'pivot-export/add-data-for-pivot-export]
[::mbql5 #'large-int/convert-large-int-to-string]
[::mbql5 #'viz-settings/update-viz-settings]
- [::legacy #'qp.cumulative-aggregations/sum-cumulative-aggregation-columns]
+ [::mbql5 #'qp.cumulative-aggregations/sum-cumulative-aggregation-columns]
[::mbql5 #'annotate/add-column-info]
[::mbql5 #'fetch-source-query/add-dataset-info]])
;; ↑↑↑ POST-PROCESSING ↑↑↑ happens from BOTTOM TO TOP
diff --git a/src/metabase/query_processor/preprocess.clj b/src/metabase/query_processor/preprocess.clj
index 307123a106f..4516abd138e 100644
--- a/src/metabase/query_processor/preprocess.clj
+++ b/src/metabase/query_processor/preprocess.clj
@@ -129,7 +129,7 @@
(ensure-mbql5 #'qp.remove-inactive-field-refs/remove-inactive-field-refs)
;; yes, this is called a second time, because we need to handle any joins that got added
(ensure-mbql5 #'qp.middleware.enterprise/apply-sandboxing)
- (ensure-legacy #'qp.cumulative-aggregations/rewrite-cumulative-aggregations)
+ (ensure-mbql5 #'qp.cumulative-aggregations/rewrite-cumulative-aggregations)
(ensure-mbql5 #'qp.wrap-value-literals/wrap-value-literals)
(ensure-mbql5 #'auto-parse-filter-values/auto-parse-filter-values)
(ensure-mbql5 #'validate-temporal-bucketing/validate-temporal-bucketing)
diff --git a/test/metabase/lib/util_test.cljc b/test/metabase/lib/util_test.cljc
index 0077b3e99f2..cf61c9da6d6 100644
--- a/test/metabase/lib/util_test.cljc
+++ b/test/metabase/lib/util_test.cljc
@@ -114,41 +114,51 @@
(is (=? {:lib/type :mbql.stage/mbql
:source-table 1}
(lib.util/query-stage {:database 1
- :type :query
- :query {:source-table 1}}
- 0)))
+ :lib/type :mbql/query
+ :stages [{:lib/type :mbql.stage/mbql
+ :source-table 1}]}
+ 0))))
+
+(deftest ^:parallel query-stage-test-2
(are [index expected] (=? expected
(lib.util/query-stage {:database 1
- :type :query
- :query {:source-query {:source-table 1}}}
+ :lib/type :mbql/query
+ :stages [{:lib/type :mbql.stage/mbql
+ :source-table 1}
+ {:lib/type :mbql.stage/mbql}]}
index))
0 {:lib/type :mbql.stage/mbql
:source-table 1}
- 1 {:lib/type :mbql.stage/mbql})
+ 1 {:lib/type :mbql.stage/mbql}))
+
+(deftest ^:parallel query-stage-test-3
(testing "negative index"
(are [index expected] (=? expected
(lib.util/query-stage {:database 1
- :type :query
- :query {:source-query {:source-table 1}}}
+ :lib/type :mbql/query
+ :stages [{:lib/type :mbql.stage/mbql
+ :source-table 1}
+ {:lib/type :mbql.stage/mbql}]}
index))
-1 {:lib/type :mbql.stage/mbql}
-2 {:lib/type :mbql.stage/mbql
- :source-table 1}))
+ :source-table 1})))
+
+(deftest ^:parallel query-stage-test-4
(testing "Out of bounds"
- (is (thrown-with-msg?
- #?(:clj Throwable :cljs js/Error)
- #"Stage 2 does not exist"
- (lib.util/query-stage {:database 1
- :type :query
- :query {:source-query {:source-table 1}}}
- 2)))
- (is (thrown-with-msg?
- #?(:clj Throwable :cljs js/Error)
- #"Stage -3 does not exist"
- (lib.util/query-stage {:database 1
- :type :query
- :query {:source-query {:source-table 1}}}
- -3)))))
+ (let [query {:database 1
+ :lib/type :mbql/query
+ :stages [{:lib/type :mbql.stage/mbql
+ :source-table 1}
+ {:lib/type :mbql.stage/mbql}]}]
+ (is (thrown-with-msg?
+ #?(:clj Throwable :cljs js/Error)
+ #"Stage 2 does not exist"
+ (lib.util/query-stage query 2)))
+ (is (thrown-with-msg?
+ #?(:clj Throwable :cljs js/Error)
+ #"Stage -3 does not exist"
+ (lib.util/query-stage query -3))))))
(deftest ^:parallel update-query-stage-test
(is (=? {:database 1
diff --git a/test/metabase/query_processor/middleware/cumulative_aggregations_test.clj b/test/metabase/query_processor/middleware/cumulative_aggregations_test.clj
index f0021b274a1..1c4a26acac7 100644
--- a/test/metabase/query_processor/middleware/cumulative_aggregations_test.clj
+++ b/test/metabase/query_processor/middleware/cumulative_aggregations_test.clj
@@ -2,9 +2,10 @@
(:require
[clojure.test :refer :all]
[metabase.driver :as driver]
+ [metabase.lib.core :as lib]
[metabase.lib.test-metadata :as meta]
[metabase.query-processor.middleware.cumulative-aggregations :as qp.cumulative-aggregations]
- [metabase.query-processor.store :as qp.store]))
+ [metabase.util.malli :as mu]))
(deftest ^:parallel add-values-from-last-partition-test
(are [expected indexes] (= expected
@@ -70,45 +71,49 @@
(is (= [[1 1 1] [2 3 2] [3 6 3]]
(sum-rows #{1} '((1 1 1) (2 2 2) (3 3 3))))))))
-(deftest ^:parallel replace-cumulative-ags-test
- (testing "does replacing cumulative ags work correctly?"
- (is (= {:database 1
- :type :query
- :query {:source-table 1
- :breakout [[:field 1 nil]]
- :aggregation [[:sum [:field 1 nil]]]}}
- (#'qp.cumulative-aggregations/replace-cumulative-ags
- {:database 1
- :type :query
- :query {:source-table 1
- :breakout [[:field 1 nil]]
- :aggregation [[:cum-sum [:field 1 nil]]]}}))))
- (testing "...even inside expression aggregations?"
- (is (= {:database 1
- :type :query
- :query {:source-table 1, :aggregation [[:* [:count] 1]]}}
- (#'qp.cumulative-aggregations/replace-cumulative-ags
- {:database 1
- :type :query
- :query {:source-table 1, :aggregation [[:* [:cum-count] 1]]}})))))
-
-(driver/register! ::no-window-function-driver)
+(driver/register! ::no-window-function-driver, :abstract? true)
(defmethod driver/database-supports? [::no-window-function-driver :window-functions/cumulative]
[_driver _feature _database]
false)
+(deftest ^:parallel replace-cumulative-ags-test
+ (testing "does replacing cumulative ags work correctly?"
+ (driver/with-driver ::no-window-function-driver
+ (is (=? {:stages [{:source-table 1
+ :breakout [[:field {} 1]]
+ :aggregation [[:sum {} [:field {} 1]]]}]}
+ (#'qp.cumulative-aggregations/rewrite-cumulative-aggregations
+ (lib/query
+ meta/metadata-provider
+ {:database (meta/id)
+ :type :query
+ :query {:source-table 1
+ :breakout [[:field 1 nil]]
+ :aggregation [[:cum-sum [:field 1 nil]]]}})))))))
+
+(deftest ^:parallel replace-cumulative-ags-test-2
+ (testing "...even inside expression aggregations?"
+ (driver/with-driver ::no-window-function-driver
+ (is (=? {:stages [{:source-table 1, :aggregation [[:* {} [:count {}] 1]]}]}
+ (#'qp.cumulative-aggregations/rewrite-cumulative-aggregations
+ (lib/query
+ meta/metadata-provider
+ {:database (meta/id)
+ :type :query
+ :query {:source-table 1, :aggregation [[:* [:cum-count] 1]]}})))))))
+
(defn- handle-cumulative-aggregations [query]
(driver/with-driver ::no-window-function-driver
- (qp.store/with-metadata-provider meta/metadata-provider
- (let [query (#'qp.cumulative-aggregations/rewrite-cumulative-aggregations query)
- rff (qp.cumulative-aggregations/sum-cumulative-aggregation-columns query (constantly conj))
- rf (rff nil)]
- (transduce identity rf [[1 1]
- [2 2]
- [3 3]
- [4 4]
- [5 5]])))))
+ (let [query (lib/query meta/metadata-provider query)
+ query (#'qp.cumulative-aggregations/rewrite-cumulative-aggregations query)
+ rff (qp.cumulative-aggregations/sum-cumulative-aggregation-columns query (constantly conj))
+ rf (rff nil)]
+ (transduce identity rf [[1 1]
+ [2 2]
+ [3 3]
+ [4 4]
+ [5 5]]))))
(deftest ^:parallel e2e-test
(testing "make sure we take breakout fields into account"
@@ -133,48 +138,50 @@
(deftest ^:parallel multiple-breakouts-reset-counts-test
(testing "Multiple breakouts: reset counts after breakouts other than first get new values (#2862, #42003)"
- (let [rows [[#t "2016-04-01" "Long Beach" 2] ; [LB] 0 + 2 => 2
+ (mu/disable-enforcement
+ (let [rows [[#t "2016-04-01" "Long Beach" 2] ; [LB] 0 + 2 => 2
+ [#t "2016-04-01" "San Francisco" 10] ; [SF] 0 + 10 => 10
+ [#t "2016-04-02" "San Francisco" 30] ; [SF] 10 + 30 => 40
+ [#t "2016-04-03" "Long Beach" 4] ; [LB] 2 + 4 => 6
+ [#t "2016-04-04" "San Francisco" 40] ; [SF] 40 + 40 => 80
+ [#t "2016-04-06" "Long Beach" 8]] ; [LB] 6 + 8 => 14
+ rff (qp.cumulative-aggregations/sum-cumulative-aggregation-columns
+ {:stages [{:breakout [:a :b]
+ ::qp.cumulative-aggregations/replaced-indexes #{2}}]}
+ (fn [_metadata]
+ conj))
+ rf (rff nil)]
+ (is (= [[#t "2016-04-01" "Long Beach" 2] ; [LB] 0 + 2 => 2
[#t "2016-04-01" "San Francisco" 10] ; [SF] 0 + 10 => 10
- [#t "2016-04-02" "San Francisco" 30] ; [SF] 10 + 30 => 40
- [#t "2016-04-03" "Long Beach" 4] ; [LB] 2 + 4 => 6
- [#t "2016-04-04" "San Francisco" 40] ; [SF] 40 + 40 => 80
- [#t "2016-04-06" "Long Beach" 8]] ; [LB] 6 + 8 => 14
- rff (qp.cumulative-aggregations/sum-cumulative-aggregation-columns
- {::qp.cumulative-aggregations/replaced-indexes #{2}
- :query {:breakout [:a :b]}}
- (fn [_metadata]
- conj))
- rf (rff nil)]
- (is (= [[#t "2016-04-01" "Long Beach" 2] ; [LB] 0 + 2 => 2
- [#t "2016-04-01" "San Francisco" 10] ; [SF] 0 + 10 => 10
- [#t "2016-04-02" "San Francisco" 40] ; [SF] 10 + 30 => 40
- [#t "2016-04-03" "Long Beach" 6] ; [LB] 2 + 4 => 6
- [#t "2016-04-04" "San Francisco" 80] ; [SF] 40 + 40 => 80
- [#t "2016-04-06" "Long Beach" 14]] ; [LB] 6 + 8 => 14
- (reduce rf [] rows))))))
+ [#t "2016-04-02" "San Francisco" 40] ; [SF] 10 + 30 => 40
+ [#t "2016-04-03" "Long Beach" 6] ; [LB] 2 + 4 => 6
+ [#t "2016-04-04" "San Francisco" 80] ; [SF] 40 + 40 => 80
+ [#t "2016-04-06" "Long Beach" 14]] ; [LB] 6 + 8 => 14
+ (reduce rf [] rows)))))))
(deftest ^:parallel multiple-breakouts-reset-counts-test-2
(testing "3 breakouts: reset counts after breakouts other than first get new values (#2862, #42003)"
- (let [rows [[#t "2016-04-01" "Long Beach" "LB" 2] ; [LB] 0 + 2 => 2
- [#t "2016-04-01" "San Francisco" "SF" 10] ; [SF] 0 + 10 => 10
- [#t "2016-04-02" "San Francisco" "SF" 30] ; [SF] 10 + 30 => 40
- [#t "2016-04-03" "Long Beach" "LB" 4] ; [LB] 2 + 4 => 6
- [#t "2016-04-03" "Long Beach" "LBC" 4] ; [LBC] 0 + 4 => 4
- [#t "2016-04-04" "San Francisco" "SF" 40] ; [SF] 40 + 40 => 80
- [#t "2016-04-06" "Long Beach" "LB" 8] ; [LB] 6 + 8 => 14
- [#t "2016-04-06" "Long Beach" "LBC" 8]] ; [LBC] 4 + 8 => 12
- rff (qp.cumulative-aggregations/sum-cumulative-aggregation-columns
- {::qp.cumulative-aggregations/replaced-indexes #{3}
- :query {:breakout [:a :b :c]}}
- (fn [_metadata]
- conj))
- rf (rff nil)]
- (is (= [[#t "2016-04-01" "Long Beach" "LB" 2] ; [LB] 0 + 2 => 2
- [#t "2016-04-01" "San Francisco" "SF" 10] ; [SF] 0 + 10 => 10
- [#t "2016-04-02" "San Francisco" "SF" 40] ; [SF] 10 + 30 => 40
- [#t "2016-04-03" "Long Beach" "LB" 6] ; [LB] 2 + 4 => 6
- [#t "2016-04-03" "Long Beach" "LBC" 4] ; [LBC] 0 + 4 => 4
- [#t "2016-04-04" "San Francisco" "SF" 80] ; [SF] 40 + 40 => 80
- [#t "2016-04-06" "Long Beach" "LB" 14] ; [LB] 6 + 8 => 14
- [#t "2016-04-06" "Long Beach" "LBC" 12]] ; [LBC] 4 + 8 => 12
- (reduce rf [] rows))))))
+ (mu/disable-enforcement
+ (let [rows [[#t "2016-04-01" "Long Beach" "LB" 2] ; [LB] 0 + 2 => 2
+ [#t "2016-04-01" "San Francisco" "SF" 10] ; [SF] 0 + 10 => 10
+ [#t "2016-04-02" "San Francisco" "SF" 30] ; [SF] 10 + 30 => 40
+ [#t "2016-04-03" "Long Beach" "LB" 4] ; [LB] 2 + 4 => 6
+ [#t "2016-04-03" "Long Beach" "LBC" 4] ; [LBC] 0 + 4 => 4
+ [#t "2016-04-04" "San Francisco" "SF" 40] ; [SF] 40 + 40 => 80
+ [#t "2016-04-06" "Long Beach" "LB" 8] ; [LB] 6 + 8 => 14
+ [#t "2016-04-06" "Long Beach" "LBC" 8]] ; [LBC] 4 + 8 => 12
+ rff (qp.cumulative-aggregations/sum-cumulative-aggregation-columns
+ {:stages [{:breakout [:a :b :c]
+ ::qp.cumulative-aggregations/replaced-indexes #{3}}]}
+ (fn [_metadata]
+ conj))
+ rf (rff nil)]
+ (is (= [[#t "2016-04-01" "Long Beach" "LB" 2] ; [LB] 0 + 2 => 2
+ [#t "2016-04-01" "San Francisco" "SF" 10] ; [SF] 0 + 10 => 10
+ [#t "2016-04-02" "San Francisco" "SF" 40] ; [SF] 10 + 30 => 40
+ [#t "2016-04-03" "Long Beach" "LB" 6] ; [LB] 2 + 4 => 6
+ [#t "2016-04-03" "Long Beach" "LBC" 4] ; [LBC] 0 + 4 => 4
+ [#t "2016-04-04" "San Francisco" "SF" 80] ; [SF] 40 + 40 => 80
+ [#t "2016-04-06" "Long Beach" "LB" 14] ; [LB] 6 + 8 => 14
+ [#t "2016-04-06" "Long Beach" "LBC" 12]] ; [LBC] 4 + 8 => 12
+ (reduce rf [] rows)))))))