From e87d3375f8e8a280f95d07c75775da9398f06513 Mon Sep 17 00:00:00 2001 From: paul cannon Date: Tue, 28 Jan 2025 11:50:25 -0600 Subject: [PATCH] Decode from base64 for BYTES values from Spanner --- redash/query_runner/spanner.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/redash/query_runner/spanner.py b/redash/query_runner/spanner.py index 5f6db9208b..2ef2b7760d 100644 --- a/redash/query_runner/spanner.py +++ b/redash/query_runner/spanner.py @@ -92,7 +92,7 @@ def run_query(self, query, user): try: cursor.execute(query) columns = self.fetch_columns([(i[0], i[1]) for i in cursor.description]) - rows = [dict(zip((column["name"] for column in columns), row)) for row in cursor.fetchall()] + rows = [self.prepare_col_value(cursor.description, row) for row in cursor.fetchall()] data = { "columns": columns, @@ -111,6 +111,18 @@ def run_query(self, query, user): return data, error + @staticmethod + def prepare_col_value(col_descriptions, row): + + row_dict = {} + for (desc, val) in zip(col_descriptions, row): + if desc[1] == 'BYTES': + val = b64decode(val) + row_dict[desc[0]] = val + + return row_dict + + def fetch_columns(self, columns): column_types = {