Functions for Working with Tuples

    The function implements the operator .

    Syntax

    A function that allows getting a column from a tuple.
    ‘N’ is the column index, starting from 1. N must be a constant. ‘N’ must be a constant. ‘N’ must be a strict postive integer no greater than the size of the tuple.
    There is no cost to execute the function.

    The function implements the operator x.N.

    Syntax

    1. tupleElement(tuple, n)

    Performs syntactic substitution of tuple elements in the call location.

    Syntax

    1. untuple(x)

    You can use the EXCEPT expression to skip columns as a result of the query.

    Arguments

    • x — A tuple function, column, or tuple of elements. .
    • None.

    Examples

    Input table:

    1. ┌─key─┬─v1─┬─v2─┬─v3─┬─v4─┬─v5─┬─v6────────┐
    2. 1 10 20 40 30 15 (33,'ab')
    3. 2 25 65 70 40 6 (44,'cd')
    4. 3 57 30 20 10 5 (55,'ef')
    5. 5 30 50 70 25 55 (77,'kl')

    Example of using a Tuple-type column as the untuple function parameter:

    Query:

    Result:

    1. ┌─_ut_1─┬─_ut_2─┐
    2. 33 ab
    3. 44 cd
    4. 55 ef
    5. 66 gh
    6. 77 kl
    7. └───────┴───────┘

    Note: the names are implementation specific and are subject to change. You should not assume specific names of the columns after application of the untuple.

    Example of using an EXCEPT expression:

    Query:

    1. SELECT untuple((* EXCEPT (v2, v3),)) FROM kv;

    Result:

    1. 1 10 30 15 (33,'ab')
    2. 3 57 10 5 (55,'ef')
    3. 4 55 80 90 (66,'gh')
    4. 5 30 25 55 (77,'kl')
    5. └─────┴────┴────┴────┴───────────┘

    Returns the between two tuples of the same size.

    Syntax

    Arguments

    • tuple1 — First tuple. Tuple.
    • tuple2 — Second tuple. .

    Tuples should have the same type of the elements.

    Returned value

    • The Hamming distance.

    Type: UInt8.

    Examples

    Query:

    1. SELECT tupleHammingDistance((1, 2, 3), (3, 2, 1)) AS HammingDistance;

    Result:

    1. ┌─HammingDistance─┐
    2. 2
    3. └─────────────────┘

      Result: