You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "korlov42 (via GitHub)" <gi...@apache.org> on 2023/11/01 10:53:11 UTC

Re: [PR] IGNITE-20660 SQL: broken behaviour of OCTET_LENGTH function [ignite-3]

korlov42 commented on code in PR #2769:
URL: https://github.com/apache/ignite-3/pull/2769#discussion_r1378636547


##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/datatypes/varbinary/ItVarBinaryExpressionTest.java:
##########
@@ -93,6 +93,10 @@ public void testLengthExpressionWithDynamicParameter() {
                 .withParams(new byte[0])
                 .returns(0).check();
 
+        checkQuery("SELECT OCTET_LENGTH(?)")
+                .withParams("123")

Review Comment:
   this test class dedicated to VarBinary type, not VarChar



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/exp/IgniteSqlFunctions.java:
##########
@@ -125,7 +125,12 @@ public static String toString(ByteString b) {
 
     /** LENGTH(VARBINARY|VARCHAR). */
     public static int length(Object b) {
-        return b instanceof ByteString ? octetLength((ByteString) b) : charLength((String) b);
+        return b instanceof ByteString ? SqlFunctions.octetLength((ByteString) b) : charLength((String) b);
+    }
+
+    /** OCTET_LENGTH(VARBINARY|VARCHAR). */
+    public static int octetLength(Object s) {

Review Comment:
   it's better to have overloaded version for every supported type of parameters



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItFunctionsTest.java:
##########
@@ -68,6 +68,13 @@ public void testLength() {
         assertQuery("SELECT LENGTH(NULL)").returns(NULL_RESULT).check();
     }
 
+    @Test
+    public void testOctetLength() {
+        assertQuery("SELECT OCTET_LENGTH('TEST')").returns(4).check();

Review Comment:
   let's also add different tests for different languages to make sure OCTET_LENGTH differs from regular LENGTH



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org