Skip to content

Instantly share code, notes, and snippets.

@aucker
Created September 3, 2022 06:30
Show Gist options
  • Save aucker/70b9f4b18e17081f987f0299d9608df8 to your computer and use it in GitHub Desktop.
Save aucker/70b9f4b18e17081f987f0299d9608df8 to your computer and use it in GitHub Desktop.
impl the `unhex` function in OpenMLDB

I want to add the new built-in function in OpenMLDB, called unhex. The unhex has the following action just like Spark SQL and MySQL.

Spark SQL:

spark-sql> select unhex(hex('Spark SQL'));
Spark SQL
Time taken: 2.163 seconds, Fetched 1 row(s)
spark-sql> select unhex(hex(14));

Time taken: 0.065 seconds, Fetched 1 row(s)
spark-sql> select unhex(hex(50));
2
Time taken: 0.056 seconds, Fetched 1 row(s)
spark-sql> select hex('Spark SQL');
537061726B2053514C
Time taken: 0.072 seconds, Fetched 1 row(s)
spark-sql> select unhex('537061726B2053514C');
Spark SQL
Time taken: 0.04 seconds, Fetched 1 row(s)

MySQL:

mysql> select hex('MySQL');
+--------------+
| hex('MySQL') |
+--------------+
| 4D7953514C   |
+--------------+
1 row in set (0.00 sec)

mysql> select unhex('4D7953514C');
+---------------------+
| unhex('4D7953514C') |
+---------------------+
| MySQL               |
+---------------------+
1 row in set (0.00 sec)

mysql> select unhex(hex('MySQL'));
+---------------------+
| unhex(hex('MySQL')) |
+---------------------+
| MySQL               |
+---------------------+
1 row in set (0.00 sec)

mysql> select unhex(hex(14));
+----------------+
| unhex(hex(14)) |
+----------------+
|               |
+----------------+
1 row in set (0.00 sec)

mysql> select unhex(hex(50));
+----------------+
| unhex(hex(50)) |
+----------------+
| 2              |
+----------------+
1 row in set (0.01 sec)

As you can see, the unhex function can successfully unhex the String but can't unhex the int or double. Weird.🤔🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment