chore(sql_parse): Provide more meaningful SQLGlot errors (#27858)

This commit is contained in:
John Bodley
2024-04-03 07:10:52 -07:00
committed by GitHub
parent 848a7ffbf3
commit c38529741e
2 changed files with 20 additions and 6 deletions

View File

@@ -752,11 +752,21 @@ class ParsedQuery:
statements = parse(self.stripped(), dialect=self._dialect)
except SqlglotError as ex:
logger.warning("Unable to parse SQL (%s): %s", self._dialect, self.sql)
dialect = self._dialect or "generic"
message = (
"Error parsing near '{highlight}' at line {line}:{col}".format( # pylint: disable=consider-using-f-string
**ex.errors[0]
)
if isinstance(ex, ParseError)
else str(ex)
)
raise SupersetSecurityException(
SupersetError(
error_type=SupersetErrorType.QUERY_SECURITY_ACCESS_ERROR,
message=__(f"Unable to parse SQL ({dialect}): {self.sql}"),
message=__(
f"You may have an error in your SQL statement. {message}"
),
level=ErrorLevel.ERROR,
)
) from ex