Skip to content

Commit

Permalink
Vertica: prevent overwriting row data when duplicated column names ex…
Browse files Browse the repository at this point in the history
…ist (#4201)

* Vertica: prevent overwriting row data when duplicated column names exist

* remove enumeration
  • Loading branch information
rz269 authored and arikfr committed Oct 2, 2019
1 parent e8ccdc2 commit f6ad3d9
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions redash/query_runner/vertica.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,12 @@ def run_query(self, query, user):
logger.debug("Vertica running query: %s", query)
cursor.execute(query)

# TODO - very similar to pg.py
if cursor.description is not None:
columns_data = [(i[0], i[1]) for i in cursor.description]

# bug -- same name columns will always be assigned single last value
# corrected with fetch_columns in pull request https://github.com/getredash/redash/pull/4201
rows = [dict(zip((c[0] for c in columns_data), row)) for row in cursor.fetchall()]
columns = [{'name': col[0],
'friendly_name': col[0],
'type': types_map.get(col[1], None)} for col in columns_data]
columns_data = [(i[0], types_map.get(i[1], None)) for i in cursor.description]

columns = self.fetch_columns(column_data)
rows = [dict(zip(([c['name'] for c in columns]), r))
for r in cursor.fetchall()]

data = {'columns': columns, 'rows': rows}
json_data = json_dumps(data)
Expand Down

0 comments on commit f6ad3d9

Please sign in to comment.