From 2354926e92a48f9210f510001c7ca87caf310a4b Mon Sep 17 00:00:00 2001 From: yangj1211 Date: Tue, 21 May 2024 15:40:49 +0800 Subject: [PATCH] add doc of unhex() --- .../MatrixOne/Develop/schema-design/vector.md | 9 ++--- .../Functions-and-Operators/String/unhex.md | 39 +++++++++++++++++++ mkdocs.yml | 1 + 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 docs/MatrixOne/Reference/Functions-and-Operators/String/unhex.md diff --git a/docs/MatrixOne/Develop/schema-design/vector.md b/docs/MatrixOne/Develop/schema-design/vector.md index 4362d75ef..b8a43846f 100644 --- a/docs/MatrixOne/Develop/schema-design/vector.md +++ b/docs/MatrixOne/Develop/schema-design/vector.md @@ -51,12 +51,9 @@ insert into t1 values(1, "[1,2,3]", "[4,5,6]"); Suppose you are working with Python NumPy arrays. In that case, you can directly insert the NumPy array into MatrixOne by performing hexadecimal encoding on the array instead of converting it into a comma-separated textual format. This approach is faster when inserting vectors with higher dimensions. ```sql -insert into t1 (a, b) values -(2, decode("7e98b23e9e10383b2f41133f", "hex")); +insert into t1 (a, b) values (2, cast(unhex("7e98b23e9e10383b2f41133f") as blob)); -- "7e98b23e9e10383b2f41133f" represents the hexadecimal encoding of the little-endian []float32{0.34881967, 0.0028086076, 0.5752134} - --- "hex" represents hexadecimal encoding ``` ### Querying @@ -81,9 +78,9 @@ mysql> select a, b from t1; The binary format is very useful if you need to directly read the vector result set into a NumPy array with minimal conversion cost. ```sql -mysql> select encode(b, "hex") from t1; +mysql> select hex(b) from t1; +--------------------------+ -| encode(b, hex) | +| hex(b) | +--------------------------+ | 0000803f0000004000004040 | | 7e98b23e9e10383b2f41133f | diff --git a/docs/MatrixOne/Reference/Functions-and-Operators/String/unhex.md b/docs/MatrixOne/Reference/Functions-and-Operators/String/unhex.md new file mode 100644 index 000000000..fdab7b212 --- /dev/null +++ b/docs/MatrixOne/Reference/Functions-and-Operators/String/unhex.md @@ -0,0 +1,39 @@ +# **UNHEX()** + +## **Description** + +For a string argument str, `UNHEX()` interprets each pair of characters in the argument as a hexadecimal number and converts it to the byte represented by the number. The return value is a binary string. + +The characters in the argument string must be legal hexadecimal digits: '0' .. '9', 'A' .. 'F', 'a' .. 'f'. If the argument contains any nonhexadecimal digits, or is itself NULL, the result is NULL. + +## **Syntax** + +``` +> UNHEX(str) +``` + +## **Arguments** + +| Arguments | Description | +| ---- | ---- | +| str | Required. Legal hexadecimal string. | + +## **Examples** + +```SQL +mysql> SELECT UNHEX('4d6174726978204f726967696e'); ++-----------------------------------+ +| unhex(4d6174726978204f726967696e) | ++-----------------------------------+ +| Matrix Origin | ++-----------------------------------+ +1 row in set (0.00 sec) + +mysql> select unhex(NULL); ++-------------+ +| unhex(null) | ++-------------+ +| NULL | ++-------------+ +1 row in set (0.00 sec) +``` diff --git a/mkdocs.yml b/mkdocs.yml index cb64abadb..de06ec38d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -505,6 +505,7 @@ nav: - SUBSTRING(): MatrixOne/Reference/Functions-and-Operators/String/substring.md - SUBSTRING_INDEX(): MatrixOne/Reference/Functions-and-Operators/String/substring-index.md - TRIM(): MatrixOne/Reference/Functions-and-Operators/String/trim.md + - UNHEX(): MatrixOne/Reference/Functions-and-Operators/String/unhex.md - Regular Expressions: - Regular Expressions Overview: MatrixOne/Reference/Functions-and-Operators/String/Regular-Expressions/Regular-Expression-Functions-Overview.md - NOT REGEXP: MatrixOne/Reference/Functions-and-Operators/String/Regular-Expressions/not-regexp.md