caicancai commented on code in PR #4172:
URL: https://github.com/apache/calcite/pull/4172#discussion_r1933533786


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5823,6 +5823,38 @@ void testBitGetFunc(SqlOperatorFixture f, String 
functionName) {
     f0.forEachLibrary(libraries, consumer);
   }
 
+  @Test void testHex() {

Review Comment:
   Add jira link



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5823,6 +5823,38 @@ void testBitGetFunc(SqlOperatorFixture f, String 
functionName) {
     f0.forEachLibrary(libraries, consumer);
   }
 
+  @Test void testHex() {
+    SqlOperatorFixture sqlOperatorFixture = fixture();
+    final SqlOperatorFixture f0 = 
sqlOperatorFixture.setFor(SqlLibraryOperators.HEX);
+    f0.checkFails("^hex('')^",
+        "No match found for function signature HEX\\(<CHARACTER>\\)",
+        false);
+    final Consumer<SqlOperatorFixture> consumer = f -> {
+      f.checkString("hex('abc')",
+          "616263",
+          "VARCHAR NOT NULL");
+      f.checkString("hex('')", "", "VARCHAR NOT NULL");
+      f.checkNull("hex(cast(null as varbinary))");
+    };
+    f0.forEachLibrary(list(SqlLibrary.HIVE, SqlLibrary.SPARK), consumer);
+  }
+
+  @Test void testUnHex() {
+    SqlOperatorFixture sqlOperatorFixture = fixture();
+    final SqlOperatorFixture f0 = 
sqlOperatorFixture.setFor(SqlLibraryOperators.UNHEX);
+    f0.checkFails("^unhex('')^",
+        "No match found for function signature UNHEX\\(<CHARACTER>\\)",
+        false);
+    final Consumer<SqlOperatorFixture> consumer = f -> {
+      f.checkString("unhex('616263')",
+          "abc",
+          "VARCHAR NOT NULL");
+      f.checkString("unhex('')", "", "VARCHAR NOT NULL");
+      f.checkNull("unhex(cast(null as varbinary))");

Review Comment:
   You need to add more tests
   
   e.g. 
   ```
   scala> val df = spark.sql("select unhex(null)")
   df: org.apache.spark.sql.DataFrame = [unhex(NULL): binary]
   
   scala> df.show()
   +-----------+
   |unhex(NULL)|
   +-----------+
   |       null|
   +-----------+
   
   
   scala> val df = spark.sql("select unhex(0)")
   df: org.apache.spark.sql.DataFrame = [unhex(0): binary]
   
   scala> df.show()
   +--------+
   |unhex(0)|
   +--------+
   |    [00]|
   +--------+
   
   
   scala> val df = spark.sql("select unhex(-1)")
   df: org.apache.spark.sql.DataFrame = [unhex(-1): binary]
   
   scala> df.show()
   +---------+
   |unhex(-1)|
   +---------+
   |     null|
   +---------+
   
   
   ```



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -5823,6 +5823,38 @@ void testBitGetFunc(SqlOperatorFixture f, String 
functionName) {
     f0.forEachLibrary(libraries, consumer);
   }
 
+  @Test void testHex() {
+    SqlOperatorFixture sqlOperatorFixture = fixture();
+    final SqlOperatorFixture f0 = 
sqlOperatorFixture.setFor(SqlLibraryOperators.HEX);
+    f0.checkFails("^hex('')^",
+        "No match found for function signature HEX\\(<CHARACTER>\\)",
+        false);
+    final Consumer<SqlOperatorFixture> consumer = f -> {
+      f.checkString("hex('abc')",
+          "616263",
+          "VARCHAR NOT NULL");
+      f.checkString("hex('')", "", "VARCHAR NOT NULL");
+      f.checkNull("hex(cast(null as varbinary))");

Review Comment:
   above all



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