Skip to content
Snippets Groups Projects
Commit a989d4f6 authored by Cam Saul's avatar Cam Saul
Browse files

"$$aggregation" -> ["aggregation" 0] :smirk:

parent 3fe1b1e7
Branches
Tags
No related merge requests found
......@@ -360,7 +360,7 @@ var GuiQueryEditor = React.createClass({
if (this.canSortByAggregateField()) {
breakoutFieldList.push({
id: '$$aggregation',
id: ["aggregation", 0],
name: this.props.query.query.aggregation[0] // e.g. "sum"
});
}
......
......@@ -176,17 +176,17 @@
(when-not (empty? order-by-pairs)
(->> order-by-pairs
(map (fn [pair] (when-not (vector? pair) (throw (Exception. "order_by clause must consists of pairs like [field_id \"ascending\"]"))) pair))
(mapv (fn [[field-id asc-desc]]
(mapv (fn [[field asc-desc]]
{:pre [(string? asc-desc)]}
`(order ~(cond
(integer? field-id) (field-id->kw field-id)
(= field-id "$$aggregation") (let [[ag] (:aggregation (:query qp/*query*))]
`(raw ~(case ag
"avg" "\"avg\"" ; based on the type of the aggregation
"count" "\"count\"" ; make sure we ask the DB to order by the
"distinct" "\"count\"" ; name of the aggregate field
"stddev" "\"stddev\""
"sum" "\"sum\""))))
`(order ~(match [field]
[field-id :guard integer?] (field-id->kw field-id)
[["aggregation" 0]] (let [[ag] (:aggregation (:query qp/*query*))]
`(raw ~(case ag
"avg" "\"avg\"" ; based on the type of the aggregation
"count" "\"count\"" ; make sure we ask the DB to order by the
"distinct" "\"count\"" ; name of the aggregate field
"stddev" "\"stddev\""
"sum" "\"sum\""))))
~(case asc-desc
"ascending" :ASC
"descending" :DESC)))))))
......
......@@ -642,7 +642,7 @@
{:source_table (id :venues)
:aggregation ["count"]
:breakout [(id :venues :price)]
:order_by [["$$aggregation" "ascending"]]})
:order_by [[["aggregation" 0] "ascending"]]})
;;; ### order_by aggregate ["sum" field-id]
......@@ -658,7 +658,7 @@
{:source_table (id :venues)
:aggregation ["sum" (id :venues :id)]
:breakout [(id :venues :price)]
:order_by [["$$aggregation" "descending"]]})
:order_by [[["aggregation" 0] "descending"]]})
;;; ### order_by aggregate ["distinct" field-id]
......@@ -674,7 +674,7 @@
{:source_table (id :venues)
:aggregation ["distinct" (id :venues :id)]
:breakout [(id :venues :price)]
:order_by [["$$aggregation" "ascending"]]})
:order_by [[["aggregation" 0] "ascending"]]})
;;; ### order_by aggregate ["avg" field-id]
......@@ -690,7 +690,7 @@
{:source_table (id :venues)
:aggregation ["avg" (id :venues :category_id)]
:breakout [(id :venues :price)]
:order_by [["$$aggregation" "ascending"]]})
:order_by [[["aggregation" 0] "ascending"]]})
;;; ### order_by aggregate ["stddev" field-id]
(qp-expect-with-datasets #{:generic-sql}
......@@ -705,4 +705,4 @@
{:source_table (id :venues)
:aggregation ["stddev" (id :venues :category_id)]
:breakout [(id :venues :price)]
:order_by [["$$aggregation" "descending"]]})
:order_by [[["aggregation" 0] "descending"]]})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment