Skip to content
Snippets Groups Projects
Commit 8f1eb1e2 authored by Simon Belak's avatar Simon Belak
Browse files

Test complex share predicate

parent 75f9058a
Branches
Tags
No related merge requests found
......@@ -444,10 +444,14 @@
(defmethod expand-aggregation :default
[ag]
(println ag)
[[[(annotate/aggregation-name ag) (aggregation->rvalue ag)]]])
(defn- group-and-post-aggregations
"Mongo is picky (and somewhat stupid) which top-level aggregations it alows with groups. Eg. even
though [:/ [:coun-if ...] [:count]] is a perfectly fine reduction, it's not allowed. Therefore
more complex aggregations are split in two: the reductions are done in `$group` stage after which
we do postprocessing in `$addFields` stage to arrive at the final result. The intermitent results
accrued in `$group` stage are discarded in the final `$project` stage."
[id aggregations]
(let [expanded-ags (map expand-aggregation aggregations)
group-ags (mapcat first expanded-ags)
......
......@@ -3,7 +3,9 @@
[metric :refer [Metric]]
[segment :refer [Segment]]]
[metabase.query-processor-test :refer :all]
[metabase.test.data :as data]
[metabase.test
[data :as data]
[util :as tu]]
[metabase.test.data.datasets :as datasets]
[toucan.util.test :as tt]))
......@@ -15,6 +17,16 @@
ffirst
double))
(datasets/expect-with-drivers (non-timeseries-drivers-with-feature :basic-aggregations)
0.17
(->> {:aggregation [[:share [:and [:< [:field-id (data/id :venues :price)] 4]
[:or [:starts-with [:field-id (data/id :venues :name)] "M"]
[:ends-with [:field-id (data/id :venues :name)] "t"]]]]]}
(data/run-mbql-query venues)
rows
ffirst
double))
(datasets/expect-with-drivers (non-timeseries-drivers-with-feature :basic-aggregations)
nil
(->> {:aggregation [[:share [:< [:field-id (data/id :venues :price)] 4]]]
......@@ -24,14 +36,15 @@
ffirst))
(datasets/expect-with-drivers (non-timeseries-drivers-with-feature :basic-aggregations)
[[2 0M]
[3 0M]
[4 0.5M]
[5 0.14285714285714285714285714M]]
[[2 0.0]
[3 0.0]
[4 0.5]
[5 0.14]]
(->> {:aggregation [[:share [:< [:field-id (data/id :venues :price)] 2]]]
:breakout [[:field-id (data/id :venues :category_id)]]
:limit 4}
(data/run-mbql-query venues)
(tu/round-all-decimals 2)
rows))
(datasets/expect-with-drivers (non-timeseries-drivers-with-feature :basic-aggregations)
......
......@@ -440,7 +440,7 @@
(defn round-all-decimals
"Uses `walk/postwalk` to crawl `data`, looking for any double values, will round any it finds"
[decimal-place data]
(postwalk-pred double?
(postwalk-pred (some-fn double? decimal?)
#(u/round-to-decimals decimal-place %)
data))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment