mihaibudiu commented on code in PR #3904:
URL: https://github.com/apache/calcite/pull/3904#discussion_r1705880323
##########
core/src/test/java/org/apache/calcite/test/SqlFunctionsTest.java:
##########
@@ -172,6 +173,58 @@ static <E> List<E> list() {
assertThat(concat(null, "b"), is("nullb"));
}
+ @Test void testSubString() {
+ // str vs single param
+ assertThat(substring("string", -1), is("string"));
+ assertThat(substring("string", -1L), is("string"));
+ assertThat(substring("string", 2), is("tring"));
+ assertThat(substring("string", 2L), is("tring"));
+ assertThat(substring("string", Integer.MIN_VALUE), is("string"));
+ assertThat(substring("string", Long.MIN_VALUE), is("string"));
+ assertThat(substring("string", Integer.MIN_VALUE + 10), is("string"));
+ assertThat(substring("string", Integer.MAX_VALUE), is(""));
+ assertThat(substring("string", Long.MAX_VALUE), is(""));
+ assertThat(substring("string", Integer.MAX_VALUE - 10), is(""));
+ assertThat(substring("string", Integer.MIN_VALUE - 10L), is("string"));
+ assertThat(substring("string", Integer.MAX_VALUE + 10L), is(""));
+
+ // str vs multi params
+ assertThat(substring("string", -1, 1), is(""));
Review Comment:
As I said, one can imagine that negative s is first clamped to 0 and then
the function is evaluated with 0 and an unchanged l.
Does the reference.md file document this behavior?
It's also not obvious to me that substring's behavior is defined by Postgres.
According to
https://calcite.apache.org/docs/reference.html#character-string-operators-and-functions
it is a standard function.
We have seen many cases where various SQL dialects treat corner cases
differently for function implementations (but this may be out of scope for the
current 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]