Skip to content
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

fix: 🐛 Correctly switch coalesce() result .NotNull value #1664

Merged

Conversation

mpyw
Copy link
Contributor

@mpyw mpyw commented Jun 7, 2022

This change follows the previous implementation that mutates and returns the first column, but switches only the .NotNull value depending on the situation.

  • Is it sufficient that asserting only types of columns and constants?
  • Also I'm concerned that the A_Const node may contain Null.

Also, I am new to Golang OSS, so I may be making some large mistakes. Thank you in advance for your review.

BREAKING CHANGE: 🧨 coalesce() may assign nullable results

Closes: #1663

This change follows the previous implementation that mutates and returns
the first column, but switches only the `.NotNull` value depending on
the situation.

BREAKING CHANGE: 🧨 `coalesce()` may assign nullable results

✅ Closes: sqlc-dev#1663
@mpyw mpyw marked this pull request as ready for review June 7, 2022 10:52
Comment on lines +171 to +175
if firstColumn != nil {
firstColumn.NotNull = shouldNotBeNull
firstColumn.skipTableRequiredCheck = true
cols = append(cols, firstColumn)
} else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question: Is this really correct that using first column on this way?

Comment on lines +154 to 157
if _, ok := arg.(*ast.A_Const); ok {
shouldNotBeNull = true
continue
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question: Is it sufficient that asserting only A_Const and ColumnRef?

Comment on lines +164 to +167
if firstColumn == nil {
firstColumn = c
}
shouldNotBeNull = shouldNotBeNull || c.NotNull
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question: What are the differences between n.Args.Items and their inner columns?

@kyleconroy kyleconroy self-requested a review August 29, 2022 02:56
Copy link
Collaborator

@kyleconroy kyleconroy left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Sorry that it's take so long to review. Took me a few times through to understand the changes, but I think it's the right change and actually quite backwards compatible.

@kyleconroy kyleconroy merged commit 0a1b04e into sqlc-dev:main Sep 1, 2022
@mpyw mpyw deleted the fix/#1663-coalesce-always-be-non-null branch September 2, 2022 03:03
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.

SELECT COALESCE() results are always assumed non-null
2 participants