aoc_1211.slt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # https://github.com/MaterializeInc/advent-of-code-2023/blob/main/week1/aoc_1211.md
  10. mode cockroach
  11. statement ok
  12. CREATE TABLE input (input TEXT);
  13. statement ok
  14. INSERT INTO input VALUES (
  15. '#?##..#?.???..##??...??....#....?....#?...#.?..?.#...#....?#..#..##...???.##?...?#####.....##..?.??.?........?.#..#?##..#.###??......??.?#..
  16. .#...#.#?.#...?.#??..##.?##?.#......##.?...?...??#.?.?..?.###??.#.......#...?#.##.##.?#.#?..##?#.###.?..#.#?........?.??##..#?....##...?..??
  17. ?.#..###????#.?.#....?#.?.?.?.#.?..?.#.#.#.?.#.??..?.??#????.?.#.#.?...#.#..?#?#?.#...?..#.#...?.?#?.?...#?..?.?.?##.??.?.#......#.??....##.
  18. ..#.....?.??..#?...?##?....#??.###??.#.#.#..?.#?..?##..?.?##..##.##?.#?..??#?..#.?.#....#??.?.?.?.??#?#.#...?.#?.??.#??.?.?#.#...?...??#..?#
  19. #.??..#?.?....#.?.?.##.#...???...??.#.#..?..##...?.??.###.???#..#??....?.??.?#?#?...#??....?#.?#?...?..#..#.?..?.?..#.#.#.#...#.??..#.#.?#..
  20. ..##....?....#.??..?.#..?#.?#?..?#?..?....#..??....##?#..##?.#.?.?..??.#......#...#.?.#.#..?...............###?.##.?##..#???##??.?.?###...?.
  21. #.#..#####??#??##.###...#.#.#.#.####..?#.?.##...#.##..#.#..#.?.#.#?.#.#...?....??#.#..?#.##..##?......#?.#.#..?.......#?.?.....#..?.#.#??##.
  22. .##.?.##..?#.##..?#.#....#...##.?.#?#...##??.#?##.?..?#...???.#..?.#?......?.#?#..##???.#...##.#..#?..?.#...?.?..##..?.??##?..?#??..#..?#.??
  23. #.#.#........?.???..#.###?##.?....?###...#?##?..##..#?.?...#...#??.??.?##...?...????....?.?..#...#...#...#.?.#.....??..???..?#??..?#.#.?.#.?
  24. ?.?...#..?.#.#..?..###?.#?#?.##.??...??#...#?#.???.?#?#.#.#?...#....#.?.##...#?##..#..?#.#...??#.#.?..?#.#?#.....#?.......??#.###...#?#.....
  25. ..#?...#.#?.#.??..?.?..#.#...?#..#.#......?..#??#...?..#.#...#?..#?.#.#.?.###..????#?..?.??.#..?#?..#........#....?###...#?..#.?#.#?.#??....
  26. .##..#?##..#?...#?.#.?.....#..?..?#.??..#..#.?...?.##.?.#..###.#?.?#.....##?.??#..?..#..??##?..#?#...##.#.?.?#.?..#...##..??.???..??..#.#...
  27. ?.#..#.#?....?.?.?.#.?.#.#?#.#......?.#?....#.#.#.?#.##....?....#....#.#?..#.#.?#...?.?..?..###?.?.?.###..#..??#????#.....#...##.?#..#???.#.
  28. ?#..?..?#.#.?.?...??.#.......#?#.?..#..?.#.??.#?.#.#?...##..?..?#??.#???......?.?.....#.?#.#?#??.?.##..??.??.#??##?.#....?#.#.#??.?.?.?.?#.?
  29. ....#.#.??.??.?..###?#.?..##.???.?.#?#....##?...##..#.#?#.##?.#......#.?#.?.#..??#.#..#?#..?.........##.#.??.??#.##.##?.?#??..#.?#.##.?.?.?#
  30. ..??.###....?#?.???..#.....??.??#...##.?..#...##..#.#..?#.....#.???.....#.#??...#......?.?.#.#??##?.#.??#..#...????.#..#.?#..##?..?.?.?..#..
  31. #?.....#.???#..##.#?.?#.?....?#??...?.....##...#.#.#.##?..?..#.#....??.?#?.?#..#?....#.?#???.#?#..?.#.?#.???..?.?..?.#.?#?..###??.?##..#.###
  32. ????#.##....?.#.??.?....#?..?#...#..#???....#.##..???.#..##?.#.....#.??.#.....??..?....#....???##??....#....?#.?#...?..?..??....?..#.##.????
  33. ..?#?#??..##??#.....?.?#...??.?#...?#####?.?#.?#?##.#.?#?#??.??..?.?...#.??..#...#.#..##?.#..##?#.?.#??#?.#?.??#...#??.#.?#..??.###.?.#..?.?
  34. ..?#??.#?.#.?...##.#..#?.??#?..#...?##.#?.#?...##.#..###....?..#.....#?##.??#.##???.?.###...##.???....?.??.?#?.#?.#?.?#.??..###.?.#.?.....##
  35. #..#.....#.#.???.#..??......?.?...?#?.#?.#??.#?#?##..?..??##.#..?..##.#.....##?.??.#..#?.??##?#??.??#??#.#?....?#?....??#..?.??..?#?..##?##.
  36. ..?..#??.?.?..?.??....#..#?.???..???.......#?#.?..?....##...#...#..?..?#...?..??.....#.#??#?.###..#?.#.#?.......??..#..?.??..#...##?..#.?..#
  37. ?.?....??.#.???.##?.#.?.?.??#.?.###.......?..#...??.#...#.#.?#.?..?...???.##..?.?..####?#....?.#..?...###?...??........#???##..##..??#.#.??.
  38. ?#.#?#...?.?....?....?...?.##.....##.##?.....?#####?..#?#.??#??.??#.....?..##..#?.#.#.#?#..#??......#.#?.###.#?#?.?.#.....#...?.#..#?....??.
  39. #?...??...?..?#?#......?.....#.????#?.#?##???.#.?..##.#.##.....?..?.##.##.......?.##?......?#.#?.#.##...?..?#??..#..#..#.#?..?#...??#.?#.?.#
  40. #..?....?#?#......#...#.........??#............#.?..?#.#....#.?#..#.....#??...#.?.?#??..?..??.#.?.#.....#?....?##.#?##..#?#...?#.??.?.??..?.
  41. ..###?...???.?#.##???#?.#?.?.?#.#.#.##.?#.####.#?.???.....##.?...#.##..?....#?.?#.?...#.##.?..#..??#..?#..#?#...?..?..??.....?...?.?...?.#?#
  42. #??#.?##.#.?..##?..#.#??#????.?#.?....?...#....??...##?.#.?#?.?.##.#???.?#.?#?..?#.#.#?###?.....##..?..?.#?..?.?.#.#..?.?..?#.?##..#.#..?.#?
  43. .?.#.....##..#?#.??...?...?....????.#?##?....#.#.#.?.#??...?.?.##.#.##.?...##.#???#.?.?......???.?.?..?..??..#.?##..###?.##.##?##.?.###??..?
  44. ??.#..###..??#.#.#.#.??.....?#??...?...?#.?...?#.#..#?#..?..#?.#.?#..?.#?.#.?#..#?..##.......??.?##?#??#??....#.......#.#...?#.?.?....?#..#.
  45. ?.?#..##?..?....??.#..#....#?....?..?..#.#.#.#?...#....##.??#.##.?.???#.#...?.....?.#...?#..?...??..#.#.?..?........###.#..##.?..#.#..??....
  46. .....?.??#.?..#?#.#?.??........#????.......###.......?#??.##..#?####...?#.?.?.##??#?...?#.#...?...?...##..???.#.#.??????....#..#.?.?.##.?..?
  47. ??.?.#?..#.??.#.#.#.??.#.#??#.#...?...##......?...?...##..?.#?.?#...?..#....##.#?.#..?.....?...#?.?#.?#...?#??#?...??......?#?.??#.#??...?.?
  48. #?.###..#.....#?....#.##...#.##.....#.#.#.#..##.....?..#.....?##...#?.??.......#??##?..###??....?.#?......#.??..#??.#?.#.#.###??.#?..?#?#..#
  49. ?.?....?.#??.#....?#?#?.?#.?.....#??#.??.?#?#.#......?.#?...?#..#.....??#.?....??.##...?..#?.#??.#.?.??....#?.?.#...##.?#...##....#.#??..?#.
  50. ?#?.?....?.##...??...#?##.#.????##.#..?..?..#..##.??#?.?.??#...?.?...#..?..#..??.?.?#.#.#??..?.#......#...#?.?...?#?.......#.???.#?.##..#?#.
  51. ..??.#..??#####.#?.........#.#.?####...?#.?.#??.#??#..?##?#.??#....?.??...?..?..??.#...?..????..#..##?###...#.??.?##..#.#..?.#..##?#.??.?#.?
  52. ?.##.?.#.##?.?...#...#?##.#.?.#..?#.?.??##?#??.?.?.#.???...??#.##..?#.??#.??....?..#?..##?#?##???.#..#??.?#???...#?##..#.#..#......??#..###.
  53. ###...#...??.#.?..#?..?...#.#?.?.?.?#....#.?#.#..####.?..??##?....?#.?.....#...?#??....??....#.????.?...#.??.#..#..??.?..##..#.?..?..##.#?..
  54. #....#.?.##.?.......#...##?..#...#.?##..###?..#...?....?#????###.?.....?##.##?.#?.###?.#???#..#....?...#?.....#...?..#.?.#???#.?#.??.?#.#.??
  55. #...#??......?..#.......??.?..#....#.?#.#?..#.##..??##..#?#.#?...#...?....?.?.?...#??#?#..####...#..?.#?#..#..#.?.####..#?#.##?#.?#?#.....?.
  56. ...#?...#...?#?.##.??..#..#?.?.....#.#?#...#.......#..#....?.??...#???.?...?.#??##.?##?##.#??.#?..##??...#..?.....#?#..##??..###...??.??#?#.
  57. .........?.#.?.#?...?..?.??#?#.?.#??......#..#.#.?#?.#??#...#?#?.#?.#..?#...?...##?#.##..?.##......??.?##.?###?.#?##..#.?#?...#..##....?##?#
  58. #??#.##.##..#..#???.?.?#.#...##?##?#.#??.?.#.#??.#.#.#.....?#???#??#..?.#.?..??..?.?....?#.....#.?#.??.?.????#..?.#.??###.??#?..#?..??##..?#
  59. #.#??..#.?....###.....?#.....##?.#?.?.#.??##...?#?#.?...#..?#.?...?#..?#?#.##.?....##....#..#.##?.??..?.?.?#.?###.?.##?...#...??....#.#..#?.
  60. ?..?..?.?.????#???.??.#.???.??..##..#..??##?.#?..?#??##...?????.#?..#...#..?#...?..?#..#.#....?....#.#..?..?#??#??##....#?..?.???...#.#.#.?#
  61. ..##?#.#....??...........?.##.....?#?..#..?..#?.?.?...#?#.?###...#.#.?#?..?.#.??#?##...?..?........?.#.....##..?#..?..#.??.?...?.?###.#?#...
  62. ..?...#.#?#..#?..#..#..#...#..?.....#.#...#..#?.?.....?..??...#.?.?......?.#?##..?#..#.?..#..?#??...#.#.....?#...?.#...#.#..#.#?.#?.?##?#?##
  63. #?.#...##.?.#.####.??.#?.?#?.#...#.?#.??#??.##.#.#..#...#.?.#.#.#.###....?.??.?......?....#????..#.......#..#.###.#.?....?#...#..?.#...#.#..
  64. #...??...??..?.#?...##.?..?#.??.?.#.#..?..###?.????#....#..?.?#.#.#####?##...#.?...??.??...#.#?#.#?..?#..?#??.##.?.?..#....?.#..##.?..?...#.
  65. ?..#?##???..?.##??.?....##.??..?.#?....?..?..?....??#.#.??.?...?#?....#.?.#?????#.?#..#?..##...?????##.....#.#.####.?#.?...#?..?.??##?..#.??
  66. ?....?.#.#?..?.?...#..#.#?.#..#...?.#.?#.?.#.##??..#..#?#?#.#??..#.??.?...?.?..?##?...?.?..##.?..?.???...?#.##?#..??..#?#...?..?....#..#.##?
  67. #?#.?#......?.#??##...?#.#.##.?...?...?...?#..#?###.##?##..?.#?#.?#..#...#....#?#.#??...?#.#?..#?##?..??..?..#?....?#.#?..#.#.##.?#.?.#..##?
  68. .#.....##.##?.?...??..##...#?.#...#...#.??.?...#..?.?.#.##?.?#.#?..#???#?#?#.##..#.#.?...........#.?#..##...##??##..?.?###??#.#........#.?.#
  69. ?..#...#.##..?#.?.##..?..?.#....??#...#?..#.#.?.??.?..?#.#.#..??##?.##..?##?#..#?..??#.#.?.?#.?....#.##?#..#....?..##.??###?#...?..#.##.?#?#
  70. .??......?..??##?..??...?...?##?.?###?..##?..#?..???#.##.##.?..#..???..???...??#..?##...##.?..?.??#..#####?.#.#..?......##.?.##.#.?#??#..#..
  71. .#?..#.?.#...?.???.?..#...?...?.#....?..#........#.??..?...#.#?..?#....#...#.#...?.?.##???..???..#..??.?..#..#.##?..?#.#..##.??##...?#.....?');
  72. query II
  73. WITH MUTUALLY RECURSIVE
  74. lines(line TEXT, r INT) AS (
  75. SELECT regexp_split_to_array(input, '\n')[i], i
  76. FROM input, generate_series(1, array_length(regexp_split_to_array(input, '\n'), 1)) i
  77. ),
  78. symbols(symb TEXT, r INT, c INT) as (
  79. SELECT substring(line, j, 1), r, j
  80. FROM lines, generate_series(1, length(line)) j
  81. ),
  82. row_gaps(r INT) AS (
  83. SELECT r
  84. FROM symbols
  85. GROUP BY r
  86. HAVING COUNT(*) FILTER (WHERE symb = '#') = 0
  87. ),
  88. col_gaps(c INT) AS (
  89. SELECT c
  90. FROM symbols
  91. GROUP BY c
  92. HAVING COUNT(*) FILTER (WHERE symb = '#') = 0
  93. ),
  94. -- Part1: Expand space and restrict to galaxies
  95. galaxies(r INT, c INT) AS (
  96. SELECT
  97. r + (SELECT COUNT(*) FROM row_gaps WHERE row_gaps.r < symbols.r),
  98. c + (SELECT COUNT(*) FROM col_gaps WHERE col_gaps.c < symbols.c)
  99. FROM symbols
  100. WHERE symb = '#'
  101. ),
  102. -- Sum of L1 distance between distinct galaxies
  103. part1(part1 BIGINT) AS (
  104. SELECT SUM(ABS(g1.r - g2.r) + ABS(g1.c - g2.c))
  105. FROM galaxies g1, galaxies g2
  106. WHERE g1.r < g2.r
  107. OR (g1.r = g2.r AND g1.c < g2.c)
  108. ),
  109. -- Part2: Expand space MORE and restrict to galaxies
  110. galaxies2(r INT, c INT) AS (
  111. SELECT
  112. r + 999999 * (SELECT COUNT(*) FROM row_gaps WHERE row_gaps.r < symbols.r),
  113. c + 999999 * (SELECT COUNT(*) FROM col_gaps WHERE col_gaps.c < symbols.c)
  114. FROM symbols
  115. WHERE symb = '#'
  116. ),
  117. -- Sum of L1 distance between distinct galaxies
  118. part2(part2 BIGINT) AS (
  119. SELECT SUM(ABS(g1.r - g2.r) + ABS(g1.c - g2.c))
  120. FROM galaxies2 g1, galaxies2 g2
  121. WHERE g1.r < g2.r
  122. OR (g1.r = g2.r AND g1.c < g2.c)
  123. )
  124. SELECT * FROM part1, part2;
  125. ----
  126. 129655908 129655908
  127. query T multiline
  128. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  129. WITH MUTUALLY RECURSIVE
  130. lines(line TEXT, r INT) AS (
  131. SELECT regexp_split_to_array(input, '\n')[i], i
  132. FROM input, generate_series(1, array_length(regexp_split_to_array(input, '\n'), 1)) i
  133. ),
  134. symbols(symb TEXT, r INT, c INT) as (
  135. SELECT substring(line, j, 1), r, j
  136. FROM lines, generate_series(1, length(line)) j
  137. ),
  138. row_gaps(r INT) AS (
  139. SELECT r
  140. FROM symbols
  141. GROUP BY r
  142. HAVING COUNT(*) FILTER (WHERE symb = '#') = 0
  143. ),
  144. col_gaps(c INT) AS (
  145. SELECT c
  146. FROM symbols
  147. GROUP BY c
  148. HAVING COUNT(*) FILTER (WHERE symb = '#') = 0
  149. ),
  150. -- Part1: Expand space and restrict to galaxies
  151. galaxies(r INT, c INT) AS (
  152. SELECT
  153. r + (SELECT COUNT(*) FROM row_gaps WHERE row_gaps.r < symbols.r),
  154. c + (SELECT COUNT(*) FROM col_gaps WHERE col_gaps.c < symbols.c)
  155. FROM symbols
  156. WHERE symb = '#'
  157. ),
  158. -- Sum of L1 distance between distinct galaxies
  159. part1(part1 BIGINT) AS (
  160. SELECT SUM(ABS(g1.r - g2.r) + ABS(g1.c - g2.c))
  161. FROM galaxies g1, galaxies g2
  162. WHERE g1.r < g2.r
  163. OR (g1.r = g2.r AND g1.c < g2.c)
  164. ),
  165. -- Part2: Expand space MORE and restrict to galaxies
  166. galaxies2(r INT, c INT) AS (
  167. SELECT
  168. r + 999999 * (SELECT COUNT(*) FROM row_gaps WHERE row_gaps.r < symbols.r),
  169. c + 999999 * (SELECT COUNT(*) FROM col_gaps WHERE col_gaps.c < symbols.c)
  170. FROM symbols
  171. WHERE symb = '#'
  172. ),
  173. -- Sum of L1 distance between distinct galaxies
  174. part2(part2 BIGINT) AS (
  175. SELECT SUM(ABS(g1.r - g2.r) + ABS(g1.c - g2.c))
  176. FROM galaxies2 g1, galaxies2 g2
  177. WHERE g1.r < g2.r
  178. OR (g1.r = g2.r AND g1.c < g2.c)
  179. )
  180. SELECT * FROM part1, part2;
  181. ----
  182. Explained Query:
  183. With
  184. cte l0 =
  185. Project (#0, #2, #3) // { arity: 3 }
  186. Map (substr(#1{line}, #2{j}, 1)) // { arity: 4 }
  187. FlatMap generate_series(1, char_length(#1{line}), 1) // { arity: 3 }
  188. Project (#1, #2) // { arity: 2 }
  189. Map (array_index(regexp_split_to_array["\n", case_insensitive=false](#0{input}), integer_to_bigint(#1{i}))) // { arity: 3 }
  190. FlatMap generate_series(1, (regexp_split_to_array["\n", case_insensitive=false](#0{input}) array_length 1), 1) // { arity: 2 }
  191. ReadStorage materialize.public.input // { arity: 1 }
  192. cte l1 =
  193. Project (#0, #1) // { arity: 2 }
  194. Filter (#2{symb} = "#") // { arity: 3 }
  195. Get l0 // { arity: 3 }
  196. cte l2 =
  197. Distinct project=[#0, #1] // { arity: 2 }
  198. Get l1 // { arity: 2 }
  199. cte l3 =
  200. Distinct project=[#0] // { arity: 1 }
  201. Project (#0) // { arity: 1 }
  202. Get l2 // { arity: 2 }
  203. cte l4 =
  204. Reduce group_by=[#0] aggregates=[count(*)] // { arity: 2 }
  205. Project (#0) // { arity: 1 }
  206. Filter (#1{r} < #0{r}) // { arity: 2 }
  207. CrossJoin type=differential // { arity: 2 }
  208. implementation
  209. %1[×]ef » %0:l3[×]ef
  210. ArrangeBy keys=[[]] // { arity: 1 }
  211. Get l3 // { arity: 1 }
  212. ArrangeBy keys=[[]] // { arity: 1 }
  213. Project (#0) // { arity: 1 }
  214. Filter (#1{count} = 0) // { arity: 2 }
  215. Reduce group_by=[#0] aggregates=[count((null OR ((#1{symb}) IS NOT NULL AND (#1{symb} = "#"))))] // { arity: 2 }
  216. Project (#0, #2) // { arity: 2 }
  217. Get l0 // { arity: 3 }
  218. cte l5 =
  219. Union // { arity: 2 }
  220. Get l4 // { arity: 2 }
  221. Map (0) // { arity: 2 }
  222. Union // { arity: 1 }
  223. Negate // { arity: 1 }
  224. Project (#0) // { arity: 1 }
  225. Get l4 // { arity: 2 }
  226. Get l3 // { arity: 1 }
  227. cte l6 =
  228. Distinct project=[#0] // { arity: 1 }
  229. Project (#1) // { arity: 1 }
  230. Get l2 // { arity: 2 }
  231. cte l7 =
  232. Reduce group_by=[#0] aggregates=[count(*)] // { arity: 2 }
  233. Project (#0) // { arity: 1 }
  234. Filter (#1{c} < #0{c}) // { arity: 2 }
  235. CrossJoin type=differential // { arity: 2 }
  236. implementation
  237. %1[×]ef » %0:l6[×]ef
  238. ArrangeBy keys=[[]] // { arity: 1 }
  239. Get l6 // { arity: 1 }
  240. ArrangeBy keys=[[]] // { arity: 1 }
  241. Project (#0) // { arity: 1 }
  242. Filter (#1{count} = 0) // { arity: 2 }
  243. Reduce group_by=[#0] aggregates=[count((null OR ((#1{symb}) IS NOT NULL AND (#1{symb} = "#"))))] // { arity: 2 }
  244. Project (#1, #2) // { arity: 2 }
  245. Get l0 // { arity: 3 }
  246. cte l8 =
  247. Union // { arity: 2 }
  248. Get l7 // { arity: 2 }
  249. Map (0) // { arity: 2 }
  250. Union // { arity: 1 }
  251. Negate // { arity: 1 }
  252. Project (#0) // { arity: 1 }
  253. Get l7 // { arity: 2 }
  254. Get l6 // { arity: 1 }
  255. cte l9 =
  256. Project (#0, #1, #3{count}, #5{count}) // { arity: 4 }
  257. Join on=(#0 = #2 AND #1 = #4) type=delta // { arity: 6 }
  258. implementation
  259. %0:l1 » %1[#0]UK » %2[#0]UK
  260. %1 » %0:l1[#0]Kef » %2[#0]UK
  261. %2 » %0:l1[#1]Kef » %1[#0]UK
  262. ArrangeBy keys=[[#0], [#1]] // { arity: 2 }
  263. Get l1 // { arity: 2 }
  264. ArrangeBy keys=[[#0]] // { arity: 2 }
  265. Union // { arity: 2 }
  266. Get l5 // { arity: 2 }
  267. Map (null) // { arity: 2 }
  268. Union // { arity: 1 }
  269. Negate // { arity: 1 }
  270. Project (#0) // { arity: 1 }
  271. Get l5 // { arity: 2 }
  272. Get l3 // { arity: 1 }
  273. ArrangeBy keys=[[#0]] // { arity: 2 }
  274. Union // { arity: 2 }
  275. Get l8 // { arity: 2 }
  276. Map (null) // { arity: 2 }
  277. Union // { arity: 1 }
  278. Negate // { arity: 1 }
  279. Project (#0) // { arity: 1 }
  280. Get l8 // { arity: 2 }
  281. Get l6 // { arity: 1 }
  282. cte l10 =
  283. ArrangeBy keys=[[]] // { arity: 2 }
  284. Project (#4, #5) // { arity: 2 }
  285. Map (bigint_to_integer((integer_to_bigint(#0{r}) + #2{count})), bigint_to_integer((integer_to_bigint(#1{c}) + #3{count}))) // { arity: 6 }
  286. Get l9 // { arity: 4 }
  287. cte l11 =
  288. Reduce aggregates=[sum((abs((#0{r} - #2{r})) + abs((#1{c} - #3{c}))))] // { arity: 1 }
  289. Filter ((#0{r} < #2{r}) OR ((#0{r} = #2{r}) AND (#1{c} < #3{c}))) // { arity: 4 }
  290. CrossJoin type=differential // { arity: 4 }
  291. implementation
  292. %0:l10[×] » %1:l10[×]
  293. Get l10 // { arity: 2 }
  294. Get l10 // { arity: 2 }
  295. cte l12 =
  296. ArrangeBy keys=[[]] // { arity: 2 }
  297. Project (#4, #5) // { arity: 2 }
  298. Map (bigint_to_integer((integer_to_bigint(#0{r}) + (999999 * #2{count}))), bigint_to_integer((integer_to_bigint(#1{c}) + (999999 * #3{count})))) // { arity: 6 }
  299. Get l9 // { arity: 4 }
  300. cte l13 =
  301. Reduce aggregates=[sum((abs((#0{r} - #2{r})) + abs((#1{c} - #3{c}))))] // { arity: 1 }
  302. Filter ((#0{r} < #2{r}) OR ((#0{r} = #2{r}) AND (#1{c} < #3{c}))) // { arity: 4 }
  303. CrossJoin type=differential // { arity: 4 }
  304. implementation
  305. %0:l12[×] » %1:l12[×]
  306. Get l12 // { arity: 2 }
  307. Get l12 // { arity: 2 }
  308. Return // { arity: 2 }
  309. CrossJoin type=differential // { arity: 2 }
  310. implementation
  311. %0[×]U » %1[×]U
  312. ArrangeBy keys=[[]] // { arity: 1 }
  313. Union // { arity: 1 }
  314. Get l11 // { arity: 1 }
  315. Map (null) // { arity: 1 }
  316. Union // { arity: 0 }
  317. Negate // { arity: 0 }
  318. Project () // { arity: 0 }
  319. Get l11 // { arity: 1 }
  320. Constant // { arity: 0 }
  321. - ()
  322. ArrangeBy keys=[[]] // { arity: 1 }
  323. Union // { arity: 1 }
  324. Get l13 // { arity: 1 }
  325. Map (null) // { arity: 1 }
  326. Union // { arity: 0 }
  327. Negate // { arity: 0 }
  328. Project () // { arity: 0 }
  329. Get l13 // { arity: 1 }
  330. Constant // { arity: 0 }
  331. - ()
  332. Source materialize.public.input
  333. Target cluster: quickstart
  334. EOF