Skip to content
Snippets Groups Projects
Commit e550b521 authored by Tom Robinson's avatar Tom Robinson Committed by GitHub
Browse files

Merge pull request #4037 from metabase/fix-download-row-limits

CSV/JSON download limits
parents a3d9bec2 7d5b199f
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@ import DownloadButton from "metabase/components/DownloadButton.jsx";
import FieldSet from "metabase/components/FieldSet.jsx";
import _ from "underscore";
const DownloadWidget = ({ className, card, datasetQuery, isLarge }) =>
<PopoverWithTrigger
triggerElement={<Icon className={className} title="Download this data" name='download' size={16} />}
......@@ -29,7 +31,8 @@ const DownloadWidget = ({ className, card, datasetQuery, isLarge }) =>
}
params={card.id != null ?
{ parameters: JSON.stringify(datasetQuery.parameters) } :
{ query: JSON.stringify(datasetQuery) }
// exclude `constraints` to ensure we download all rows (up to hard-coded 1M):
{ query: JSON.stringify(_.omit(datasetQuery, "constraints")) }
}
extensions={[type]}
>
......
......@@ -324,12 +324,12 @@
;;; ------------------------------------------------------------ Running a Query ------------------------------------------------------------
(defn- run-query-for-card [card-id parameters]
(defn- run-query-for-card [card-id parameters constraints]
{:pre [(u/maybe? sequential? parameters)]}
(let [card (read-check Card card-id)
query (assoc (:dataset_query card)
:parameters parameters
:constraints dataset-api/query-constraints)
:constraints constraints)
options {:executed-by *current-user-id*
:card-id card-id}]
(qp/dataset-query query options)))
......@@ -337,19 +337,19 @@
(defendpoint POST "/:card-id/query"
"Run the query associated with a Card."
[card-id :as {{:keys [parameters]} :body}]
(run-query-for-card card-id parameters))
(run-query-for-card card-id parameters dataset-api/query-constraints))
(defendpoint POST "/:card-id/query/csv"
"Run the query associated with a Card, and return its results as CSV. Note that this expects the parameters as serialized JSON in the 'parameters' parameter"
[card-id parameters]
{parameters (s/maybe su/JSONString)}
(dataset-api/as-csv (run-query-for-card card-id (json/parse-string parameters keyword))))
(dataset-api/as-csv (run-query-for-card card-id (json/parse-string parameters keyword) nil)))
(defendpoint POST "/:card-id/query/json"
"Run the query associated with a Card, and return its results as JSON. Note that this expects the parameters as serialized JSON in the 'parameters' parameter"
[card-id parameters]
{parameters (s/maybe su/JSONString)}
(dataset-api/as-json (run-query-for-card card-id (json/parse-string parameters keyword))))
(dataset-api/as-json (run-query-for-card card-id (json/parse-string parameters keyword) nil)))
(define-routes)
......@@ -85,7 +85,7 @@
{query su/JSONString}
(let [query (json/parse-string query keyword)]
(read-check Database (:database query))
(as-csv (qp/dataset-query query {:executed-by *current-user-id*}))))
(as-csv (qp/dataset-query (dissoc query :constraints) {:executed-by *current-user-id*}))))
(defendpoint POST "/json"
"Execute a query and download the result data as a JSON file."
......@@ -93,7 +93,7 @@
{query su/JSONString}
(let [query (json/parse-string query keyword)]
(read-check Database (:database query))
(as-json (qp/dataset-query query {:executed-by *current-user-id*}))))
(as-json (qp/dataset-query (dissoc query :constraints) {:executed-by *current-user-id*}))))
(define-routes)
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