Skip to content
Open
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
23 changes: 22 additions & 1 deletion redash/query_runner/trino.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ def _convert_row_types(value):
"timestamp": TYPE_DATETIME,
}

def _map_trino_type(type_name):
"""Map Trino type names to Redash types, handling parameterized types like timestamp(0)."""
if type_name is None:
return None

# First try direct lookup
mapped = TRINO_TYPES_MAPPING.get(type_name)
if mapped is not None:
return mapped

# If not found and contains parentheses, strip parameters and try again
if "(" in type_name:
base_type = type_name.split("(", 1)[0]
mapped = TRINO_TYPES_MAPPING.get(base_type)
if mapped is not None:
return mapped

return None




class Trino(BaseQueryRunner):
noop_query = "SELECT 1"
Expand Down Expand Up @@ -215,7 +236,7 @@ def run_query(self, query, user):
cursor.execute(query)
results = cursor.fetchall()
description = cursor.description
columns = self.fetch_columns([(c[0], TRINO_TYPES_MAPPING.get(c[1], None)) for c in description])
columns = self.fetch_columns([(c[0], _map_trino_type(c[1])) for c in description])
column_names = [c["name"] for c in columns]
rows = [dict(zip(column_names, [_convert_row_types(v) for v in r])) for r in results]
data = {"columns": columns, "rows": rows}
Expand Down
Loading