fix(pinot): DATE_ADD function (#35424)

This commit is contained in:
Beto Dealmeida
2025-10-02 09:56:20 -04:00
committed by GitHub
parent 5493e2c96d
commit 5428376662
3 changed files with 76 additions and 9 deletions

View File

@@ -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)