Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Util function fixes; enable schemas in dev & tests (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
camsaul committed Jul 12, 2019
1 parent c118b40 commit a1d46ff
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 4 additions & 2 deletions project.clj
@@ -1,4 +1,4 @@
(defproject metabase/mbql "1.3.0"
(defproject metabase/mbql "1.3.1"
:description "Shared things used across several Metabase projects, such as i18n and config."
:url "https://github.com/metabase/mbql"
:min-lein-version "2.5.0"
Expand Down Expand Up @@ -31,7 +31,9 @@

:injections
[(require 'expectations)
((resolve 'expectations/disable-run-on-shutdown))]
(#'expectations/disable-run-on-shutdown)
(require 'schema.core)
(schema.core/set-fn-validation! true)]

:jvm-opts
["-Xverify:none"]}
Expand Down
4 changes: 2 additions & 2 deletions src/metabase/mbql/schema.clj
Expand Up @@ -636,8 +636,8 @@
implicit joins; for explicit joins, you *must* specify `:alias` yourself; you can then reference Fields by using a
`:joined-field` clause, e.g.
[:joined-field \"my_join_alias\" [:field-id 1]] ; for joins against other Tabless
[:joined-field \"my_join_alias\" [:field-literal \"my_field\"]] ; for joins against nested queries"
[:joined-field \"my_join_alias\" [:field-id 1]] ; for joins against other Tabless
[:joined-field \"my_join_alias\" [:field-literal \"my_field\" :field/Integer]] ; for joins against nested queries"
(->
{;; *What* to JOIN. Self-joins can be done by using the same `:source-table` as in the query where this is specified.
;; YOU MUST SUPPLY EITHER `:source-table` OR `:source-query`, BUT NOT BOTH!
Expand Down
6 changes: 3 additions & 3 deletions src/metabase/mbql/util.clj
Expand Up @@ -485,15 +485,15 @@
(def ^:private NamedAggregation
(s/constrained
mbql.s/aggregation-options
:name
#(:name (nth % 2))
"`:aggregation-options` with a `:name`"))

(def ^:private UniquelyNamedAggregations
(s/constrained
[NamedAggregation]
(fn [clauses]
(distinct? (for [[_ _ {ag-name :name}] clauses]
ag-name)))
(apply distinct? (for [[_ _ {ag-name :name}] clauses]
ag-name)))
"sequence of named aggregations with unique names"))

(s/defn uniquify-named-aggregations :- UniquelyNamedAggregations
Expand Down
10 changes: 6 additions & 4 deletions test/metabase/mbql/util_test.clj
Expand Up @@ -696,11 +696,11 @@
(expect
[[:aggregation-options [:sum [:field-id 1]] {:name "sum"}]
[:aggregation-options [:sum [:field-id 1]] {:name "sum_2"}]
[:aggregation-options [:sum [:field-id 1]] {:name "sum_2_2", :display_name "Sum of Field 1"}]]
[:aggregation-options [:sum [:field-id 1]] {:name "sum_2_2", :display-name "Sum of Field 1"}]]
(mbql.u/pre-alias-and-uniquify-aggregations simple-ag->name
[[:sum [:field-id 1]]
[:sum [:field-id 1]]
[:aggregation-options [:sum [:field-id 1]] {:name "sum_2", :display_name "Sum of Field 1"}]]))
[:aggregation-options [:sum [:field-id 1]] {:name "sum_2", :display-name "Sum of Field 1"}]]))


;;; --------------------------------------------- query->max-rows-limit ----------------------------------------------
Expand Down Expand Up @@ -806,9 +806,11 @@
[:joined-field "a" [:field-id 10]]
(mbql.u/->joined-field "a" [:field-id 10]))

(derive :type/Integer :type/*)

(expect
[:joined-field "a" [:field-literal "ABC" :type/Integer]]
(mbql.u/->joined-field "a" [:field-literal "ABC" :type/Integer]))
[:joined-field "a" [:field-literal "ABC" :type/Integer]]
(mbql.u/->joined-field "a" [:field-literal "ABC" :type/Integer]))

(expect
[:datetime-field [:joined-field "a" [:field-id 1]] :month]
Expand Down

0 comments on commit a1d46ff

Please sign in to comment.