tanishq-chugh commented on code in PR #6471:
URL: https://github.com/apache/hive/pull/6471#discussion_r3290564817


##########
ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFUnhex.java:
##########
@@ -40,8 +42,41 @@ public void testUnhexConversion(){
     UDFUnhex udf = new UDFUnhex();
     byte[] output = udf.evaluate(hex);
     assertEquals(expected.length,output.length);
-    for (int i = 0; i < expected.length; i++){
-      assertEquals(expected[i], output[i]);
-    }
+    assertArrayEquals(expected, output);
+  }
+
+  @Test
+  public void testUnhexOddLength() {
+    UDFUnhex udf = new UDFUnhex();
+
+    Text hex1 = new Text("A");
+    byte[] expected1 = new byte[] {(byte) 0x0A};
+    assertArrayEquals(expected1, udf.evaluate(hex1));
+
+    Text hex2 = new Text("123");
+    byte[] expected2 = new byte[] {(byte) 0x01, (byte) 0x23};
+    assertArrayEquals(expected2, udf.evaluate(hex2));
+  }
+
+  @Test
+  public void testUnhexInvalidCharacters() {
+    UDFUnhex udf = new UDFUnhex();
+
+    Text hex = new Text("7374G9");
+    assertNull("Should return null for invalid hex characters", 
udf.evaluate(hex));
+
+    Text hexOddInvalid = new Text("12G");
+    assertNull("Should return null for invalid hex characters in odd length 
string", udf.evaluate(hexOddInvalid));
+  }
+
+  @Test
+  public void testUnhexNullEmptyCases() {
+    UDFUnhex udf = new UDFUnhex();
+
+    assertNull(udf.evaluate(null));
+
+    Text hexEmpty = new Text("");
+    byte[] expectedEmpty = new byte[0];
+    assertArrayEquals(expectedEmpty, udf.evaluate(hexEmpty));
   }

Review Comment:
   Have added these test cases in commit: 
[254027f](https://github.com/apache/hive/pull/6471/commits/254027f42517e7e1fda76d355c1ef31aade3b4ae)
   
   >Also, maybe not in this file, but are there any tests for hex(unhex(...)) 
and unhex(hex(..))?
   
   I see the `UNHEX(HEX(...))` case being used in `ba_table_udfs.q` QTest, but 
i don't think `HEX(UNHEX(...))` is a valid scenario, what do you think? please 
feel free to correct me if i am wrong here.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to