fix: Make cte_alias a property of db engine spec (#22947)

This commit is contained in:
alexclavel-ocient
2023-02-06 14:27:48 -07:00
committed by GitHub
parent aa0a07859e
commit 9dfaad772d
3 changed files with 6 additions and 8 deletions
+3 -4
View File
@@ -86,9 +86,6 @@ ColumnTypeMapping = Tuple[
logger = logging.getLogger()
CTE_ALIAS = "__cte"
class TimeGrain(NamedTuple):
name: str # TODO: redundant field, remove
label: str
@@ -346,6 +343,8 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
# If True, then it will allow in subquery ,
# if False it will allow as regular CTE
allows_cte_in_subquery = True
# Define alias for CTE
cte_alias = "__cte"
# Whether allow LIMIT clause in the SQL
# If True, then the database engine is allowed for LIMIT clause
# If False, then the database engine is allowed for TOP clause
@@ -889,7 +888,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
# extract rest of the SQLs after CTE
remainder = "".join(str(token) for token in stmt.tokens[idx:]).strip()
return f"WITH {token.value},\n{CTE_ALIAS} AS (\n{remainder}\n)"
return f"WITH {token.value},\n{cls.cte_alias} AS (\n{remainder}\n)"
return None