Skip to content
Snippets Groups Projects
Unverified Commit b4b8f6e9 authored by lbrdnk's avatar lbrdnk Committed by GitHub
Browse files

Avoid sorting by missing aggregation reference (#46386)

* Update values-from-card-query

* Add test

* Update values-from-card-query

* Add missing issue no
parent 1c7de429
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,7 @@
(-> card :dataset_query :query))]
;; MBQL query - hijack the final stage, drop its aggregation and breakout (if any).
(-> inner-mbql
(dissoc :aggregation)
(dissoc :aggregation :order-by)
(assoc :breakout [value-field-ref])
(update :limit (fnil min *max-rows*) *max-rows*)
(update :filter (fn [old]
......
......@@ -248,3 +248,23 @@
:value_field [:field 0 nil]}}
nil
(constantly mock-default-result))))))))))
(deftest ^:parallel order-by-aggregation-fields-test
(testing "Values could be retrieved for queries containing ordering by aggregation (#46369)"
(doseq [model? [true false]]
(testing (format "source card is a %s" (if model? "model" "question"))
(mt/with-temp
[Card {card-id :id} (merge (-> (mt/mbql-query
products
{:aggregation [[:count]]
:breakout [$category !month.created_at]
:order-by [[:asc [:aggregation 0]]]})
mt/card-with-source-metadata-for-query)
{:database_id (mt/id)
:type (if model? :model :question)
:table_id (mt/id :products)})]
(is (= {:has_more_values false
:values [["Doohickey"] ["Gadget"] ["Gizmo"] ["Widget"]]}
(custom-values/values-from-card
(t2/select-one Card :id card-id)
(mt/$ids $products.category)))))))))
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