mihaibudiu commented on code in PR #3286:
URL: https://github.com/apache/calcite/pull/3286#discussion_r1246920157


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -7347,6 +7347,8 @@ private static void 
checkSubstringFunction(SqlOperatorFixture f) {
         "ab", "VARCHAR(3) NOT NULL");
     f.checkString("substring(x'aabbcc' from 1 for 2)",
         "aabb", "VARBINARY(3) NOT NULL");
+    f.checkString("substring('abc' from 2 for 2147483646)",

Review Comment:
   If you want to support long arguments the SqlFunction above is broken, since 
it only takes `int` arguments.
   And java string.length() returns an int, so it's unlikely that strings that 
long can be supported using regular strings.
   This is all about compile-time evaluation.
   I tried using a larger value and you get the following not very informative 
error:
   ```
   Error while executing SQL "values (substring('abc' from 2 for 2147483650))": 
Unable to implement EnumerableCalc(expr#0=[{inputs}], expr#1=['abc'], 
expr#2=[2], expr#3=[2147483650:BIGINT], expr#4=[SUBSTRING($t1, $t2, $t3)], 
EXPR$0=[$t4]): rowcount = 1.0, cumulative cost = {2.0 rows, 7.0 cpu, 0.0 io}, 
id = 153424
     EnumerableValues(tuples=[[{ 0 }]]): rowcount = 1.0, cumulative cost = {1.0 
rows, 1.0 cpu, 0.0 io}, id = 153408
   ```
   So this is probably a deeper issue about validating (or truncating?) 
arguments that may be out of bounds, which, I suspect, may affect all the 
functions, not just substring. I can file an issue about that.
   



-- 
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]

Reply via email to