Skip to content
Snippets Groups Projects
Commit 19e495db authored by Simon Belak's avatar Simon Belak Committed by Cam Saul
Browse files

Generate correct query when no DB supports nested queries (#12527)

parent 2e9e16b5
No related branches found
No related tags found
No related merge requests found
......@@ -123,19 +123,20 @@
(defn- source-query-cards
"Fetch the Cards that can be used as source queries (e.g. presented as virtual tables)."
[& {:keys [additional-constraints xform], :or {xform identity}}]
(transduce
(comp (filter card-can-be-used-as-source-query?) xform)
(completing conj #(hydrate % :collection))
[]
(db/select-reducible [Card :name :description :database_id :dataset_query :id :collection_id :result_metadata]
{:where (into [:and
[:not= :result_metadata nil]
[:= :archived false]
[:in :database_id (ids-of-dbs-that-support-source-queries)]
(collection/visible-collection-ids->honeysql-filter-clause
(collection/permissions-set->visible-collection-ids @api/*current-user-permissions-set*))]
additional-constraints)
:order-by [[:%lower.name :asc]]})))
(when-let [ids-of-dbs-that-support-source-queries (not-empty (ids-of-dbs-that-support-source-queries))]
(transduce
(comp (filter card-can-be-used-as-source-query?) xform)
(completing conj #(hydrate % :collection))
[]
(db/select-reducible [Card :name :description :database_id :dataset_query :id :collection_id :result_metadata]
{:where (into [:and
[:not= :result_metadata nil]
[:= :archived false]
[:in :database_id ids-of-dbs-that-support-source-queries]
(collection/visible-collection-ids->honeysql-filter-clause
(collection/permissions-set->visible-collection-ids @api/*current-user-permissions-set*))]
additional-constraints)
:order-by [[:%lower.name :asc]]}))))
(defn- source-query-cards-exist?
"Truthy if a single Card that can be used as a source query exists."
......
......@@ -441,6 +441,10 @@
saved-questions-virtual-db)
(fetch-virtual-database)))))
(testing "should work when there are no DBs that support nested queries"
(with-redefs [metabase.driver/supports? (constantly false)]
(is (nil? (fetch-virtual-database)))))
(testing "should remove Cards that use cumulative-sum and cumulative-count aggregations"
(mt/with-temp* [Card [ok-card (ok-mbql-card)]
Card [_ (merge
......
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