Movatterモバイル変換


[0]ホーム

URL:


JSON_ARRAY_PACK

Converts a JSON array of zero or more floating point numbers to an encoded blob.

It is a scalar function.

Syntax

JSON_ARRAY_PACK('[float [, ...]]')

Arguments

A JSON array.

Return Type

A blob containing packed single-precision floating-point numbers in little-endian byte order.

Warning

Beginning with 8.5 the blob data type will be replaced with the vector data type. Blob data types will be deprecated for vector databases.

Remarks

JSON_ARRAY_PACK() can be used with other vector built-in functions, namelyDOT_PRODUCT(),VECTOR_ADD(),VECTOR_MUL(),VECTOR_SUB(), andEUCLIDEAN_DISTANCE(). These functions require two input vectors that are encoded as blobs containing packed single-precision or double-precision floating-point numbers in little-endian byte order. The vector returned byJSON_ARRAY_PACK() is appropriately formatted for use as an input parameter to these functions.

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. Omitting the suffix from the function is equivalent to suffixing it with_F32. All operations are done using the specified data type. The following table lists the suffixes and their data type.

Suffix

Data Type

_I8

8-bit signed integer

_I16

16-bit signed integer

_I32

32-bit signed integer

_I64

64-bit signed integer

_F32

32-bit floating-point number (IEEE standard format)

_F64

64-bit floating-point number (IEEE standard format)

Examples

Example: Inserting Data Using JSON_ARRAY_PACK()

The following example inserts data into a table with a column of theBLOB data type. In this example, theHEX() built-in function is also used to return a readable form of the binary output:

CREATETABLE jp_t(bblob);
INSERTINTO jp_tVALUES(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'));
SELECT HEX(b)FROM jp_t;
+--------------------------+| HEX(b)                   |+--------------------------+| 0000803F0000003F00000040 |+--------------------------+

You can also use the suffix to specify the data type as follows:

INSERTINTO jp_tVALUES(JSON_ARRAY_PACK_I16('[1.0, 0.5, 2.0]'));
SELECT HEX(b)FROM jp_t;
+--------------+| HEX(b)       |+--------------+| 010001000200 |+--------------+

Example: Using JSON_ARRAY_PACK() with DOT_PRODUCT()

The following example usesJSON_ARRAY_PACK() for input parameters to theDOT_PRODUCT() built-in function:

SELECT DOT_PRODUCT(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'));
+-------------------------------------------------------------------------------------+| DOT_PRODUCT(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[1.0, 0.5, 2.0]')) |+-------------------------------------------------------------------------------------+|                                                                                5.25 |+-------------------------------------------------------------------------------------+

Example: Using JSON_ARRAY_PACK() with VECTOR_SUB()

The following example usesJSON_ARRAY_PACK() for input parameters to theVECTOR_SUB() built-in function. TheHEX() built-in function is also used to return a readable form of the binary output:

SELECT HEX(VECTOR_SUB(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]')));
+-----------------------------------------------------------------------------------------+| HEX(VECTOR_SUB(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]'))) |+-----------------------------------------------------------------------------------------+| 9A99993E9A99993E9899993E                                                                |+-----------------------------------------------------------------------------------------+

Example: Using JSON_ARRAY_PACK() with EUCLIDEAN_DISTANCE()

The following example usesJSON_ARRAY_PACK() for input parameters to theEUCLIDEAN_DISTANCE() built-in function:

SELECT EUCLIDEAN_DISTANCE(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]'));
+--------------------------------------------------------------------------------------------+| EUCLIDEAN_DISTANCE(JSON_ARRAY_PACK('[1.0, 0.5, 2.0]'), JSON_ARRAY_PACK('[0.7, 0.2, 1.7]')) |+--------------------------------------------------------------------------------------------+|                                                                         0.5196152239171921 |+--------------------------------------------------------------------------------------------+

Related Topics

Last modified: March 21, 2024

Was this article helpful?

Was this article helpful?

Verification instructions

Note: You must installcosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity ofsinglestoredb-server,singlestoredb-toolbox,singlestoredb-studio, andsinglestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can runcosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click theDownload Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined|
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC\
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker\
    --bundle undefined\
    --new-bundle-format -
    Verified OK

[8]ページ先頭

©2009-2025 Movatter.jp