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

feat:implement sql style 'find_in_set' string function #8328

Merged
merged 4 commits into from
Nov 30, 2023

Conversation

Syleechan
Copy link
Contributor

Which issue does this PR close?

https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_find-in-set:~:text=FIND_IN_SET(str%2Cstrlist)

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 logical-expr Logical plan and expressions physical-expr Physical Expressions sqllogictest labels Nov 27, 2023
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 the contribution @Syleechan -- this PR seems pretty mysql specific and maybe it belong in a downstream system given:

  1. There is already a function like array_contains
  2. DataFusion isn't trying to replicate the full function library of existing databases

@@ -1170,6 +1171,20 @@ substr_index(str, delim, count)
- **delim**: the string to find in str to split str.
- **count**: The number of times to search for the delimiter. Can be both a positive or negative number.

### `find_in_set`
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about using one of the existing array union functions instead? What about array_contains?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @alamb . I have checked that the array functions input args type are different from the string function find_in_set.Actually, we use calcite to transfer to datafusion to compute data, and calcite also has array_contains, array_position functions.But Calcite take them as different functions, array functions process array input args and string functions process string input args.
https://calcite.apache.org/docs/reference.html#:~:text=ARRAY_POSITION(array%2C%20element)
https://calcite.apache.org/docs/reference.html#:~:text=FIND_IN_SET(matchStr%2C%20textStr)
these are calcite style functions in the reference.

@alamb alamb requested a review from Ted-Jiang November 28, 2023 12:43
Copy link
Member

@Ted-Jiang Ted-Jiang left a comment

Choose a reason for hiding this comment

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

LGTM, thx @Syleechan. @alamb this is the last str_func user case in our system, but we want to introduce more array_func, @Syleechan could you plz help list the need list.

# Conflicts:
#	datafusion/expr/src/built_in_function.rs
@alamb alamb merged commit c079a92 into apache:main Nov 30, 2023
23 checks passed
@alamb
Copy link
Contributor

alamb commented Nov 30, 2023

Thanks again @Syleechan

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 physical-expr Physical Expressions sqllogictest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants