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

[FLINK-26940][table] Add the built-in function SUBSTRING_INDEX #24972

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dylanhz
Copy link
Contributor

@dylanhz dylanhz commented Jun 24, 2024

What is the purpose of the change

Add SUBSTRING_INDEX supported in SQL & Table API.
Examples:

> SELECT substring_index('www.apache.org', '.', 2);
 www.apache 

Brief change log

FLINK-26940

Verifying this change

This change added tests and can be verified as follows: StringFunctionsITCase#substringIndexTestCases

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API, i.e., is any changed class annotated with @Public(Evolving): yes
  • The serializers: no
  • The runtime per-record code paths (performance sensitive): no
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
  • The S3 file system connector: no

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? docs

@flinkbot
Copy link
Collaborator

flinkbot commented Jun 24, 2024

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

Copy link
Contributor

@superdiaodiao superdiaodiao left a comment

Choose a reason for hiding this comment

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

Maybe we should also support API for Python? If so, you could refer other functions in these two files:

  • docs/reference/pyflink.table/expressions.rst
  • pyflink/table/expression.py

Copy link
Contributor

@lsyldliu lsyldliu left a comment

Choose a reason for hiding this comment

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

@dylanhz Thanks for your contribution, I left some comments.

}

private int find(byte[] str, int beginIdx, byte[] target) {
final int endIdx = str.length - target.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we should check the str.length > target.length?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it is unnecessary, as the current code would return -1 directly in this case, indicating no matching substring found, which aligns with the expected behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW, I do find a bug in the next row, beginIndex < endIndex should be beginIndex <= endIndex. Corresponding test cases have been added.

docs/data/sql_functions.yml Outdated Show resolved Hide resolved
docs/data/sql_functions_zh.yml Outdated Show resolved Hide resolved
if (count == 0) {
return BinaryStringData.EMPTY_UTF8;
}
String str = expr.toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can use the BinaryStringData to judge and find the substring instead of materialized it in advance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently we don't have find and rfind for BinaryStringData. I think it would be great to introduce them into BinaryStringDataUtil because they are commonly used for string matching.

@dylanhz dylanhz changed the title [FLINK-26940][Table SQL / API] Add SUBSTRING_INDEX supported in SQL & Table API [FLINK-26940][table] Add the built-in function SUBSTRING_INDEX Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants