Skip to content

Commit c4de945

Browse files
authored
Fix(Trino): Prevent first_value and last_value from being converted (#4661)
* Fix(Trino): Prevent first_value and last_value from being converted to arbitrary * address pr review comments
1 parent b091f2f commit c4de945

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

sqlglot/dialects/presto.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ class Generator(generator.Generator):
392392
exp.Encode: lambda self, e: encode_decode_sql(self, e, "TO_UTF8"),
393393
exp.FileFormatProperty: lambda self, e: f"FORMAT='{e.name.upper()}'",
394394
exp.First: _first_last_sql,
395-
exp.FirstValue: _first_last_sql,
396395
exp.FromTimeZone: lambda self,
397396
e: f"WITH_TIMEZONE({self.sql(e, 'this')}, {self.sql(e, 'zone')}) AT TIME ZONE 'UTC'",
398397
exp.GenerateSeries: sequence_sql,
@@ -403,7 +402,6 @@ class Generator(generator.Generator):
403402
exp.Initcap: _initcap_sql,
404403
exp.JSONExtract: lambda self, e: self.jsonextract_sql(e),
405404
exp.Last: _first_last_sql,
406-
exp.LastValue: _first_last_sql,
407405
exp.LastDay: lambda self, e: self.func("LAST_DAY_OF_MONTH", e.this),
408406
exp.Lateral: explode_to_unnest_sql,
409407
exp.Left: left_to_substring_sql,

tests/dialects/test_presto.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,9 @@ def test_presto(self):
10831083
"snowflake": "CURRENT_USER()",
10841084
},
10851085
)
1086+
self.validate_identity(
1087+
"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"
1088+
)
10861089

10871090
def test_encode_decode(self):
10881091
self.validate_identity("FROM_UTF8(x, y)")

0 commit comments

Comments
 (0)