Skip to content

Commit 04ba451

Browse files
authored
Merge pull request #10 from thalesmg/s-query-partitions-mkIII
feat(spark-query): add more ways to check partitions
2 parents a515037 + 8478b0e commit 04ba451

2 files changed

Lines changed: 30 additions & 13 deletions

File tree

spark-query/src/spark_query/core.clj

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,19 @@
7575
iterator-seq
7676
(into [])))
7777

78-
(defn table-partitions
78+
(defn partition-data->vec
79+
[pdata]
80+
(let [size (.size pdata)
81+
fields (->> pdata
82+
.getPartitionType
83+
.fields
84+
(mapv #(.name %)))
85+
values (mapv #(.get pdata %) (range size))]
86+
(zipmap fields values)))
87+
88+
(defn table-partitions-from-meta
7989
[table]
80-
(letfn [(partition-data->vec [pdata]
81-
(let [size (.size pdata)
82-
fields (->> pdata
83-
.getPartitionType
84-
.fields
85-
(mapv #(.name %)))
86-
values (mapv #(.get pdata %) (range size))]
87-
(zipmap fields values)))
88-
(content-data-file->vec [content-data-file]
90+
(letfn [(content-data-file->vec [content-data-file]
8991
(-> content-data-file
9092
.partition
9193
partition-data->vec))]
@@ -94,6 +96,18 @@
9496
(.addedDataFiles (.io table))
9597
(->> (map content-data-file->vec)))))
9698

99+
(defn table-partitions-from-data
100+
[table]
101+
(-> table
102+
.newScan
103+
.planTasks
104+
.iterator
105+
iterator-seq
106+
(->> (mapcat #(.files %))
107+
(map #(-> %
108+
.partition
109+
partition-data->vec)))))
110+
97111
(defn handle-scan-table [ns-in table-in]
98112
(let [table (load-table (get-catalog) ns-in table-in)
99113
rows (scan-table table)
@@ -104,8 +118,11 @@
104118

105119
(defn handle-table-partitions [ns-in table-in]
106120
(let [table (load-table (get-catalog) ns-in table-in)
107-
partitions (table-partitions table)
108-
response-body (json/write-str partitions)]
121+
partitions-from-meta (table-partitions-from-meta table)
122+
partitions-from-data (table-partitions-from-data table)
123+
response {:from-data partitions-from-data
124+
:from-meta partitions-from-meta}
125+
response-body (json/write-str response)]
109126
{:body response-body}))
110127

111128
(defroutes app-routes

spark-query/vsn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.2
1+
1.0.3

0 commit comments

Comments
 (0)