Skip to content
Snippets Groups Projects
Unverified Commit 87d4e587 authored by Case Nelson's avatar Case Nelson Committed by GitHub
Browse files

Include field annotations for native queries too (#22962)

* Include field annotations for native queries too

Persistence will replace a source-table source-query with a native
query, but preprocess has still filled in source-metadata with all of
the relevant field-ids expected to be returned. With this change we
include field info from the store in the same way that mbql-cols does.
This allows persisted models to honor field settings like `:visibility
:details-only`.

* Force type of merge-source-metadata-col to map

By doing the lookup to store/field at the top of the merge, the type of
annotations coming through was a FieldInstance. Tests, at least, were
unhappy about this and it's better not to change it.

* Resolve fields for ids in source-metadata

Makes sure that the qp/store has all the available fields for
annotations.

* Recursively find source-metadata field-ids for annotations

* Use transducer as per review
parent 6e64e2ce
Branches
Tags
No related merge requests found
......@@ -494,6 +494,9 @@
(s/defn ^:private merge-source-metadata-col :- (s/maybe su/Map)
[source-metadata-col :- (s/maybe su/Map) col :- (s/maybe su/Map)]
(merge
{} ;; ensure the type is not FieldInstance
(when-let [field-id (:id source-metadata-col)]
(dissoc (qp.store/field field-id) :database_type))
source-metadata-col
col
;; pass along the unit from the source query metadata if the top-level metadata has unit `:default`. This way the
......
......@@ -15,7 +15,9 @@
(defn resolve-fields
"Resolve all field referenced in the `query`, and store them in the QP Store."
[query]
(let [ids (set (mbql.u/match (:query query) [:field (id :guard integer?) _] id))]
(let [ids (into (set (mbql.u/match (:query query) [:field (id :guard integer?) _] id))
(comp cat (keep :id))
(mbql.u/match (:query query) {:source-metadata source-metadata} source-metadata))]
(try
(u/prog1 query
(resolve-fields-with-ids! ids))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment