Skip to content
Snippets Groups Projects
Unverified Commit 677f2eca authored by github-automation-metabase's avatar github-automation-metabase Committed by GitHub
Browse files

XLSX Pivot Exports Now Use The Sort Settings from Viz Settings (#50099) (#50103)


* XLSX Pivot Exports Now Use The Sort Settings from Viz Settings

Prior to this PR, the xlsx pivot exports worked correctly except for the fact that no sorting (ascending or
descending) was applied to the pivot rows or columns. Now, those settings are used when they exist.

* only try to set sort when a correct setting exists

* add ooxml-full dep for correct classes

* Update src/metabase/query_processor/streaming/xlsx.clj



---------

Co-authored-by: default avataradam-james <21064735+adam-james-v@users.noreply.github.com>
Co-authored-by: default avatarNoah Moss <32746338+noahmoss@users.noreply.github.com>
parent cb44d0af
No related branches found
No related tags found
No related merge requests found
......@@ -125,6 +125,7 @@
org.apache.poi/poi-ooxml {:mvn/version "5.2.5"
:exclusions [org.bouncycastle/bcpkix-jdk15on
org.bouncycastle/bcprov-jdk15on]}
org.apache.poi/poi-ooxml-full {:mvn/version "5.2.5"}
org.apache.sshd/sshd-core {:mvn/version "2.12.1" ; ssh tunneling and test server
:exclusions [org.slf4j/slf4j-api
org.slf4j/jcl-over-slf4j]}
......
......@@ -25,7 +25,8 @@
(org.apache.poi.ss.usermodel Cell DataConsolidateFunction DataFormat DateUtil Workbook)
(org.apache.poi.ss.util AreaReference CellRangeAddress CellReference)
(org.apache.poi.xssf.streaming SXSSFRow SXSSFSheet SXSSFWorkbook)
(org.apache.poi.xssf.usermodel XSSFPivotTable XSSFRow XSSFSheet XSSFWorkbook)))
(org.apache.poi.xssf.usermodel XSSFPivotTable XSSFRow XSSFSheet XSSFWorkbook)
(org.openxmlformats.schemas.spreadsheetml.x2006.main STFieldSortType)))
(set! *warn-on-reflection* true)
......@@ -576,7 +577,7 @@
;; Since we're the ones creating the file, we can lower the ratio to get what we want.
(ZipSecureFile/setMinInflateRatio 0.001)
(defn- init-native-pivot
[{:keys [pivot-grouping-key] :as pivot-spec}
[{:keys [pivot-grouping-key column-sort-order] :as pivot-spec}
{:keys [ordered-cols col-settings viz-settings format-rows?]}]
(let [idx-shift (fn [indices]
(map (fn [idx]
......@@ -612,6 +613,16 @@
(.addColLabel pivot-table idx))
(doseq [idx pivot-measures]
(.addColumnLabel pivot-table DataConsolidateFunction/SUM #_(get aggregation-functions idx DataConsolidateFunction/SUM) idx))
(doseq [[idx sort-setting] column-sort-order]
(let [setting (case sort-setting
:ascending STFieldSortType/ASCENDING
:descending STFieldSortType/DESCENDING)]
(when setting
(-> pivot-table
.getCTPivotTableDefinition
.getPivotFields
(.getPivotFieldArray idx)
(.setSortType setting)))))
(let [swb (-> (SXSSFWorkbook. ^XSSFWorkbook wb)
(doto (.setCompressTempFiles true)))
sheet (spreadsheet/select-sheet "data" swb)]
......
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