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

$udfScript = @@
import functools
def Len(key, input):
    return {"sumByValAndKeyLen":functools.reduce(lambda x,y: x + int(y.value) + len(y.key), input, 0)}
@@;

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

--INSERT INTO Output
$res = (REDUCE Input1 ON key USING $udf(AsStruct(TableRow().value as value, TableRow().subkey as key)));

select * from $res order by sumByValAndKeyLen;