static_fold.sql 978 B

123456789101112131415161718192021222324252627282930313233
  1. /* syntax version 1 */
  2. $st_many = <|a: "one", b: "two", c: "three", d: "four"|>;
  3. $st_single = <|a: "zero"|>;
  4. $st_empty = <||>;
  5. $tup = AsTuple("first", "second");
  6. $concat = ($item, $state) -> { return $state || $item; };
  7. $start = ($value) -> { return "(" || $value || ")"; };
  8. SELECT
  9. StaticFold($st_many, "->", $concat),
  10. StaticFold($st_single, "->", $concat),
  11. CAST(StaticFold($st_empty, "->", $concat) AS Optional<String>),
  12. StaticFold($tup, "->", $concat);
  13. SELECT
  14. StaticFold1($st_many, $start, $concat),
  15. StaticFold1($st_single, $start, $concat),
  16. CAST(StaticFold1($st_empty, $start, $concat) AS Optional<String>),
  17. StaticFold1($tup, $start, $concat);
  18. --WithOptionalArgs lambda test
  19. $puk = ($row_struct) -> {
  20. RETURN StaticFold(
  21. $row_struct,
  22. 0,
  23. ($item, $sum?) -> {
  24. RETURN $sum + IF($item IS NULL, 0, 1)
  25. }
  26. )
  27. };
  28. SELECT $puk(Unwrap(CAST(<|one:"8912", two:42|> AS Struct<one: Int64, two:Int64>)));