mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
fix(sqla): make text clause escaping optional (#17641)
This commit is contained in:
@@ -32,6 +32,7 @@ SYNTAX_ERROR_REGEX = re.compile(
|
||||
class AthenaEngineSpec(BaseEngineSpec):
|
||||
engine = "awsathena"
|
||||
engine_name = "Amazon Athena"
|
||||
allows_escaped_colons = False
|
||||
|
||||
_time_grain_expressions = {
|
||||
None: "{col}",
|
||||
|
||||
@@ -52,7 +52,7 @@ from sqlalchemy.engine.url import make_url, URL
|
||||
from sqlalchemy.ext.compiler import compiles
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy.sql import quoted_name, text
|
||||
from sqlalchemy.sql.expression import ColumnClause, Select, TextAsFrom
|
||||
from sqlalchemy.sql.expression import ColumnClause, Select, TextAsFrom, TextClause
|
||||
from sqlalchemy.types import String, TypeEngine, UnicodeText
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
@@ -279,6 +279,7 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
allows_alias_in_select = True
|
||||
allows_alias_in_orderby = True
|
||||
allows_sql_comments = True
|
||||
allows_escaped_colons = True
|
||||
|
||||
# Whether ORDER BY clause can use aliases created in SELECT
|
||||
# that are the same as a source column
|
||||
@@ -338,6 +339,18 @@ class BaseEngineSpec: # pylint: disable=too-many-public-methods
|
||||
) -> bool:
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def get_text_clause(cls, clause: str) -> TextClause:
|
||||
"""
|
||||
SQLALchemy wrapper to ensure text clauses are escaped properly
|
||||
|
||||
:param clause: string clause with potentially unescaped characters
|
||||
:return: text clause with escaped characters
|
||||
"""
|
||||
if cls.allows_escaped_colons:
|
||||
clause = clause.replace(":", "\\:")
|
||||
return text(clause)
|
||||
|
||||
@classmethod
|
||||
def get_engine(
|
||||
cls,
|
||||
|
||||
Reference in New Issue
Block a user