reduce_with_python_row.sql 448 B

1234567891011121314151617
  1. /* syntax version 1 */
  2. /* postgres can not */
  3. USE plato;
  4. $udfScript = @@
  5. import functools
  6. def Len(key, input):
  7. return {"sumByVal": functools.reduce(lambda x,y: x + int(y.value), input, 0)}
  8. @@;
  9. $udf = Python3::Len(Callable<(String, Stream<Struct<key:String,subkey:String,value:String>>)->Struct<sumByVal:Uint32>>, $udfScript);
  10. --INSERT INTO Output
  11. $res = (REDUCE Input1 ON key USING $udf(TableRow()));
  12. select * from $res order by sumByVal;