Skip to content
Snippets Groups Projects
Unverified Commit 38f59c73 authored by Simon Belak's avatar Simon Belak Committed by GitHub
Browse files

MBQL: make mbql.u/field-clause->id-or-field work with expressions (#13242)

* MBQL: make mbql.u/field-clause->id-or-field work with expressions

* Update docs

* Fix test
parent a3459e82
No related branches found
No related tags found
No related merge requests found
......@@ -442,7 +442,7 @@
"Unwrap a Field `clause`, if it's something that can be unwrapped (i.e. something that is, or wraps, a `:field-id` or
`:field-literal`). Otherwise return `clause` as-is."
[clause]
(if (is-clause? #{:field-id :fk-> :field-literal :datetime-field :binning-strategy} clause)
(if (is-clause? #{:field-id :fk-> :field-literal :datetime-field :binning-strategy :joined-field} clause)
(unwrap-field-clause clause)
clause))
......@@ -453,10 +453,9 @@
(field-clause->id-or-literal [:datetime-field [:field-id 100] ...]) ; -> 100
(field-clause->id-or-literal [:field-id 100]) ; -> 100
For expressions (or any other clauses) this returns the clause as-is, so as to facilitate the primary use case of
comparing Field clauses."
For expressions returns the expression name."
[clause :- mbql.s/Field]
(second (unwrap-field-clause clause)))
(second (maybe-unwrap-field-clause clause)))
(s/defn add-order-by-clause :- mbql.s/MBQLQuery
"Add a new `:order-by` clause to an MBQL `inner-query`. If the new order-by clause references a Field that is
......
......@@ -1059,3 +1059,15 @@
:query {:source-query {:expressions {:two [:+ 1 1]}
:source-table 1}}}
"two"))
(expect
1
(mbql.u/field-clause->id-or-literal [:field-id 1]))
(expect
"foo"
(mbql.u/field-clause->id-or-literal [:field-literal "foo" :type/Integer]))
(expect
"foo"
(mbql.u/field-clause->id-or-literal [:expression "foo"]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment