mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +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)
|
||||
|
||||
Reference in New Issue
Block a user