Skip to content

fix: avoid invalid CAST(NULL AS NULL) in SQLGlot compiler#17487

Merged
shuoweil merged 3 commits into
mainfrom
shuowei-fix-sqlglot-null-cast
Jun 18, 2026
Merged

fix: avoid invalid CAST(NULL AS NULL) in SQLGlot compiler#17487
shuoweil merged 3 commits into
mainfrom
shuowei-fix-sqlglot-null-cast

Conversation

@shuoweil

Copy link
Copy Markdown
Contributor

This PR resolves a compilation crash caused by the SQLGlot compiler attempting to generate an invalid CAST(NULL AS NULL) statement in BigQuery, which triggers a syntax/validation error (e.g., Unexpected keyword NULL).

Fixes #<524701452> 🦕

@shuoweil shuoweil self-assigned this Jun 16, 2026
@shuoweil shuoweil requested review from a team as code owners June 16, 2026 19:34
@shuoweil shuoweil requested review from TrevorBergeron and tswast and removed request for a team June 16, 2026 19:34

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the SQLGlot compilation logic to return a plain NULL expression instead of a cast when the value is None and the SQLGlot type is "NULL". It also adds a unit test to verify this behavior. The reviewer noted that calling .upper() directly on sqlglot_type could raise an AttributeError if it is a DataType object rather than a string, and suggested converting it to a string first.

Comment thread packages/bigframes/bigframes/core/compile/sqlglot/sql/base.py Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

@TrevorBergeron TrevorBergeron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like on ok fix, but I wonder if we should be handling this earlier, upstream? Like where are the casts to NULL type happening?

@shuoweil

Copy link
Copy Markdown
Contributor Author

Seems like on ok fix, but I wonder if we should be handling this earlier, upstream? Like where are the casts to NULL type happening?

Good idea. I will use another PR for this upstream fix.

@shuoweil shuoweil enabled auto-merge (squash) June 18, 2026 01:09
@shuoweil shuoweil merged commit 3b79caa into main Jun 18, 2026
30 of 31 checks passed
@shuoweil shuoweil deleted the shuowei-fix-sqlglot-null-cast branch June 18, 2026 01:25
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