Skip to content

Commit

Permalink
Merge pull request #501 from johnkearney/all_pg_queries_with_no_results
Browse files Browse the repository at this point in the history
All pg queries with no results
  • Loading branch information
arikfr committed Jul 21, 2015
2 parents d512cd0 + c4502b2 commit d4a18ba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
15 changes: 6 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
REDASH_CONNECTION_ADAPTER=pg
REDASH_CONNECTION_STRING="dbname=data"
REDASH_STATIC_ASSETS_PATH=../rd_ui/app/
REDASH_GOOGLE_APPS_DOMAIN=
REDASH_ADMINS=
REDASH_WORKERS_COUNT=2
REDASH_COOKIE_SECRET=
REDASH_DATABASE_URL='postgresql://rd'
REDASH_LOG_LEVEL = "INFO"
export REDASH_STATIC_ASSETS_PATH="../rd_ui/app/"
export REDASH_LOG_LEVEL="INFO"
export REDASH_REDIS_URL=redis://localhost:6379/1
export REDASH_DATABASE_URL="postgresql://redash"
export REDASH_COOKIE_SECRET=veryverysecret
export REDASH_GOOGLE_APPS_DOMAIN=
47 changes: 25 additions & 22 deletions redash/query_runner/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,35 +127,38 @@ def run_query(self, query):
columns = []
duplicates_counter = 1

for column in cursor.description:
# TODO: this deduplication needs to be generalized and reused in all query runners.
column_name = column.name
if column_name in column_names:
column_name += str(duplicates_counter)
duplicates_counter += 1

column_names.append(column_name)

columns.append({
'name': column_name,
'friendly_name': column_name,
'type': types_map.get(column.type_code, None)
})

rows = [dict(zip(column_names, row)) for row in cursor]

data = {'columns': columns, 'rows': rows}
json_data = json.dumps(data, cls=JSONEncoder)
error = None
cursor.close()
if cursor.description is not None:
for column in cursor.description:
# TODO: this deduplication needs to be generalized and reused in all query runners.
column_name = column.name
if column_name in column_names:
column_name += str(duplicates_counter)
duplicates_counter += 1

column_names.append(column_name)

columns.append({
'name': column_name,
'friendly_name': column_name,
'type': types_map.get(column.type_code, None)
})

rows = [dict(zip(column_names, row)) for row in cursor]

data = {'columns': columns, 'rows': rows}
error = None
json_data = json.dumps(data, cls=JSONEncoder)
else:
error = 'Query completed but it returned no data.'
json_data = None
except (select.error, OSError) as e:
logging.exception(e)
error = "Query interrupted. Please retry."
json_data = None
except psycopg2.DatabaseError as e:
logging.exception(e)
json_data = None
error = e.message
json_data = None
except KeyboardInterrupt:
connection.cancel()
error = "Query cancelled by user."
Expand Down
5 changes: 1 addition & 4 deletions setup/files/env
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
export REDASH_CONNECTION_ADAPTER=pg
export REDASH_CONNECTION_STRING="dbname=redash"
export REDASH_STATIC_ASSETS_PATH="../rd_ui/dist/"
export REDASH_LOG_LEVEL="INFO"
export REDASH_WORKERS_COUNT=6
export REDASH_REDIS_URL=redis://localhost:6379/1
export REDASH_DATABASE_URL="postgresql://redash"
export REDASH_COOKIE_SECRET=veryverysecret
export REDASH_GOOGLE_APPS_DOMAIN=
export REDASH_GOOGLE_APPS_DOMAIN=

0 comments on commit d4a18ba

Please sign in to comment.