Skip to content

Commit 5552f12

Browse files
authored
feat!: annotation support for LOCALTIME function (#6651)
* annotation support for LOCALTIME func * handled mysql case
1 parent 3d59af5 commit 5552f12

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

sqlglot/dialects/mysql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from sqlglot.generator import unsupported_args
3131
from sqlglot.helper import seq_get
3232
from sqlglot.tokens import TokenType
33+
from sqlglot.typing.mysql import EXPRESSION_METADATA
3334

3435

3536
def _show_parser(*args: t.Any, **kwargs: t.Any) -> t.Callable[[MySQL.Parser], exp.Show]:
@@ -166,6 +167,8 @@ class MySQL(Dialect):
166167
SAFE_TO_ELIMINATE_DOUBLE_NEGATION = False
167168
LEAST_GREATEST_IGNORES_NULLS = False
168169

170+
EXPRESSION_METADATA = EXPRESSION_METADATA.copy()
171+
169172
# https://prestodb.io/docs/current/functions/datetime.html#mysql-date-functions
170173
TIME_MAPPING = {
171174
"%M": "%B",

sqlglot/typing/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
expr_type: {"returns": exp.DataType.Type.TIME}
145145
for expr_type in {
146146
exp.CurrentTime,
147+
exp.Localtime,
147148
exp.Time,
148149
exp.TimeAdd,
149150
exp.TimeSub,

sqlglot/typing/mysql.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from __future__ import annotations
2+
3+
from sqlglot import exp
4+
from sqlglot.typing import EXPRESSION_METADATA
5+
6+
EXPRESSION_METADATA = {
7+
**EXPRESSION_METADATA,
8+
exp.Localtime: {"returns": exp.DataType.Type.DATETIME},
9+
}

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ DOUBLE;
2222
CURRENT_TIME();
2323
TIME;
2424

25+
LOCALTIME();
26+
TIME;
27+
2528
TIME_ADD(CAST('09:05:03' AS TIME), INTERVAL 2 HOUR);
2629
TIME;
2730

@@ -4831,3 +4834,11 @@ TIMESTAMPTZ;
48314834
# dialect: tsql
48324835
RADIANS(90);
48334836
INT;
4837+
4838+
--------------------------------------
4839+
-- MySQL
4840+
--------------------------------------
4841+
4842+
# dialect: mysql
4843+
LOCALTIME;
4844+
DATETIME;

0 commit comments

Comments
 (0)