udaf_short.sql 544 B

123456789101112131415161718192021222324252627
  1. /* postgres can not */
  2. /* syntax version 1 */
  3. $script = @@
  4. def create(item):
  5. return item
  6. def add(state, item):
  7. return state + item
  8. def merge(state_a, state_b):
  9. return state_a + state_b
  10. @@;
  11. $create = Python3::create(Callable<(Int64)->Int64>, $script);
  12. $add = Python3::add(Callable<(Int64,Int64)->Int64>, $script);
  13. $merge = Python3::merge(Callable<(Int64,Int64)->Int64>, $script);
  14. SELECT UDAF(
  15. item,
  16. $create,
  17. $add,
  18. $merge
  19. ) FROM (
  20. SELECT
  21. CAST(LENGTH(value) AS Int64) AS item
  22. FROM plato.Input
  23. );