Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Fix CSV output by encoding to UTF-8 first
Browse files Browse the repository at this point in the history
Closes #20
  • Loading branch information
Cédric Raud committed Oct 4, 2017
1 parent 128b2d6 commit e88e32f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions athena_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def execute(self, statement):

if status == 'SUCCEEDED':
results = self.athena.get_query_results()
headers = [h['Name'] for h in results['ResultSet']['ResultSetMetadata']['ColumnInfo']]
headers = [h['Name'].encode("utf-8") for h in results['ResultSet']['ResultSetMetadata']['ColumnInfo']]

if self.format in ['CSV', 'CSV_HEADER']:
csv_writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL)
if self.format == 'CSV_HEADER':
csv_writer.writerow(headers)
csv_writer.writerows([row for row in self.athena.yield_rows(results, headers)])
csv_writer.writerows([[text.encode("utf-8") for text in row] for row in self.athena.yield_rows(results, headers)])
elif self.format == 'TSV':
print(tabulate([row for row in self.athena.yield_rows(results, headers)], tablefmt='tsv'))
elif self.format == 'TSV_HEADER':
Expand Down

0 comments on commit e88e32f

Please sign in to comment.