mirror of
https://github.com/apache/superset.git
synced 2026-04-24 02:25:13 +00:00
fix(pinot): DATE_ADD function (#35424)
This commit is contained in:
@@ -26,6 +26,7 @@ from __future__ import annotations
|
||||
|
||||
from sqlglot import exp
|
||||
from sqlglot.dialects.mysql import MySQL
|
||||
from sqlglot.helper import seq_get
|
||||
from sqlglot.tokens import TokenType
|
||||
|
||||
|
||||
@@ -50,6 +51,16 @@ class Pinot(MySQL):
|
||||
"BYTES": TokenType.VARBINARY,
|
||||
}
|
||||
|
||||
class Parser(MySQL.Parser):
|
||||
FUNCTIONS = {
|
||||
**MySQL.Parser.FUNCTIONS,
|
||||
"DATE_ADD": lambda args: exp.DateAdd(
|
||||
this=seq_get(args, 2),
|
||||
expression=seq_get(args, 1),
|
||||
unit=seq_get(args, 0),
|
||||
),
|
||||
}
|
||||
|
||||
class Generator(MySQL.Generator):
|
||||
TYPE_MAPPING = {
|
||||
**MySQL.Generator.TYPE_MAPPING,
|
||||
@@ -80,6 +91,12 @@ class Pinot(MySQL):
|
||||
|
||||
TRANSFORMS = {
|
||||
**MySQL.Generator.TRANSFORMS,
|
||||
exp.DateAdd: lambda self, e: self.func(
|
||||
"DATE_ADD",
|
||||
exp.Literal.string(str(e.args.get("unit").name)),
|
||||
e.args.get("expression"),
|
||||
e.this,
|
||||
),
|
||||
}
|
||||
# Remove DATE_TRUNC transformation - Pinot supports standard SQL DATE_TRUNC
|
||||
TRANSFORMS.pop(exp.DateTrunc, None)
|
||||
|
||||
@@ -552,14 +552,16 @@ class SQLStatement(BaseSQLStatement[exp.Expression]):
|
||||
try:
|
||||
statements = sqlglot.parse(script, dialect=dialect)
|
||||
except sqlglot.errors.ParseError as ex:
|
||||
error = ex.errors[0]
|
||||
raise SupersetParseError(
|
||||
script,
|
||||
engine,
|
||||
highlight=error["highlight"],
|
||||
line=error["line"],
|
||||
column=error["col"],
|
||||
) from ex
|
||||
kwargs = (
|
||||
{
|
||||
"highlight": ex.errors[0]["highlight"],
|
||||
"line": ex.errors[0]["line"],
|
||||
"column": ex.errors[0]["col"],
|
||||
}
|
||||
if ex.errors
|
||||
else {}
|
||||
)
|
||||
raise SupersetParseError(script, engine, **kwargs) from ex
|
||||
except sqlglot.errors.SqlglotError as ex:
|
||||
raise SupersetParseError(
|
||||
script,
|
||||
|
||||
Reference in New Issue
Block a user