aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/produce/reduce_all.sql
blob: 89362a445466429ae0ccbde31d5bfd4098d5d7db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* syntax version 1 */
/* postgres can not */
/* dqfile can not */
USE plato;

$udfScript = @@
import functools
def Len(stream):
    sums = [functools.reduce(lambda x,y: x + int(y.value), pair[1], 0) for pair in stream]
    return {"sumByAllVal":functools.reduce(lambda x,y: x + y, sums, 0)}
@@;

$udf = Python::Len(Callable<(Stream<Tuple<String,Stream<Struct<key:String,subkey:String,value:String>>>>)->Struct<sumByAllVal:Uint32>>, $udfScript);

--INSERT INTO Output
REDUCE Input1 ON key USING ALL $udf(TableRow());