Skip to content

feat!: annotation support for LOCALTIME function#6651

Merged
VaggelisD merged 2 commits intotobymao:mainfrom
AbhishekASLK:abhishekaslk/localtime-annotation
Jan 5, 2026
Merged

feat!: annotation support for LOCALTIME function#6651
VaggelisD merged 2 commits intotobymao:mainfrom
AbhishekASLK:abhishekaslk/localtime-annotation

Conversation

@AbhishekASLK
Copy link
Contributor

This PR ensures LOCALTIME expressions are correctly resolved to DataType.Type.TIME by adding exp.Localtime to the expression metadata, fixing an issue where they were previously annotated as UNKNOWN

Before:

Select(
  expressions=[
    Localtime(_type=DataType(this=Type.UNKNOWN))],
  _type=DataType(this=Type.UNKNOWN))

After:

Select(
  expressions=[
    Localtime(_type=DataType(this=Type.TIME))],
  _type=DataType(this=Type.UNKNOWN))

Copy link
Collaborator

@VaggelisD VaggelisD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AbhishekASLK, I'd generally expect that LOCALTIME does evaluates to a TIME type across all dialects but from a quick search it might not be the case e.g MySQL seems to produce a timestamp:

mysql> select LOCALTIME;
+---------------------+
| LOCALTIME           |
+---------------------+
| 2026-01-05 12:01:09 |
+---------------------+

We should only annotate an expression "globally" (i.e in __init__.py) if that's the case for all dialects

@AbhishekASLK
Copy link
Contributor Author

Hey @AbhishekASLK, I'd generally expect that LOCALTIME does evaluates to a TIME type across all dialects but from a quick search it might not be the case e.g MySQL seems to produce a timestamp:

mysql> select LOCALTIME;
+---------------------+
| LOCALTIME           |
+---------------------+
| 2026-01-05 12:01:09 |
+---------------------+

We should only annotate an expression "globally" (i.e in __init__.py) if that's the case for all dialects

So let me do it specific to dialects

@VaggelisD
Copy link
Collaborator

VaggelisD commented Jan 5, 2026

So let me do it specific to dialects

We can probably add mysql.py in typing/ and override that entry, but please do a pass over all dialects that support LOCALTIME, as is the usual suggestion.

@AbhishekASLK
Copy link
Contributor Author

So let me do it specific to dialects

We can probably add mysql.py in typing/ and override that entry, but please do a pass over all dialects that support LOCALTIME, as is the usual suggestion.

Sure @VaggelisD I'll pass over all dialects for this.

@AbhishekASLK
Copy link
Contributor Author

Dialects (returns time): postgres duckdb snowflake presto trino
Dialects (do not return time): mysql

postgres:

    localtime    
-----------------
 13:05:11.990461
(1 row)

duckdb

duckdb> select localtime;
┌──────────────┐
│ localtime    │
╞══════════════╡
│ 13:06:02.393 │
└──────────────┘

snowflake

LOCALTIME
05:11:01

presto
Documentation
localtime -> time

trino
Documentation

mysql

+---------------------+
| localtime           |
+---------------------+
| 2026-01-05 13:20:24 |
+---------------------+

@AbhishekASLK AbhishekASLK requested a review from VaggelisD January 5, 2026 14:27
Copy link
Collaborator

@VaggelisD VaggelisD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@VaggelisD VaggelisD merged commit 5552f12 into tobymao:main Jan 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants