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]: Coerce integer values for substr #13154

Closed
wants to merge 2 commits into from

Conversation

jonathanc-n
Copy link
Contributor

Which issue does this PR close?

Closes #13150.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added sqllogictest SQL Logic Tests (.slt) functions labels Oct 29, 2024
Comment on lines 196 to 199
query T
select substr(123456, 3);
----
3456
Copy link
Contributor

Choose a reason for hiding this comment

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

string/string_literal.slt is used to collect the string-related test. It's better to move it there.

@@ -94,6 +94,7 @@ impl ScalarUDFImpl for SubstrFunc {
let first_data_type = match &arg_types[0] {
DataType::Null => Ok(DataType::Utf8),
DataType::LargeUtf8 | DataType::Utf8View | DataType::Utf8 => Ok(arg_types[0].clone()),
DataType::Int64 | DataType::Int32 => Ok(DataType::Utf8), // Allows for first arg to be int
Copy link
Contributor

Choose a reason for hiding this comment

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

DataType::UInt64, DataType::UInt32 as well?
What about any type that can be coerced to Utf8?

Copy link
Contributor

Choose a reason for hiding this comment

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

I also forget why this function needs custom coercion logic. I feel like we should be able to do this with a Signature as the same logic could/should apply to any function that takes a string as argument 🤔

@jayzhan211
Copy link
Contributor

In Postgres and DuckDB, they don't accept integer as the first input, I suggest we follow them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
functions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

substr function no longer coerces types previously accepted
5 participants