See if the new window function support (see the OVER clause in the SQL++ Language documentation and the Window Functions section of the Built-in Functions documentation for more info) meets your needs?  The rank or dense_rank functionality might do the trick....  (Eventually SQL++ will have positional variable support, but right now it does not; that's in progress, as it's slightly tricky in a shared-nothing parallel setting.)

On 8/16/19 2:53 AM, [email protected] wrote:
Hello everyone, apologies if this is a trivial question.

I am trying to do something like this:

================================
DROP DATAVERSE test IF EXISTS;
CREATE DATAVERSE test;
USE test;

CREATE TYPE B AS {
    B1: string,
    B2: string
};

CREATE TYPE RooTType As{
    id:uuid,
    A: string,
    B:[B]
};

CREATE DATASET  root (RooTType) PRIMARY KEY id AUTOGENERATED;

INSERT INTO root([
    {
        "A": "a1",
        "B": [{
            "B1": "b111",
            "B2": "b112"
        },
        {
            "B1": "b121",
            "B2": "b122"
        }]
    },
    {
        "A": "a2",
        "B": [{
            "B1": "b211",
            "B2": "b212"
        },
        {
            "B1": "b221",
            "B2": "b222"
        }]
    },
    {
        "A": "a3",
        "B": [{
            "B1": "b311",
            "B2": "b312"
        },
        {
            "B1": "b321",
            "B2": "b322"
        }]
    }
]);

FROM root, root.B as B
SELECT root.A, (
    FROM B
    LET I = I + 1
    SELECT B.B1, B.B2, I
) AS B;

================================

Basically I would like I to be an index of the occurrence of B being produced. Would be value 1 or 2.

Output should look like this:

[ { "A": "a1", "B": [ { "B1": "b111", "B2": "b112", "I": 1 }, { "B1": "b121", "B2": "b122", "I": 2 } ] } , { "A": "a2", "B": [ { "B1": "b211", "B2": "b212", "I": 1 }, { "B1": "b221", "B2": "b222", "I": 2 } ] } , { "A": "a3", "B": [ { "B1": "b311", "B2": "b312", "I": 1 }, { "B1": "b321", "B2": "b322", "I": 2 } ] }
 ]

Is there a way to do that?

Thank you!

Fady

Reply via email to