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

coercion vec[Dictionary, Utf8] to Dictionary for coalesce function #9958

Merged
merged 4 commits into from
Apr 5, 2024

Conversation

Lordworms
Copy link
Contributor

@Lordworms Lordworms commented Apr 5, 2024

Which issue does this PR close?

Closes #9925

Rationale for this change

The signature of the coalesce function has changed to variadic_equal and we need to add a new rule to coercion [Dictionary, Utf8] to Dictionary

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added logical-expr Logical plan and expressions physical-expr Physical Expressions labels Apr 5, 2024
@Lordworms Lordworms changed the title coercion vec[Dictionary, Utf8] to Dictionary coercion vec[Dictionary, Utf8] to Dictionary for coalesce function Apr 5, 2024
@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) and removed physical-expr Physical Expressions labels Apr 5, 2024
finish

remove print

add space
@Lordworms Lordworms marked this pull request as ready for review April 5, 2024 03:54
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you for working on this @Lordworms 🙏

I think we need a few more tests and to handle a few more cases, but it looks good so far

@@ -430,7 +430,7 @@ fn coerced_from<'a>(
{
Some(type_into.clone())
}

Dictionary(_, _) if matches!(type_from, Utf8) => Some(type_into.clone()),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this currently says it is possible to coerce from Utf8 to any dictionary type (e.g. even Dictionary(Int64, Int32))

I think the dictionary_coercion function does something similar here: https://github.com/apache/arrow-datafusion/blob/37b73751b19b82516443579c714b3b5986dac927/datafusion/expr/src/type_coercion/binary.rs#L635-L634

So maybe we need to verify we can coerce the value types, like this?

Suggested change
Dictionary(_, _) if matches!(type_from, Utf8) => Some(type_into.clone()),
Dictionary(_, value_type) if coerce_from(value_type, from_type) => Some(type_into.clone()),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it

datafusion/sqllogictest/test_files/scalar.slt Show resolved Hide resolved
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @Lordworms -- this looks very nice to me 🙏

@alamb alamb merged commit 4d85979 into apache:main Apr 5, 2024
24 checks passed
wiedld pushed a commit to influxdata/arrow-datafusion that referenced this pull request Apr 10, 2024
…pache#9958)

* for debug

finish

remove print

add space

* fix clippy

* finish

* fix clippy
alamb pushed a commit to alamb/datafusion that referenced this pull request Apr 16, 2024
…pache#9958)

* for debug

finish

remove print

add space

* fix clippy

* finish

* fix clippy
alamb added a commit that referenced this pull request Apr 17, 2024
…9958) (#10104)

* for debug

finish

remove print

add space

* fix clippy

* finish

* fix clippy

Co-authored-by: Lordworms <[email protected]>
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 sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression: Coercion stopped working for coalesce on a dictionary column
2 participants