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

Disambiguate duplicate native cols (#12345)

parent 1bfb2c12
No related branches found
No related tags found
No related merge requests found
......@@ -75,7 +75,7 @@
(defn- native-column-info-for-a-single-column
"Determine column metadata for a single column for native query results."
[{col-name :name, driver-base-type :base_type, :as col} values-sample]
[unique-name-fn {col-name :name, driver-base-type :base_type, :as col} values-sample]
;; Native queries don't have the type information from the original `Field` objects used in the query.
;;
;; If the driver returned a base type more specific than :type/*, use that; otherwise look at the sample
......@@ -94,14 +94,14 @@
;; `:field-literal` clauses, because `SELECT ""` doesn't make any sense. So if we can't return a valid
;; `:field-literal`, omit the `:field_ref`.
(when (seq col-name)
{:field_ref [:field-literal col-name base-type]})
{:field_ref [:field-literal (unique-name-fn col-name) base-type]})
col
{:base_type base-type})))
(defmethod column-info :native
[_ {:keys [cols rows]}]
(check-driver-native-columns cols rows)
(mapv native-column-info-for-a-single-column
(mapv (partial native-column-info-for-a-single-column (mbql.u/unique-name-generator))
cols
(for [i (range (count cols))]
(for [row rows]
......
......@@ -43,7 +43,15 @@
(annotate/merged-column-info
{:type :native}
{:cols [{:name "a", :base_type :type/*}]
:rows [[1] [2] [nil] [3]]}))))))
:rows [[1] [2] [nil] [3]]}))))
(testing "should disambiguate duplicate names"
(is (= [{:name "a", :display_name "a", :base_type :type/Integer, :source :native, :field_ref [:field-literal "a" :type/Integer]}
{:name "a", :display_name "a", :base_type :type/Integer, :source :native, :field_ref [:field-literal "a_2" :type/Integer]}]
(annotate/column-info
{:type :native}
{:cols [{:name "a"} {:name "a"}]
:rows [[1 nil] [2 nil] [3 nil] [4 5] [6 7]]}))))))
;;; +----------------------------------------------------------------------------------------------------------------+
......
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