Skip to main content
Last updated on

L1_DISTANCE

Description​

Calculate the distance between two points in L1 space (vector values are coordinates)

Syntax​

L1_DISTANCE(<array1>, <array2>)

Parameters​

ParameterDescription
<array1>The first vector (the vector value is the coordinate). The subtypes of the input array are: TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE. The number of elements must be consistent with array2
<array2>The second vector (the vector value is the coordinate), the subtype of the input array supports: TINYINT, SMALLINT, INT, BIGINT, LARGEINT, FLOAT, DOUBLE, the number of elements must be consistent with array1

Return Value​

Returns the distance between two points (vector values are coordinates) in L1 space. The return type is FLOAT.

If either input array is NULL, or contains a NULL element, the function returns an error.

Example​

SELECT L1_DISTANCE([4, 5], [6, 8]),L1_DISTANCE([3, 6], [4, 5]);
+-----------------------------+-----------------------------+
| l1_distance([4, 5], [6, 8]) | l1_distance([3, 6], [4, 5]) |
+-----------------------------+-----------------------------+
| 5 | 2 |
+-----------------------------+-----------------------------+

If an input array is NULL, the function returns an error:

SELECT L1_DISTANCE(NULL, [1, 2]);
ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]First argument for function l1_distance cannot be null

If an input array contains a NULL element, the function returns an error:

SELECT L1_DISTANCE([1, NULL], [1, 2]);
ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]First argument for function l1_distance cannot have null