VECTOR_ENFORCE
VECTOR_ENFORCE(array, length, type)
Returns the input vector if it fulfills the length and type requirements. Otherwise returns null
. Input the length argument as an int
and the type argument as the string
, int
, or float
.
Use VECTOR_ENFORCE
within your ingest transformations to ensure compatibility between vectors during query execution. VECTOR_ENFORCE
also signals to Rockset that the ingested array should be treated as a vector for storage and access optimizations.
SELECT VECTOR_ENFORCE([1, 2, 3], 3, 'int')
SELECT VECTOR_ENFORCE([1, 2, 3], 3, 'float')
SELECT VECTOR_ENFORCE([1.5, 2.6, 3.7, 4.8], 4, 'float')
SELECT VECTOR_ENFORCE([1.5, 2.6, 3.7, 4.8], 1, 'float')
SELECT VECTOR_ENFORCE('[1.5, 2.6, 3.7, 4.8]', 4, 'float')
SELECT VECTOR_ENFORCE(JSON_PARSE('[1.5, 2.6, 3.7, 4.8]'), 4, 'float')
VECTOR_ADD
VECTOR_ADD(array, addend)
Adds a scalar of type int
or float
to a vector. Alternatively, adds two vectors.
SELECT VECTOR_ADD([1, 2, 3, 4], 4)
SELECT VECTOR_ADD([1, 2, 3, 4], [5, 6, 7, 8])
SELECT VECTOR_ADD([1.5, 2.6, 3.7, 4.8], 4.4)
SELECT VECTOR_ADD([1.1, 2.2, 3.3, 4.3], [1.5, 2.6, 3.7, 4.8])
SELECT VECTOR_ADD([1.1, 2.2, 3.3, 4.3], ['0':1.5, '1':2.6, '2':3.7, '3':4.8])
VECTOR_SUBTRACT
VECTOR_SUBTRACT(array, subtrahend)
Subtracts a scalar of type int
or float
from a vector. Alternatively, subtracts a vector from another vector.
SELECT VECTOR_SUBTRACT([5, 6, 7, 8], 4)
SELECT VECTOR_SUBTRACT([5, 6, 7, 8], [1, 2, 3, 4])
SELECT VECTOR_SUBTRACT([5.1, 6.2, 7.3, 8.4], 4.4)
SELECT VECTOR_SUBTRACT([5.5, 6.6, 7.7, 8.8], [1.1, 2.2, 3.3, 4.4])
SELECT VECTOR_SUBTRACT([1.1], [5.5, 6.6, 7.7, 8.8])
VECTOR_MULTIPLY
VECTOR_MULTIPLY(array, multiplier)
Multiplies a vector by a scalar of type int
or float
or computes the element-wise multiplication of two vectors as the Hadamard product.
SELECT VECTOR_MULTIPLY([1, 2, 3, 4], 2)
SELECT VECTOR_MULTIPLY([1, 2, 3, 4], [1, 2, 3 , 4])
SELECT VECTOR_MULTIPLY([5, 6, 7, 8], 1.5)
SELECT VECTOR_MULTIPLY([5.5, 6.6, 7.7, 8.8], [5.5, 6.6, 7.7, 8.8])
SELECT VECTOR_MULTIPLY([5.5, 6.6, 7.7, 8.8], [5.5, 6.6, 7.7, 'foo'])
VECTOR_DIVIDE
VECTOR_DIVIDE(array, divisor)
Divides a vector by a scalar of type int
or float
or computes the element-wise divison of two vectors. Throws an error when division by zero occurs.
SELECT VECTOR_DIVIDE([2, 4, 6, 8], 2)
SELECT VECTOR_DIVIDE([2, 4, 6, 8], [2, 4, 6, 8])
SELECT VECTOR_DIVIDE([2.2, 4.4, 6.6, 8.8], 2.2)
SELECT VECTOR_DIVIDE([2.2, 4.4, 6.6, 8.8], [2.2, 4.4, 6.6, 8.8])
SELECT VECTOR_DIVIDE([2, 4, 6, 8], 0)
SELECT VECTOR_DIVIDE([2.2, 4.4, 6.6, 8.8], [2.2, 4.4, 0.0, 0.0])