Skip to content

Conversation

@fivetran-felixhuang
Copy link
Collaborator

When parsing SHA256 from BigQuery, we want to represent it as SHA2Digest with length 256 since the output is binary, just like we do with SHA1.

We also want to wrap SHA256 with UNHEX in the transpiled DuckDB query so that the output is binary to stay consistent with BigQuery.

For other dialects, we just want to make sure SHA2Digest with length 256 generates the appropriate queries. For example, SHA256(x) in bigquery should be tranpiled into SHA2_BINARY(x, 256) in Snowflake

Comment on lines 1876 to 1877
def build_sha2_digest_sql(self: Generator, expression: exp.SHA2Digest) -> str:
return self.func(f"SHA{expression.text('length') or '256'}", expression.this)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rename this to sha2_digest_sql, otherwise naming clashes with AST helper builders.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

Comment on lines +222 to +224
exp.SHA2Digest: lambda self, e: self.func(
"SHA2", e.this, e.args.get("length") or exp.Literal.number(256)
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a bug in how exp.SHA2 is generated in redshift? Why did we need this entry and not reuse the new sha2_digest_sql helper?

Copy link
Collaborator Author

@fivetran-felixhuang fivetran-felixhuang Nov 26, 2025

Choose a reason for hiding this comment

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

so in redshift it should be something like SHA2('abc', 256), while sha2_digest_sql produces SHA256('abc)

Comment on lines +285 to +287
exp.SHA2Digest: lambda self, e: self.func(
"SHA2", e.this, e.args.get("length") or exp.Literal.number(256)
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto, similar to Redshift.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

like redshift, spark2 also only has SHA2 function

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.

3 participants