Skip to content

Commit ca9d165

Browse files
committed
Define bigquery type hint for date funcs
1 parent 91a781b commit ca9d165

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

sqlglot/typing/bigquery.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313
# implicitly casts a string literal first arg to the function's own temporal type,
1414
# so map each to that type (e.g. DATE_ADD('2020-01-01', ...) -> DATE,
1515
# TIMESTAMP_TRUNC('...') -> TIMESTAMP).
16-
_DATE_FUNC_LITERAL_TYPE: dict[type[exp.Expr], exp.DType] = {
16+
_DateFunc = t.Union[
17+
exp.DateAdd,
18+
exp.DateSub,
19+
exp.DateTrunc,
20+
exp.DatetimeTrunc,
21+
exp.TimestampTrunc,
22+
]
23+
24+
_DATE_FUNC_LITERAL_TYPE: dict[type[_DateFunc], exp.DType] = {
1725
exp.DateAdd: exp.DType.DATE,
1826
exp.DateSub: exp.DType.DATE,
1927
exp.DateTrunc: exp.DType.DATE,
@@ -22,7 +30,7 @@
2230
}
2331

2432

25-
def _annotate_date_func(self: TypeAnnotator, expression: exp.Expr) -> exp.Expr:
33+
def _annotate_date_func(self: TypeAnnotator, expression: _DateFunc) -> exp.Expr:
2634
"""Annotate DATE_ADD / DATE_SUB / *_TRUNC, which return their first arg's type.
2735
2836
A typed first argument keeps its exact type (e.g. DATE_ADD(DATETIME, ...) ->

0 commit comments

Comments
 (0)