From 7c7f6e9750ba6750b60f740c2b2b0b3397a9bf09 Mon Sep 17 00:00:00 2001 From: Andrew Snare Date: Wed, 16 Jul 2025 18:11:21 +0200 Subject: [PATCH] Update to support sqlglot 27.0.0 --- pyproject.toml | 2 +- src/databricks/labs/ucx/source_code/sql/sql_parser.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7fc10b579e..5cff256b28 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ dependencies = ["databricks-sdk>=0.58.0,<0.59.0", "databricks-labs-lsql>=0.16.0,<0.17.0", "databricks-labs-blueprint>=0.11.0,<0.12.0", "PyYAML>=6.0.0,<6.1.0", - "sqlglot>=26.7.0,<26.8.0", + "sqlglot>=26.7.0,<27.1.0", "astroid>=3.3.0,<3.4.0"] [project.optional-dependencies] diff --git a/src/databricks/labs/ucx/source_code/sql/sql_parser.py b/src/databricks/labs/ucx/source_code/sql/sql_parser.py index a0c2b7145a..1f27989a07 100644 --- a/src/databricks/labs/ucx/source_code/sql/sql_parser.py +++ b/src/databricks/labs/ucx/source_code/sql/sql_parser.py @@ -3,8 +3,8 @@ from typing import TypeVar from sqlglot import parse -from sqlglot.errors import SqlglotError -from sqlglot.expressions import Create, Delete, Drop, Expression, Select, Table, Update, Use +from sqlglot.errors import SqlglotError, UnsupportedError +from sqlglot.expressions import Create, Delete, Drop, Expression, Select, Table, Update, Use, Identifier from databricks.labs.ucx.source_code.base import UsedTable, CurrentSessionState @@ -54,6 +54,13 @@ def _collect_table_info( if not src_schema: logger.warning(f"Could not determine schema for table {table.name}") return None + # Sqlglot handlers parameter markers by returning an Identifier as the name instead of a string. + # For example: {foo} -> Identifier(this=foo) + if isinstance(table.name, Identifier): + # TODO: Support these properly, for example by inferring the placeholder value from the outside context. + msg = f"Table placeholder detected, not yet supported: {{{table.name}}}" + logger.debug(msg) + raise UnsupportedError(msg) return UsedTable( catalog_name=catalog_name, schema_name=src_schema,