mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
More logging to csv endpoint (#3164)
This commit is contained in:
parent
c34df3eea4
commit
d01e67a159
@ -2061,6 +2061,7 @@ class Superset(BaseSupersetView):
|
|||||||
@log_this
|
@log_this
|
||||||
def csv(self, client_id):
|
def csv(self, client_id):
|
||||||
"""Download the query results as csv."""
|
"""Download the query results as csv."""
|
||||||
|
logging.info("Exporting CSV file [{}]".format(client_id))
|
||||||
query = (
|
query = (
|
||||||
db.session.query(Query)
|
db.session.query(Query)
|
||||||
.filter_by(client_id=client_id)
|
.filter_by(client_id=client_id)
|
||||||
@ -2074,14 +2075,20 @@ class Superset(BaseSupersetView):
|
|||||||
return redirect('/')
|
return redirect('/')
|
||||||
blob = None
|
blob = None
|
||||||
if results_backend and query.results_key:
|
if results_backend and query.results_key:
|
||||||
|
logging.info(
|
||||||
|
"Fetching CSV from results backend "
|
||||||
|
"[{}]".format(query.results_key))
|
||||||
blob = results_backend.get(query.results_key)
|
blob = results_backend.get(query.results_key)
|
||||||
if blob:
|
if blob:
|
||||||
|
logging.info("Decompressing")
|
||||||
json_payload = utils.zlib_decompress_to_string(blob)
|
json_payload = utils.zlib_decompress_to_string(blob)
|
||||||
obj = json.loads(json_payload)
|
obj = json.loads(json_payload)
|
||||||
columns = [c['name'] for c in obj['columns']]
|
columns = [c['name'] for c in obj['columns']]
|
||||||
df = pd.DataFrame.from_records(obj['data'], columns=columns)
|
df = pd.DataFrame.from_records(obj['data'], columns=columns)
|
||||||
|
logging.info("Using pandas to convert to CSV")
|
||||||
csv = df.to_csv(index=False, encoding='utf-8')
|
csv = df.to_csv(index=False, encoding='utf-8')
|
||||||
else:
|
else:
|
||||||
|
logging.info("Running a query to turn into CSV")
|
||||||
sql = query.select_sql or query.executed_sql
|
sql = query.select_sql or query.executed_sql
|
||||||
df = query.database.get_df(sql, query.schema)
|
df = query.database.get_df(sql, query.schema)
|
||||||
# TODO(bkyryliuk): add compression=gzip for big files.
|
# TODO(bkyryliuk): add compression=gzip for big files.
|
||||||
@ -2089,6 +2096,7 @@ class Superset(BaseSupersetView):
|
|||||||
response = Response(csv, mimetype='text/csv')
|
response = Response(csv, mimetype='text/csv')
|
||||||
response.headers['Content-Disposition'] = (
|
response.headers['Content-Disposition'] = (
|
||||||
'attachment; filename={}.csv'.format(query.name))
|
'attachment; filename={}.csv'.format(query.name))
|
||||||
|
logging.info("Ready to return response")
|
||||||
return response
|
return response
|
||||||
|
|
||||||
@has_access
|
@has_access
|
||||||
|
Loading…
Reference in New Issue
Block a user