Skip to content

Commit

Permalink
Fix(Trino): Prevent first_value and last_value from being converted (#…
Browse files Browse the repository at this point in the history
…4661)

* Fix(Trino): Prevent first_value and last_value from being converted to arbitrary

* address pr review comments
  • Loading branch information
MikeWallis42 authored Jan 27, 2025
1 parent b091f2f commit c4de945
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 0 additions & 2 deletions sqlglot/dialects/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ class Generator(generator.Generator):
exp.Encode: lambda self, e: encode_decode_sql(self, e, "TO_UTF8"),
exp.FileFormatProperty: lambda self, e: f"FORMAT='{e.name.upper()}'",
exp.First: _first_last_sql,
exp.FirstValue: _first_last_sql,
exp.FromTimeZone: lambda self,
e: f"WITH_TIMEZONE({self.sql(e, 'this')}, {self.sql(e, 'zone')}) AT TIME ZONE 'UTC'",
exp.GenerateSeries: sequence_sql,
Expand All @@ -403,7 +402,6 @@ class Generator(generator.Generator):
exp.Initcap: _initcap_sql,
exp.JSONExtract: lambda self, e: self.jsonextract_sql(e),
exp.Last: _first_last_sql,
exp.LastValue: _first_last_sql,
exp.LastDay: lambda self, e: self.func("LAST_DAY_OF_MONTH", e.this),
exp.Lateral: explode_to_unnest_sql,
exp.Left: left_to_substring_sql,
Expand Down
3 changes: 3 additions & 0 deletions tests/dialects/test_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,9 @@ def test_presto(self):
"snowflake": "CURRENT_USER()",
},
)
self.validate_identity(
"SELECT id, FIRST_VALUE(is_deleted) OVER (PARTITION BY id) AS first_is_deleted, NTH_VALUE(is_deleted, 2) OVER (PARTITION BY id) AS nth_is_deleted, LAST_VALUE(is_deleted) OVER (PARTITION BY id) AS last_is_deleted FROM my_table"
)

def test_encode_decode(self):
self.validate_identity("FROM_UTF8(x, y)")
Expand Down

0 comments on commit c4de945

Please sign in to comment.