Skip to content

[CALCITE-6663] Support SPLIT_PART function for PostgreSql #4027

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

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

zhuqi-lucas
Copy link
Contributor

@zhuqi-lucas zhuqi-lucas commented Nov 1, 2024

We can support split_part function for postgresq:

split_part ( string text, delimiter text, n integer ) → text

Splits string at occurrences of delimiter and returns the n'th field (counting from one), or when n is negative, returns the |n|'th-from-last field.

split_part('abc@~def@~ghi', '@~', 2) → def

split_part('abc,def,ghi,jkl', ',', -2) → ghi

@zhuqi-lucas zhuqi-lucas force-pushed the CALCITE-6663 branch 2 times, most recently from 48434f4 to a810f9e Compare November 1, 2024 06:51
@zhuqi-lucas zhuqi-lucas changed the title [CALCITE-6663] Support SPLIT_PART function for postgresql [CALCITE-6663] Support SPLIT_PART function for Postgresql Nov 1, 2024
@zhuqi-lucas zhuqi-lucas changed the title [CALCITE-6663] Support SPLIT_PART function for Postgresql [CALCITE-6663] Support SPLIT_PART function for PostgreSql Nov 1, 2024
@zhuqi-lucas zhuqi-lucas force-pushed the CALCITE-6663 branch 3 times, most recently from 9c774d8 to 246323a Compare November 1, 2024 09:04
@NobiGo
Copy link
Contributor

NobiGo commented Nov 1, 2024

We can support split_part function for postgresq:

split_part ( string text, delimiter text, n integer ) → text

Splits string at occurrences of delimiter and returns the n'th field (counting from one), or when n is negative, returns the |n|'th-from-last field.

split_part('abc~@def@ghi', '@~', 2) → def

split_part('abc,def,ghi,jkl', ',', -2) → ghi

select split_part('abc~@def@ghi', '@~', 2); return nothing in PG. There is a typographical error here.

false);
final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL);

f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL");
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 return VARCHAR(15) for this function? I want to confirm is there a document explaining?

Copy link
Contributor

Choose a reason for hiding this comment

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

This type comes from ARG0_NULLABLE.
It is true that the result will never be larger.
Another reasonable type would be VARCHAR.
I think there are many functions which use this result type inference.
But indeed, the VARCHAR(N) types have some unintuitive behaviors sometimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to VARCHAR , addressed in latest PR, thanks!

@zhuqi-lucas
Copy link
Contributor Author

We can support split_part function for postgresq:
split_part ( string text, delimiter text, n integer ) → text
Splits string at occurrences of delimiter and returns the n'th field (counting from one), or when n is negative, returns the |n|'th-from-last field.

split_part('abc~@def@ghi', '@~', 2) → def

split_part('abc,def,ghi,jkl', ',', -2) → ghi

select split_part('abc~@def@ghi', '@~', 2); return nothing in PG. There is a typographical error here.

Updated, thanks!

@zhuqi-lucas zhuqi-lucas requested a review from NobiGo November 2, 2024 05:40
@zhuqi-lucas zhuqi-lucas requested a review from NobiGo November 2, 2024 10:36
Copy link
Contributor

@NobiGo NobiGo left a comment

Choose a reason for hiding this comment

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

LGTM.

@mihaibudiu
Copy link
Contributor

This has already two approvals, Can you please sqash the commits to a single one, which should have the same title as the JIRA issue? Then we can merge the PR. Thank you.

@zhuqi-lucas
Copy link
Contributor Author

This has already two approvals, Can you please sqash the commits to a single one, which should have the same title as the JIRA issue? Then we can merge the PR. Thank you.

Done, thanks @mihaibudiu !

@@ -10901,6 +10901,36 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}

/** Tests the {@code SPLIT_PART} operator. */
Copy link
Member

Choose a reason for hiding this comment

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

Minor: Add jira link

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added now, thanks!

Copy link

sonarqubecloud bot commented Nov 4, 2024

@mihaibudiu
Copy link
Contributor

Will merge this after the CI completes

@mihaibudiu mihaibudiu merged commit a83f2f8 into apache:main Nov 4, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants