reduce_all_expr.sql 483 B

12345678910111213141516
  1. /* postgres can not */
  2. /* syntax version 1 */
  3. /* dqfile can not */
  4. USE plato;
  5. $udfScript = @@
  6. import functools
  7. def Len(stream):
  8. sums = [functools.reduce(lambda x,y: x + y, pair[1], 0) for pair in stream]
  9. return {"sumByAllVal":functools.reduce(lambda x,y: x + y, sums, 0)}
  10. @@;
  11. $udf = Python::Len(Callable<(Stream<Tuple<String,Stream<Uint32>>>)->Struct<sumByAllVal:Uint32>>, $udfScript);
  12. --INSERT INTO Output
  13. REDUCE Input1 ON key USING ALL $udf(cast(value as uint32) ?? 0);