Skip to content

Commit

Permalink
Add support for timestamps
Browse files Browse the repository at this point in the history
Fix the type field
  • Loading branch information
jeremi committed Jun 27, 2014
1 parent 4cb97db commit b2fea7f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions redash/data/query_runner_bigquery.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import httplib2
import json
import logging
Expand All @@ -15,6 +16,14 @@

from redash.utils import JSONEncoder

types_map = {
'INTEGER': 'integer',
'FLOAT': 'float',
'BOOLEAN': 'boolean',
'STRING': 'string',
'TIMESTAMP': 'datetime',
}

def transform_row(row, fields):
column_index = 0
row_data = {}
Expand All @@ -28,12 +37,12 @@ def transform_row(row, fields):
# Otherwise just cast the value
elif field['type'] == 'INTEGER':
cell_value = int(cell_value)

elif field['type'] == 'FLOAT':
cell_value = float(cell_value)

elif field['type'] == 'BOOLEAN':
cell_value = cell_value in ('True', 'true', 'TRUE')
cell_value = cell_value.lower() == "true"
elif field['type'] == 'TIMESTAMP':
cell_value = datetime.datetime.fromtimestamp(float(cell_value))

row_data[field["name"]] = cell_value
column_index += 1
Expand Down Expand Up @@ -105,7 +114,7 @@ def query_runner(query):

columns = [{'name': f["name"],
'friendly_name': f["name"],
'type': None} for f in query_reply["schema"]["fields"]]
'type': types_map.get(f['type'], "string")} for f in query_reply["schema"]["fields"]]

data = {
"columns": columns,
Expand Down

0 comments on commit b2fea7f

Please sign in to comment.