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

$udfScript = @@
import functools

def Len(key, input):
    return {"sumByVal": functools.reduce(lambda x,y: x + int(y.value), input, 0)}
@@;

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

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

select * from $res order by sumByVal;