-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[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
Conversation
48434f4
to
a810f9e
Compare
9c774d8
to
246323a
Compare
select split_part('abc~@def@ghi', '@~', 2); return nothing in PG. There is a typographical error here. |
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Outdated
Show resolved
Hide resolved
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Outdated
Show resolved
Hide resolved
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Outdated
Show resolved
Hide resolved
false); | ||
final SqlOperatorFixture f = f0.withLibrary(SqlLibrary.POSTGRESQL); | ||
|
||
f.checkScalar("SPLIT_PART('abc~@~def~@~ghi', '~@~', 2)", "def", "VARCHAR(15) NOT NULL"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Outdated
Show resolved
Hide resolved
Updated, thanks! |
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Outdated
Show resolved
Hide resolved
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
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. |
5a1421b
to
08f361f
Compare
Done, thanks @mihaibudiu ! |
@@ -10901,6 +10901,36 @@ void checkEndsWith(SqlOperatorFixture f0, FunctionAlias functionAlias) { | |||
+ "requires extra delimiter argument", false); | |||
} | |||
|
|||
/** Tests the {@code SPLIT_PART} operator. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Add jira link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added now, thanks!
08f361f
to
982ed8d
Compare
|
Will merge this after the CI completes |
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.