emptyOVO commented on code in PR #10904:
URL: https://github.com/apache/inlong/pull/10904#discussion_r1734354903

##########
inlong-sdk/transform-sdk/src/test/java/org/apache/inlong/sdk/transform/process/TestTransformArithmeticFunctionsProcessor.java:
##########
@@ -619,4 +619,33 @@ public void testRandFunction() throws Exception {
         Assert.assertTrue(result >= 0.0 && result < 1.0);
     }
 
+    @Test
+    public void testHexFunction() throws Exception {
+        String transformSql1 = "select hex(numeric1) from source";
+        TransformConfig config1 = new TransformConfig(transformSql1);
+        TransformProcessor<String, String> processor1 = TransformProcessor
+                .create(config1, 
SourceDecoderFactory.createCsvDecoder(csvSource),
+                        SinkEncoderFactory.createKvEncoder(kvSink));
+        // case: hex(1007)
+        List<String> output1 = processor1.transform("1007|4|6|8", new 
HashMap<>());
+        Assert.assertEquals(1, output1.size());
+        Assert.assertEquals(output1.get(0), "result=3EF");
+        // case: hex(3.14)
+        List<String> output2 = processor1.transform("3.14|4|6|8", new 
HashMap<>());
+        Assert.assertEquals(1, output2.size());
+        Assert.assertEquals(output2.get(0), "result=3");
+        // case: hex(3.141592653589793)
+        List<String> output3 = processor1.transform("3.141592653589793|4|6|8", 
new HashMap<>());
+        Assert.assertEquals(1, output3.size());
+        Assert.assertEquals(output3.get(0), "result=3");
+        // case: hex(9223372036854775807)
+        List<String> output4 = 
processor1.transform("-9223372036854775808|4|6|8", new HashMap<>());
+        Assert.assertEquals(1, output4.size());
+        Assert.assertEquals(output4.get(0), "result=8000000000000000");

Review Comment:
   > The result is not correct?HEX(-9223372036854775808) should be 
-8000000000000000.
   
   Because the HEX function is converted based on the binary complement 
representation of the numeric value.
   In binary complement notation, the binary representation of 
-9223372036854775808 is the same as the unsigned 9223372036854775808. So, when 
you convert this binary number to a hexadecimal string, the result is 
8000000000000000 without the negative sign
   This behavior is standard in systems that use binary complement 
representations, including programming environments such as Java and SQL



-- 
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-unsubscr...@inlong.apache.org

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

Reply via email to