The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
pivot download: use source alias name for matching columns (#64192)
Oleksandr Solovyov4e7e3f10bc2e
diff --git a/src/metabase/query_processor/pivot.clj b/src/metabase/query_processor/pivot.cljindex fa928b16c34..1ddf4bd2c12 100644--- a/src/metabase/query_processor/pivot.clj+++ b/src/metabase/query_processor/pivot.clj@@ -391,16 +391,12 @@aggregations (filter #(= (:lib/source %) :source/aggregations)returned-columns)breakouts (filter :lib/breakout? returned-columns)- column-alias->index (into {}- (map-indexed (fn [i column] [(:lib/desired-column-alias column) i]))- (concat breakouts aggregations))column-name->index (into {}- (map-indexed (fn [i column] [(:name column) i]))+ (map-indexed (fn [i column] [(:lib/deduplicated-name column) i]))(concat breakouts aggregations))process-columns (fn process-columns [column-names](when (seq column-names)- (into [] (keep (fn [n] (or (column-alias->index n)- (column-name->index n)))) column-names)))+ (into [] (keep column-name->index) column-names)))pivot-opts {:pivot-rows (process-columns rows):pivot-cols (process-columns columns):pivot-measures (process-columns values)diff --git a/test/metabase/api/downloads_exports_test.clj b/test/metabase/api/downloads_exports_test.cljindex e88b1254728..3369d82cc5f 100644--- a/test/metabase/api/downloads_exports_test.clj+++ b/test/metabase/api/downloads_exports_test.clj@@ -1777,3 +1777,27 @@["3" "300.0" "" "300.0"]["Grand totals" "200.0" "100.0" "175.0"]](rest result))))))))++(deftest ^:parallel pivot-long-column-names-download-test+ (testing "Pivot table downloads should include columns with very long names that are present in frontend"+ (let [long-title (apply str (repeat 10 "Long title"))]+ (mt/dataset test-data+ (mt/with-temp [:model/Card pivot-card+ {:display :pivot+ :visualization_settings {:pivot_table.column_split+ {:columns ["CATEGORY"]+ :rows ["VENDOR"]+ :values ["sum" long-title]}}+ :dataset_query (mt/mbql-query orders+ {:aggregation [[:sum $total]+ [:aggregation-options [:count] {:name long-title+ :display-name long-title}]]+ :breakout [$product_id->products.category+ $product_id->products.vendor]+ :limit 3})}]++ (testing "download"+ (let [res (card-download pivot-card {:export-format :csv :pivot true :format-rows false})+ headers (second res)]+ (is (= 3 (count headers)))+ (is (some #{long-title} headers)))))))))