You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by "zhuqi-lucas (via GitHub)" <gi...@apache.org> on 2024/11/01 05:33:53 UTC
[PR] [CALCITE-6663] Support SPLIT_PART function for postgresql [calcite]
zhuqi-lucas opened a new pull request, #4027:
URL: https://github.com/apache/calcite/pull/4027
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
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2453510045
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1827148436
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,36 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
Review Comment:
Added now, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826543803
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
+ "No match found for function signature SPLIT_PART\\(<CHARACTER>, <NUMERIC>\\)",
+ false);
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL);
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL");
+ f.checkScalar("SPLIT_PART('abc,def,ghi,jkl', ',', 3)", "ghi", "VARCHAR(15) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', -1)", "ghi", "VARCHAR(15) NOT NULL");
+ f.checkScalar("SPLIT_PART('abc,def,ghi,jkl', ',', -2)", "ghi", "VARCHAR(15) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('h,e,l,l,o', ',', 7)", "", "VARCHAR(9) NOT NULL");
+ f.checkScalar("SPLIT_PART('h,e,l,l,o', ',', -7)", "", "VARCHAR(9) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('abc,,ghi', ',', 2)", "", "VARCHAR(8) NOT NULL");
Review Comment:
Added now the third paras null case, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2453772287
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027) **Quality Gate passed**
Issues
 [2 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826500893
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -914,6 +914,29 @@ public static List<String> split(String s, String delimiter) {
}
}
+
+ /** SQL {@code SPLIT_PART(string, string, int)} function. */
+ public static String splitPart(String s, String delimiter, int n) {
+ if (s == null || s.equals("") || delimiter == null || delimiter.isEmpty() || n == 0) {
+ return "";
+ }
+
+ String[] parts = s.split(Pattern.quote(delimiter), -1);
Review Comment:
Addressed in latest PR, thanks!
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
Review Comment:
Addressed in latest PR, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2452845020
> > 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!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2452886257
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027) **Quality Gate passed**
Issues
 [2 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826543602
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -914,6 +914,29 @@ public static List<String> split(String s, String delimiter) {
}
}
+
+ /** SQL {@code SPLIT_PART(string, string, int)} function. */
+ public static String splitPart(String s, String delimiter, int n) {
+ if (Strings.isNullOrEmpty(s) || delimiter == null || delimiter.isEmpty() || n == 0) {
Review Comment:
Good catch, addressed in latest PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "NobiGo (via GitHub)" <gi...@apache.org>.
NobiGo commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1825735353
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -914,6 +914,29 @@ public static List<String> split(String s, String delimiter) {
}
}
+
+ /** SQL {@code SPLIT_PART(string, string, int)} function. */
+ public static String splitPart(String s, String delimiter, int n) {
+ if (s == null || s.equals("") || delimiter == null || delimiter.isEmpty() || n == 0) {
Review Comment:
Using `Strings.isNullOrEmpty(s)` will be simple.
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
+ "No match found for function signature SPLIT_PART\\(<CHARACTER>, <NUMERIC>\\)",
+ false);
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL);
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL");
Review Comment:
Do we should return `VARCHAR(15)` for this function? I want to confirm is there a document explaining?
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -914,6 +914,29 @@ public static List<String> split(String s, String delimiter) {
}
}
+
+ /** SQL {@code SPLIT_PART(string, string, int)} function. */
+ public static String splitPart(String s, String delimiter, int n) {
+ if (s == null || s.equals("") || delimiter == null || delimiter.isEmpty() || n == 0) {
+ return "";
+ }
+
+ String[] parts = s.split(Pattern.quote(delimiter), -1);
Review Comment:
Why do we need `Pattern.quote`?
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
Review Comment:
Add unit test to cover `REDSHIFT`? I notice this function is except for `REDSHIFT`.
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
Review Comment:
There should be three parameters?
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
+ "No match found for function signature SPLIT_PART\\(<CHARACTER>, <NUMERIC>\\)",
+ false);
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL);
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL");
+ f.checkScalar("SPLIT_PART('abc,def,ghi,jkl', ',', 3)", "ghi", "VARCHAR(15) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', -1)", "ghi", "VARCHAR(15) NOT NULL");
+ f.checkScalar("SPLIT_PART('abc,def,ghi,jkl', ',', -2)", "ghi", "VARCHAR(15) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('h,e,l,l,o', ',', 7)", "", "VARCHAR(9) NOT NULL");
+ f.checkScalar("SPLIT_PART('h,e,l,l,o', ',', -7)", "", "VARCHAR(9) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('abc,,ghi', ',', 2)", "", "VARCHAR(8) NOT NULL");
Review Comment:
Add unit test to cover NULL parameter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "caicancai (via GitHub)" <gi...@apache.org>.
caicancai commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1827143459
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,36 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
Review Comment:
Minor: Add jira link
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2452955097
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027) **Quality Gate passed**
Issues
 [2 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2451589585
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826092703
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
+ "No match found for function signature SPLIT_PART\\(<CHARACTER>, <NUMERIC>\\)",
+ false);
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL);
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL");
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "NobiGo (via GitHub)" <gi...@apache.org>.
NobiGo commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826538406
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -914,6 +914,29 @@ public static List<String> split(String s, String delimiter) {
}
}
+
+ /** SQL {@code SPLIT_PART(string, string, int)} function. */
+ public static String splitPart(String s, String delimiter, int n) {
+ if (Strings.isNullOrEmpty(s) || delimiter == null || delimiter.isEmpty() || n == 0) {
Review Comment:
This `n==0 return ''` logic is the same as the following code logic
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -914,6 +914,29 @@ public static List<String> split(String s, String delimiter) {
}
}
+
+ /** SQL {@code SPLIT_PART(string, string, int)} function. */
+ public static String splitPart(String s, String delimiter, int n) {
+ if (Strings.isNullOrEmpty(s) || delimiter == null || delimiter.isEmpty() || n == 0) {
Review Comment:
We can also simplify the 'delimiter'.
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
+ "No match found for function signature SPLIT_PART\\(<CHARACTER>, <NUMERIC>\\)",
+ false);
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL);
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL");
+ f.checkScalar("SPLIT_PART('abc,def,ghi,jkl', ',', 3)", "ghi", "VARCHAR(15) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', -1)", "ghi", "VARCHAR(15) NOT NULL");
+ f.checkScalar("SPLIT_PART('abc,def,ghi,jkl', ',', -2)", "ghi", "VARCHAR(15) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('h,e,l,l,o', ',', 7)", "", "VARCHAR(9) NOT NULL");
+ f.checkScalar("SPLIT_PART('h,e,l,l,o', ',', -7)", "", "VARCHAR(9) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('abc,,ghi', ',', 2)", "", "VARCHAR(8) NOT NULL");
Review Comment:
I noticed you did not covered the `SPLIT_PART('abc,,ghi', ',', null)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu merged PR #4027:
URL: https://github.com/apache/calcite/pull/4027
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2453740433
> 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 !
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2453762513
## [](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027) **Quality Gate passed**
Issues
 [2 New issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_calcite&pullRequest=4027&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_calcite&pullRequest=4027&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [100.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_calcite&pullRequest=4027&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_calcite&pullRequest=4027)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826500853
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -914,6 +914,29 @@ public static List<String> split(String s, String delimiter) {
}
}
+
+ /** SQL {@code SPLIT_PART(string, string, int)} function. */
+ public static String splitPart(String s, String delimiter, int n) {
+ if (s == null || s.equals("") || delimiter == null || delimiter.isEmpty() || n == 0) {
Review Comment:
Thank you @NobiGo for review, addressed in latest PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826500974
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
Review Comment:
Added the test, addressed in latest PR, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "NobiGo (via GitHub)" <gi...@apache.org>.
NobiGo commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2451741081
> 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826543622
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -914,6 +914,29 @@ public static List<String> split(String s, String delimiter) {
}
}
+
+ /** SQL {@code SPLIT_PART(string, string, int)} function. */
+ public static String splitPart(String s, String delimiter, int n) {
+ if (Strings.isNullOrEmpty(s) || delimiter == null || delimiter.isEmpty() || n == 0) {
Review Comment:
Addressed in latest PR, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "zhuqi-lucas (via GitHub)" <gi...@apache.org>.
zhuqi-lucas commented on code in PR #4027:
URL: https://github.com/apache/calcite/pull/4027#discussion_r1826501011
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
+ "No match found for function signature SPLIT_PART\\(<CHARACTER>, <NUMERIC>\\)",
+ false);
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL);
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL");
Review Comment:
Changed to VARCHAR , addressed in latest PR, thanks!
##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10901,6 +10901,26 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) {
+ "requires extra delimiter argument", false);
}
+ /** Tests the {@code SPLIT_PART} operator. */
+ @Test void testSplitPartFunction() {
+ final SqlOperatorFixture f0 = fixture().setFor(SqlLibraryOperators.SPLIT_PART);
+ f0.checkFails("^split_part('hello', 1)^",
+ "No match found for function signature SPLIT_PART\\(<CHARACTER>, <NUMERIC>\\)",
+ false);
+ final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL);
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL");
+ f.checkScalar("SPLIT_PART('abc,def,ghi,jkl', ',', 3)", "ghi", "VARCHAR(15) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', -1)", "ghi", "VARCHAR(15) NOT NULL");
+ f.checkScalar("SPLIT_PART('abc,def,ghi,jkl', ',', -2)", "ghi", "VARCHAR(15) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('h,e,l,l,o', ',', 7)", "", "VARCHAR(9) NOT NULL");
+ f.checkScalar("SPLIT_PART('h,e,l,l,o', ',', -7)", "", "VARCHAR(9) NOT NULL");
+
+ f.checkScalar("SPLIT_PART('abc,,ghi', ',', 2)", "", "VARCHAR(8) NOT NULL");
Review Comment:
Addressed in latest PR, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [CALCITE-6663] Support SPLIT_PART function for PostgreSql [calcite]
Posted by "mihaibudiu (via GitHub)" <gi...@apache.org>.
mihaibudiu commented on PR #4027:
URL: https://github.com/apache/calcite/pull/4027#issuecomment-2453773906
Will merge this after the CI completes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@calcite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org