Important
Helios features are now enabled during weekly update windows and are no longer directly tied to SingleStore engine releases. Refer to the release notes to view the latest features available in your Helios cluster.
JSON_ ARRAY_ UNPACK
On this page
The JSON_ function converts an encoded blob representing a vector to a JSON array representing the same vector.
It is a scalar function.
Syntax
JSON_ARRAY_UNPACK(vector_expression)
Arguments
-
vector_: An expression that evaluates to a vector.expression The vector must be encoded as a blob containing packed single-precision or double-precision floating-point numbers in little-endian byte order.
Return Type
A JSON array of zero or more floating point numbers.
Warning
Beginning with 8.
Remarks
A vector can be of any length, but blob lengths must be divisible by 4 bytes (or 8 bytes, depending on the data type specified).
You can specify the data type of the vector elements in which this operation is performed on the vector by adding a suffix to the function._.
|
Suffix |
Data Type |
|---|---|
|
|
8-bit signed integer |
|
|
16-bit signed integer |
|
|
32-bit signed integer |
|
|
64-bit signed integer |
|
|
32-bit floating-point number (IEEE standard format) |
|
|
64-bit floating-point number (IEEE standard format) |
Examples
The following examples use the ju_ table.
CREATE TABLE ju_t (x BLOB, y BLOB);INSERT INTO ju_t VALUES (JSON_ARRAY_PACK('[12.1, 6.4]'), JSON_ARRAY_PACK('[8.6,9.2]'));INSERT INTO ju_t VALUES (JSON_ARRAY_PACK('[5.2, 11.7]'), JSON_ARRAY_PACK('[4.6,7.3]'));
Querying Rows Using JSON_ ARRAY_ UNPACK
The following example queries the t table using the JSON_ function:
SELECT JSON_ARRAY_UNPACK(x) "x", JSON_ARRAY_UNPACK(y) "y" from ju_t;
+-------------------------+-------------------------+
| x | y |
+-------------------------+-------------------------+
| [12.1000004,6.4000001] | [8.60000038,9.19999981] |
| [5.19999981,11.6999998] | [4.5999999,7.30000019] |
+-------------------------+-------------------------+Typecasting the Data Type using Suffixes
The values inserted in the t table are 32-bit floating point numbers, because no suffix was specified with the JSON_ function.
SELECT JSON_ARRAY_UNPACK_I32(x) "x", JSON_ARRAY_UNPACK_I32(y) "y" from ju_t;
+-------------------------+-------------------------+
| x | y |
+-------------------------+-------------------------+
| [1094818202,1087163597] | [1091148186,1091777331] |
| [1084647014,1094398771] | [1083388723,1089051034] |
+-------------------------+-------------------------+Related Topics
Last modified: