mirror of
https://github.com/apache/superset.git
synced 2026-04-07 18:35:15 +00:00
feat: improve _extract_tables_from_sql (#26748)
This commit is contained in:
@@ -28,6 +28,7 @@ from typing import Any, cast
|
||||
|
||||
import sqlglot
|
||||
import sqlparse
|
||||
from flask_babel import gettext as __
|
||||
from sqlalchemy import and_
|
||||
from sqlglot import exp, parse, parse_one
|
||||
from sqlglot.dialects.dialect import Dialect, Dialects
|
||||
@@ -58,7 +59,12 @@ from sqlparse.tokens import (
|
||||
)
|
||||
from sqlparse.utils import imt
|
||||
|
||||
from superset.exceptions import QueryClauseValidationException, SupersetParseError
|
||||
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
|
||||
from superset.exceptions import (
|
||||
QueryClauseValidationException,
|
||||
SupersetParseError,
|
||||
SupersetSecurityException,
|
||||
)
|
||||
from superset.utils.backports import StrEnum
|
||||
|
||||
try:
|
||||
@@ -467,9 +473,16 @@ class ParsedQuery:
|
||||
"""
|
||||
try:
|
||||
statements = parse(self.stripped(), dialect=self._dialect)
|
||||
except SqlglotError:
|
||||
except SqlglotError as ex:
|
||||
logger.warning("Unable to parse SQL (%s): %s", self._dialect, self.sql)
|
||||
return set()
|
||||
dialect = self._dialect or "generic"
|
||||
raise SupersetSecurityException(
|
||||
SupersetError(
|
||||
error_type=SupersetErrorType.QUERY_SECURITY_ACCESS_ERROR,
|
||||
message=__(f"Unable to parse SQL ({dialect}): {self.sql}"),
|
||||
level=ErrorLevel.ERROR,
|
||||
)
|
||||
) from ex
|
||||
|
||||
return {
|
||||
table
|
||||
|
||||
Reference in New Issue
Block a user