Skip to content
Snippets Groups Projects
Unverified Commit aab206cb authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan Committed by GitHub
Browse files

expressions->subselect: exclude fields used only inside expressions (#18065)

The expressions are executed inside the sub-query, so the fields do not need to be exposed outside.
parent a4a4e9cb
No related branches found
No related tags found
No related merge requests found
......@@ -316,7 +316,7 @@ describe("scenarios > question > custom columns", () => {
});
});
it.skip("should handle identical custom column and table column names (metabase#14255)", () => {
it("should handle identical custom column and table column names (metabase#14255)", () => {
// Uppercase is important for this reproduction on H2
const CC_NAME = "CATEGORY";
......
......@@ -1067,7 +1067,7 @@
[driver query]
(let [subselect (-> query
(select-keys [:joins :source-table :source-query :source-metadata :expressions])
(assoc :fields (-> (mbql.u/match (dissoc query :source-query :joins)
(assoc :fields (-> (mbql.u/match (dissoc query :source-query :joins :expressions)
;; remove the bucketing/binning operations from the source query -- we'll
;; do that at the parent level
[:field id-or-name opts]
......
......@@ -576,6 +576,7 @@
[:field "count" {:base-type :type/BigInteger, :join-alias "Q2"}]
[:field "count" {:base-type :type/BigInteger}]]}
:limit 2})]
(is (= [[4 41 0.46 41]]
;; This result is actually wrong due to metabase#18086, the correct result is [4 89 0.46 41].
(is (= [[4 89 0.46 89]]
(mt/formatted-rows [int int 2.0 int]
(qp/process-query query))))))))))
......@@ -371,6 +371,19 @@
[:field "max" {:base-type :type/Number}]
[:field "min" {:base-type :type/Number}]]}})))))))
(deftest expression-with-duplicate-column-name
(mt/test-drivers (mt/normal-drivers-with-feature :expressions)
(testing "Can we use expression with same column name as table (#14267)"
(mt/dataset sample-dataset
(is (= [["Doohickey2" 42]]
(mt/formatted-rows [str int]
(mt/run-mbql-query products
{:expressions {:CATEGORY [:concat $category "2"]}
:breakout [:expression :CATEGORY]
:aggregation [:count]
:order-by [[:asc [:expression :CATEGORY]]]
:limit 1}))))))))
(deftest fk-field-and-duplicate-names-test
(mt/test-drivers (mt/normal-drivers-with-feature :expressions :foreign-keys)
(testing "Expressions with `fk->` fields and duplicate names should work correctly (#14854)"
......
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