aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/produce/reduce_multi_in.sql
blob: c819fb4a583f54bdec62eb4c105e6808eb1fde53 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* syntax version 1 */
/* postgres can not */
USE plato;

$udf = YQL::@@
(lambda '(key stream) 
    (PartitionByKey stream
        (lambda '(item) (Way item))
        (Void)
        (Void)
        (lambda '(listOfPairs)
            (FlatMap listOfPairs
                (lambda '(pair) (Just (AsStruct '('key key) '('src (Nth pair '0)) '('cnt (Length (ForwardList (Nth pair '1)))))))
            )
        )
    )
)
@@;

$r = (REDUCE Input, Input ON key USING $udf(TableRow()));

SELECT key, src, cnt FROM $r ORDER BY key, src, cnt;