From 674302cfc6f84c5defc2734dccff8e5785a30e71 Mon Sep 17 00:00:00 2001 From: nmurrell07 Date: Tue, 24 Mar 2026 10:23:26 -0500 Subject: [PATCH] Fix Trino parameterized type mapping (e.g., timestamp(0), decimal(10,2)) Trino columns with parameterized types like timestamp(0) or decimal(10,2) were not being mapped correctly because TRINO_TYPES_MAPPING only contains base type keys without parameters. This fix adds a _map_trino_type helper function that: 1. First tries direct lookup in TRINO_TYPES_MAPPING 2. If not found and the type contains parentheses, strips the parameters and looks up just the base type (e.g., 'timestamp' from 'timestamp(0)') 3. Returns None if no mapping is found This ensures columns with parameterized types are correctly mapped to their Redash equivalents. --- redash/query_runner/trino.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/redash/query_runner/trino.py b/redash/query_runner/trino.py index 6bb6c5bccc..837b594f10 100644 --- a/redash/query_runner/trino.py +++ b/redash/query_runner/trino.py @@ -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" @@ -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}