Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertica: prevent overwriting row data when duplicated column names exist #4201

Merged
merged 3 commits into from
Oct 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I stumbled upon this commit while rebasing my work on master.
Tell me if I'm missing something but it looks like column_data is not defined anywhere. Shouldn't it be columns_data?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😳 of course you're right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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