Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add doc of unhex() #579

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions docs/MatrixOne/Develop/schema-design/vector.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 |
Expand Down
39 changes: 39 additions & 0 deletions docs/MatrixOne/Reference/Functions-and-Operators/String/unhex.md
Original file line number Diff line number Diff line change
@@ -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)
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading