reduce_all_opt.sql 527 B

12345678910111213141516
  1. /* syntax version 1 */
  2. /* postgres can not */
  3. /* dqfile can not */
  4. USE plato;
  5. $udfScript = @@
  6. import functools
  7. def Len(stream):
  8. sums = [functools.reduce(lambda x,y: x + int(y.value), 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<Struct<key:String,subkey:String,value:String>>>>)->Optional<Struct<sumByAllVal:Uint32>>>, $udfScript);
  12. --INSERT INTO Output
  13. REDUCE Input1 ON key USING ALL $udf(TableRow());