-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix(presto)!: preserve SHA256/SHA512 digest semantics, render SHA2 as hex string [CLAUDE] #7824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1173,8 +1173,8 @@ def test_bigquery(self): | |
| "clickhouse": "SHA512(x)", | ||
| "bigquery": "SHA512(x)", | ||
| "spark2": "SHA2(x, 512)", | ||
| "presto": "SHA512(x)", | ||
| "trino": "SHA512(x)", | ||
| "presto": "LOWER(TO_HEX(SHA512(x)))", | ||
| "trino": "LOWER(TO_HEX(SHA512(x)))", | ||
| }, | ||
|
Comment on lines
+1176
to
1178
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should add a test where you annotate types in the ast you get after parsing with bigquery, so that the transpilation path with |
||
| ) | ||
| self.validate_all( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -710,6 +710,47 @@ def test_presto(self): | |
| "LOWER(TO_HEX(MD5(TO_UTF8(CONCAT(CAST(x AS VARCHAR), CAST('s' AS VARCHAR))))))", | ||
| ) | ||
|
|
||
| self.assertEqual( | ||
| exp.func("sha2", exp.cast("x", "text"), exp.Literal.number(256)).sql(dialect="presto"), | ||
| "LOWER(TO_HEX(SHA256(TO_UTF8(CAST(x AS VARCHAR)))))", | ||
| ) | ||
|
|
||
| # native SHA256/SHA512 take and return VARBINARY, so they parse as | ||
| # SHA2Digest and round-trip untouched, mirroring MD5 -> MD5Digest | ||
| self.validate_all( | ||
| "SELECT SHA256(x)", | ||
| write={ | ||
| "presto": "SELECT SHA256(x)", | ||
| "trino": "SELECT SHA256(x)", | ||
| "duckdb": "SELECT UNHEX(SHA256(x))", | ||
| "bigquery": "SELECT SHA256(x)", | ||
| }, | ||
| ) | ||
| self.validate_all( | ||
| "SELECT SHA512(x)", | ||
| write={ | ||
| "presto": "SELECT SHA512(x)", | ||
| "trino": "SELECT SHA512(x)", | ||
| "bigquery": "SELECT SHA512(x)", | ||
| }, | ||
| ) | ||
|
|
||
| # string-semantics SHA2 renders hex output like md5_sql does for MD5 | ||
| self.validate_all( | ||
| "SELECT SHA2(x, 256)", | ||
| write={ | ||
| "presto": "SELECT LOWER(TO_HEX(SHA256(x)))", | ||
| "trino": "SELECT LOWER(TO_HEX(SHA256(x)))", | ||
| }, | ||
| ) | ||
| self.validate_all( | ||
| "SELECT SHA2(x, 512)", | ||
| write={ | ||
| "presto": "SELECT LOWER(TO_HEX(SHA512(x)))", | ||
| "trino": "SELECT LOWER(TO_HEX(SHA512(x)))", | ||
| }, | ||
| ) | ||
|
|
||
|
Comment on lines
+738
to
+753
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These aren't valid presto inputs afaict, i.e., |
||
| with self.assertLogs(helper_logger): | ||
| self.validate_all( | ||
| "SELECT COALESCE(ELEMENT_AT(MAP_FROM_ENTRIES(ARRAY[(51, '1')]), id), quantity) FROM my_table", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this. For transpilation purposes, nowadays we assume that type inference has ran separately and thus we expect
is_typeon its own to suffice.Just need to make sure the Presto functions roundtrip unaffected by default, i.e., when there aren't any type annotations in the AST. I think this is already the case, just double-checking.