0

I have a function which takes array input. I want to execute the function logic for each item in the array and combine each output in single dynamic output column. I'm able to achieve it for single input. Is it possible to do for multiple inputs ?

let T = datatable(a:string, b:dynamic)
[
    "hello", dynamic({"A":1,"B":2,"value1":3}),
    "world", dynamic({"value1":4,"value2":5}),
];

let F = (T:(b:dynamic), input: dynamic) {
    **//for each item in input. Combine b.value1 and return dynamic new column** 
    T | project b.value1
};
let input= dynamic(["input1", "input2"]);

// for each row in the table, function F is invoked
T | invoke F(input)

final view looks like

a                                   b                          new_ouput_column
hello                  {"A": 1,"B": 2,"value1": 3}       {"input1": 3,"input2": 3}
world                  {"value1": 4,"value2": 5  }       {"input1": 4,"input2": 4}

1 Answer 1

0

Is it possible to do for multiple inputs ?

Yes, it is possible with multiple inputs. Try by using mv-apply key = input iterates over each value in input and tostring(key) ensures each input key is treated as a string. In below code pack(tostring(key), b.value1) is used, which creates { "input1": b.value1, "input2": b.value1 } dynamically. Now make_bag() aggregates the results into a single dynamic object per row.

let T = datatable(a:string, b:dynamic)
[
    "hello", dynamic({"A":1,"B":2,"value1":3}),
    "world", dynamic({"value1":4,"value2":5})
];

let input = dynamic(["input1", "input2"]);

T
| mv-apply key = input on 
(
    summarize new_output_column = make_bag(pack(tostring(key), b.value1))
)

Output: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.