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 VALUES tuples type casts #12104

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

davisp
Copy link
Member

@davisp davisp commented Aug 21, 2024

Which issue does this PR close?

Closes #12103

Rationale for this change

The general idea here is to provide the target schema fields to the logical plan builder so that it can avoid the need to guess on VALUES tuple column types.

What changes are included in this PR?

This updates the SQL planner to accept a list of column data types for VALUE tuple columns which are then used to inform the logical plan builder which types each column should be cast to.

Are these changes tested?

I've added a test in the sqllogictests crate showing the behavior is fixed. I suspect there will be a request for more tests, but I am uncertain on where they should be placed. I did attempt to try and add a test to the sql crate's tests, but AFAICT those are all stateless which means more specific tests should probably live in the expr crate. However, I wasn't able to find an obviously place to add tests for these changes.

Are there any user-facing changes?

Some queries that would have previously failed, will no longer fail.

Previously, the plan created for a VALUES list would attempt to auto
detect the type of each column. Unfortunately, for UInt64 columns this
results in cases where a large UInt64 that exceeds the range of Int64
causing cast errors when it is attempted to be cast down to a UInt64.
@github-actions github-actions bot added sql SQL Planner logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Aug 21, 2024
if column_types.is_empty() {
LogicalPlanBuilder::values(values)?.build()
} else {
LogicalPlanBuilder::values_with_types(values, column_types)?.build()
Copy link
Member

Choose a reason for hiding this comment

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

I am not convinced this is a good idea, as it will lead to inconsistent behavior or statements that should be equivalent. See #12103 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @findepi -- #12103 (comment)

Thank you @davisp for this PR -- let us know what you think about the alternate proposal

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm definitely on board in making this more general. It didn't feel super awesome to be fixing things this specifically in the first place, it was just the first thing that came to mind.

@alamb You mentioned in your comment on #12103 that there are other coercion patterns to follow, can you point me at anything vaguely similar to reference? Skimming the DataType docs, I'm not immediately seeing how I'd handle the expansion correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

@alamb
Copy link
Contributor

alamb commented Sep 5, 2024

Marking as draft as I think this PR is no longer waiting on feedback. Please mark it as ready for review when it is ready for another look

@alamb alamb marked this pull request as draft September 5, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logical-expr Logical plan and expressions sql SQL Planner sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug detecting datatype in VALUES tuples
3 participants