Skip to content
Snippets Groups Projects
Unverified Commit 7828dc78 authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Add MLv2 schema and functions for `:var` (#29961)

* Add QP test middleware to validate converted pMBQL queries against MLv2 schema

* Revert 'fix' for #29944

* Fix ups

* Hack

* Fix final test failure

* Remove unused namespace

* Fix Kondo warning

* Skip #29958

* Add MLv2 schema for `:var`

* Fix typo

* Additional tests.
parent e14770bd
Branches
Tags
No related merge requests found
(ns metabase.lib.aggregation
(:refer-clojure :exclude [count distinct max min])
(:refer-clojure :exclude [count distinct max min var])
(:require
[metabase.lib.common :as lib.common]
[metabase.lib.hierarchy :as lib.hierarchy]
......@@ -195,6 +195,7 @@
(lib.common/defop stddev [x])
(lib.common/defop sum [x])
(lib.common/defop sum-where [x y])
(lib.common/defop var [x])
(mu/defn aggregate :- ::lib.schema/query
"Adds an aggregation to query."
......
......@@ -2,7 +2,7 @@
"Currently this is mostly a convenience namespace for REPL and test usage. We'll probably have a slightly different
version of this for namespace for QB and QP usage in the future -- TBD."
(:refer-clojure :exclude [filter remove replace and or not = < <= > ->> >= not-empty case count distinct max min
+ - * / time abs concat replace ref])
+ - * / time abs concat replace ref var])
(:require
[metabase.lib.aggregation :as lib.aggregation]
[metabase.lib.breakout :as lib.breakout]
......@@ -63,7 +63,8 @@
share
stddev
sum
sum-where]
sum-where
var]
[lib.breakout
breakout
current-breakouts]
......
......@@ -56,6 +56,9 @@
(lib.hierarchy/derive :sum-where :lib.type-of/type-is-type-of-first-arg)
(mbql-clause/define-tuple-mbql-clause :var :- :type/Float
#_expr [:schema [:ref ::expression/number]])
(mr/def ::aggregation
;; placeholder!
[:or
......@@ -71,6 +74,7 @@
:mbql.clause/stddev
:mbql.clause/sum
:mbql.clause/sum-where
:mbql.clause/var
any?])
(mr/def ::aggregations
......
......@@ -33,7 +33,8 @@
[lib/median :median]
[lib/sum :sum]
[lib/stddev :stddev]
[lib/distinct :distinct]]]
[lib/distinct :distinct]
[lib/var :var]]]
(is-fn? op tag [venues-category-id-metadata] [venue-field-check])))))
(defn- aggregation-display-name [aggregation-clause]
......@@ -252,3 +253,11 @@
:display_name "Sum of Price"
:lib/source :source/aggregations}
(lib.metadata.calculation/metadata query (first (lib/aggregations query -1))))))))
(deftest ^:parallel var-test
(let [query (-> (lib/query-for-table-name meta/metadata-provider "VENUES")
(lib/aggregate (lib/var (lib/field (meta/id :venues :price)))))]
(is (=? {:stages [{:aggregation [[:var {} [:field {} (meta/id :venues :price)]]]}]}
query))
(is (= "Venues, Variance of Price"
(lib.metadata.calculation/describe-query query)))))
......@@ -31,10 +31,6 @@
[legacy-query]
(or
*skip-conversion-tests*
;; #29745: missing schema for `:var`
(mbql.u/match-one legacy-query
:var
"#29745")
;; #29747: schema for `:relative-datetime` current without a unit is broken
(mbql.u/match-one legacy-query
[:relative-datetime :current]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment