aoc_1219.slt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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_1219.md
  10. mode cockroach
  11. statement ok
  12. CREATE TABLE input (input TEXT);
  13. statement ok
  14. INSERT INTO input VALUES (
  15. 'in{x<1164:zoz,s>1473:A,a<8576:ask,A}
  16. ask{m<2275:rsx,zoz}
  17. rsx{a>8922:A,s>4213:A,R}
  18. zoz{m>5813:A,s>4522:A,x<245:R,krw}
  19. krw{a>3747:dqu,a>299:R,a<927:A,A}
  20. ton{a<8226:ktx,m>1965:ktx,s>3591:uhu,dqu}
  21. dqu{m<6866:uhu,s>4649:A,R}
  22. uhu{a<6293:A,lel}
  23. lel{a<6145:ktx,A}
  24. ktx{s>8889:R,a>3215:R,R}
  25. <EMPTY_LINE>
  26. {x=61,m=818,a=525,s=29}
  27. {x=225,m=7722,a=964,s=466}
  28. {x=528,m=3628,a=914,s=8823}
  29. {x=13,m=675,a=5933,s=9}
  30. {x=9693,m=8583,a=125,s=787}');
  31. statement ok
  32. UPDATE input SET input = replace(input, '<EMPTY_LINE>', '');
  33. query II
  34. WITH MUTUALLY RECURSIVE
  35. blocks(block1 TEXT, block2 TEXT) AS (
  36. SELECT
  37. trim(regexp_split_to_array(input, '\n\n')[1]) block1,
  38. trim(regexp_split_to_array(input, '\n\n')[2]) block2
  39. FROM input
  40. ),
  41. states(state TEXT, trans TEXT) AS (
  42. SELECT
  43. regexp_split_to_array(line, '\{')[1] state,
  44. trim('}' FROM regexp_split_to_array(line, '\{')[2]) trans
  45. FROM (SELECT regexp_split_to_table(block1, '\n') line FROM blocks)
  46. ),
  47. steps(state TEXT, priority INT, rule TEXT) AS (
  48. SELECT
  49. state,
  50. priority,
  51. regexp_split_to_array(trans, ',')[priority]
  52. FROM states, generate_series(1, array_length(regexp_split_to_array(trans, ','), 1)) priority
  53. ),
  54. starts(x INT, m INT, a INT, s INT) AS (
  55. SELECT
  56. substring(regexp_split_to_array(trimmed, ',')[1], 3)::INT,
  57. substring(regexp_split_to_array(trimmed, ',')[2], 3)::INT,
  58. substring(regexp_split_to_array(trimmed, ',')[3], 3)::INT,
  59. substring(regexp_split_to_array(trimmed, ',')[4], 3)::INT
  60. FROM (SELECT trim('\{' FROM trim('\}' FROM regexp_split_to_table(block2, '\n'))) trimmed FROM blocks)
  61. ),
  62. --
  63. rules(state TEXT, priority INT, field TEXT, cmp TEXT, val INT, next TEXT) AS (
  64. SELECT
  65. state,
  66. priority,
  67. CASE WHEN substring(rule, 2, 1) = '<' OR substring(rule, 2, 1) = '>'
  68. THEN substring(rule, 1, 1)
  69. ELSE 'x'
  70. END,
  71. CASE WHEN substring(rule, 2, 1) = '<' OR substring(rule, 2, 1) = '>'
  72. THEN substring(rule, 2, 1)
  73. ELSE '>'
  74. END,
  75. CASE WHEN substring(rule, 2, 1) = '<' OR substring(rule, 2, 1) = '>'
  76. THEN regexp_split_to_array(substring(rule, 3), ':')[1]::INT
  77. ELSE '0'
  78. END,
  79. CASE WHEN substring(rule, 2, 1) = '<' OR substring(rule, 2, 1) = '>'
  80. THEN regexp_split_to_array(substring(rule, 3), ':')[2]
  81. ELSE rule
  82. END
  83. FROM steps
  84. ),
  85. -- PART 1: iterate folks forward from `in`
  86. movement(state TEXT, x INT, m INT, a INT, s INT) AS (
  87. SELECT 'in' state, * FROM starts
  88. UNION ALL
  89. SELECT next, x, m, a, s
  90. FROM (
  91. SELECT DISTINCT ON (state, x, m, a, s) state, x, m, a, s, priority, next
  92. FROM (
  93. SELECT movement.*, rules.next, rules.priority
  94. FROM movement, rules
  95. WHERE movement.state = rules.state
  96. AND CASE WHEN rules.cmp = '<'
  97. THEN CASE WHEN rules.field = 'x' THEN x < val
  98. WHEN rules.field = 'm' THEN m < val
  99. WHEN rules.field = 'a' THEN a < val
  100. WHEN rules.field = 's' THEN s < val
  101. ELSE false
  102. END
  103. WHEN rules.cmp = '>'
  104. THEN CASE WHEN rules.field = 'x' THEN x > val
  105. WHEN rules.field = 'm' THEN m > val
  106. WHEN rules.field = 'a' THEN a > val
  107. WHEN rules.field = 's' THEN s > val
  108. ELSE false
  109. END
  110. ELSE false
  111. END
  112. )
  113. ORDER BY state, x, m, a, s, priority
  114. )
  115. ),
  116. part1(part1 BIGINT) AS (
  117. SELECT SUM(x + m + a + s)
  118. FROM movement
  119. WHERE state = 'A'
  120. ),
  121. -- PART 2: just find all the bounding regions and label them 'A' or 'R'.
  122. region(state TEXT, priority INT, xl INT, xu INT, ml INT, mu INT, al INT, au INT, sl INT, su INT) AS (
  123. SELECT 'in', 1, 1, 4000, 1, 4000, 1, 4000, 1, 4000
  124. -- Could satisfy the rule, and transition to the next state ..
  125. UNION ALL
  126. SELECT
  127. next,
  128. 1,
  129. CASE WHEN rules.field = 'x' AND rules.cmp = '>' THEN GREATEST(val+1, xl) ELSE xl END,
  130. CASE WHEN rules.field = 'x' AND rules.cmp = '<' THEN LEAST(val-1, xu) ELSE xu END,
  131. CASE WHEN rules.field = 'm' AND rules.cmp = '>' THEN GREATEST(val+1, ml) ELSE ml END,
  132. CASE WHEN rules.field = 'm' AND rules.cmp = '<' THEN LEAST(val-1, mu) ELSE mu END,
  133. CASE WHEN rules.field = 'a' AND rules.cmp = '>' THEN GREATEST(val+1, al) ELSE al END,
  134. CASE WHEN rules.field = 'a' AND rules.cmp = '<' THEN LEAST(val-1, au) ELSE au END,
  135. CASE WHEN rules.field = 's' AND rules.cmp = '>' THEN GREATEST(val+1, sl) ELSE sl END,
  136. CASE WHEN rules.field = 's' AND rules.cmp = '<' THEN LEAST(val-1, su) ELSE su END
  137. FROM region, rules
  138. WHERE region.state = rules.state
  139. AND region.priority = rules.priority
  140. -- .. or could fail the rule, and advance to the next priority.
  141. UNION ALL
  142. SELECT
  143. region.state,
  144. region.priority + 1,
  145. CASE WHEN rules.field = 'x' AND rules.cmp = '<' THEN GREATEST(val, xl) ELSE xl END,
  146. CASE WHEN rules.field = 'x' AND rules.cmp = '>' THEN LEAST(val, xu) ELSE xu END,
  147. CASE WHEN rules.field = 'm' AND rules.cmp = '<' THEN GREATEST(val, ml) ELSE ml END,
  148. CASE WHEN rules.field = 'm' AND rules.cmp = '>' THEN LEAST(val, mu) ELSE mu END,
  149. CASE WHEN rules.field = 'a' AND rules.cmp = '<' THEN GREATEST(val, al) ELSE al END,
  150. CASE WHEN rules.field = 'a' AND rules.cmp = '>' THEN LEAST(val, au) ELSE au END,
  151. CASE WHEN rules.field = 's' AND rules.cmp = '<' THEN GREATEST(val, sl) ELSE sl END,
  152. CASE WHEN rules.field = 's' AND rules.cmp = '>' THEN LEAST(val, su) ELSE su END
  153. FROM region, rules
  154. WHERE region.state = rules.state
  155. AND region.priority = rules.priority
  156. ),
  157. part2(part2 NUMERIC) AS (
  158. SELECT SUM((1 + xu - xl)::BIGINT * (1 + mu - ml)::BIGINT * (1 + au - al)::BIGINT * (1 + su - sl)::BIGINT)
  159. FROM region
  160. WHERE state = 'A'
  161. ),
  162. potato(x INT) AS (SELECT 1)
  163. SELECT * FROM part1, part2;
  164. ----
  165. 42458 -257636238955235
  166. query T multiline
  167. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR
  168. WITH MUTUALLY RECURSIVE
  169. blocks(block1 TEXT, block2 TEXT) AS (
  170. SELECT
  171. regexp_split_to_array(input, '\n\n')[1] block1,
  172. regexp_split_to_array(input, '\n\n')[2] block2
  173. FROM input
  174. ),
  175. states(state TEXT, trans TEXT) AS (
  176. SELECT
  177. regexp_split_to_array(line, '\{')[1] state,
  178. trim('}' FROM regexp_split_to_array(line, '\{')[2]) trans
  179. FROM (SELECT regexp_split_to_table(block1, '\n') line FROM blocks)
  180. ),
  181. steps(state TEXT, priority INT, rule TEXT) AS (
  182. SELECT
  183. state,
  184. priority,
  185. regexp_split_to_array(trans, ',')[priority]
  186. FROM states, generate_series(1, array_length(regexp_split_to_array(trans, ','), 1)) priority
  187. ),
  188. starts(x INT, m INT, a INT, s INT) AS (
  189. SELECT
  190. substring(regexp_split_to_array(trimmed, ',')[1], 3)::INT,
  191. substring(regexp_split_to_array(trimmed, ',')[2], 3)::INT,
  192. substring(regexp_split_to_array(trimmed, ',')[3], 3)::INT,
  193. substring(regexp_split_to_array(trimmed, ',')[4], 3)::INT
  194. FROM (SELECT trim('\{' FROM trim('\}' FROM regexp_split_to_table(block2, '\n'))) trimmed FROM blocks)
  195. ),
  196. --
  197. rules(state TEXT, priority INT, field TEXT, cmp TEXT, val INT, next TEXT) AS (
  198. SELECT
  199. state,
  200. priority,
  201. CASE WHEN substring(rule, 2, 1) = '<' OR substring(rule, 2, 1) = '>'
  202. THEN substring(rule, 1, 1)
  203. ELSE 'x'
  204. END,
  205. CASE WHEN substring(rule, 2, 1) = '<' OR substring(rule, 2, 1) = '>'
  206. THEN substring(rule, 2, 1)
  207. ELSE '>'
  208. END,
  209. CASE WHEN substring(rule, 2, 1) = '<' OR substring(rule, 2, 1) = '>'
  210. THEN regexp_split_to_array(substring(rule, 3), ':')[1]::INT
  211. ELSE '0'
  212. END,
  213. CASE WHEN substring(rule, 2, 1) = '<' OR substring(rule, 2, 1) = '>'
  214. THEN regexp_split_to_array(substring(rule, 3), ':')[2]
  215. ELSE rule
  216. END
  217. FROM steps
  218. ),
  219. -- PART 1: iterate folks forward from `in`
  220. movement(state TEXT, x INT, m INT, a INT, s INT) AS (
  221. SELECT 'in' state, * FROM starts
  222. UNION ALL
  223. SELECT next, x, m, a, s
  224. FROM (
  225. SELECT DISTINCT ON (state, x, m, a, s) state, x, m, a, s, priority, next
  226. FROM (
  227. SELECT movement.*, rules.next, rules.priority
  228. FROM movement, rules
  229. WHERE movement.state = rules.state
  230. AND CASE WHEN rules.cmp = '<'
  231. THEN CASE WHEN rules.field = 'x' THEN x < val
  232. WHEN rules.field = 'm' THEN m < val
  233. WHEN rules.field = 'a' THEN a < val
  234. WHEN rules.field = 's' THEN s < val
  235. ELSE false
  236. END
  237. WHEN rules.cmp = '>'
  238. THEN CASE WHEN rules.field = 'x' THEN x > val
  239. WHEN rules.field = 'm' THEN m > val
  240. WHEN rules.field = 'a' THEN a > val
  241. WHEN rules.field = 's' THEN s > val
  242. ELSE false
  243. END
  244. ELSE false
  245. END
  246. )
  247. ORDER BY state, x, m, a, s, priority
  248. )
  249. ),
  250. part1(part1 BIGINT) AS (
  251. SELECT SUM(x + m + a + s)
  252. FROM movement
  253. WHERE state = 'A'
  254. ),
  255. -- PART 2: just find all the bounding regions and label them 'A' or 'R'.
  256. region(state TEXT, priority INT, xl INT, xu INT, ml INT, mu INT, al INT, au INT, sl INT, su INT) AS (
  257. SELECT 'in', 1, 1, 4000, 1, 4000, 1, 4000, 1, 4000
  258. -- Could satisfy the rule, and transition to the next state ..
  259. UNION ALL
  260. SELECT
  261. next,
  262. 1,
  263. CASE WHEN rules.field = 'x' AND rules.cmp = '>' THEN GREATEST(val+1, xl) ELSE xl END,
  264. CASE WHEN rules.field = 'x' AND rules.cmp = '<' THEN LEAST(val-1, xu) ELSE xu END,
  265. CASE WHEN rules.field = 'm' AND rules.cmp = '>' THEN GREATEST(val+1, ml) ELSE ml END,
  266. CASE WHEN rules.field = 'm' AND rules.cmp = '<' THEN LEAST(val-1, mu) ELSE mu END,
  267. CASE WHEN rules.field = 'a' AND rules.cmp = '>' THEN GREATEST(val+1, al) ELSE al END,
  268. CASE WHEN rules.field = 'a' AND rules.cmp = '<' THEN LEAST(val-1, au) ELSE au END,
  269. CASE WHEN rules.field = 's' AND rules.cmp = '>' THEN GREATEST(val+1, sl) ELSE sl END,
  270. CASE WHEN rules.field = 's' AND rules.cmp = '<' THEN LEAST(val-1, su) ELSE su END
  271. FROM region, rules
  272. WHERE region.state = rules.state
  273. AND region.priority = rules.priority
  274. -- .. or could fail the rule, and advance to the next priority.
  275. UNION ALL
  276. SELECT
  277. region.state,
  278. region.priority + 1,
  279. CASE WHEN rules.field = 'x' AND rules.cmp = '<' THEN GREATEST(val, xl) ELSE xl END,
  280. CASE WHEN rules.field = 'x' AND rules.cmp = '>' THEN LEAST(val, xu) ELSE xu END,
  281. CASE WHEN rules.field = 'm' AND rules.cmp = '<' THEN GREATEST(val, ml) ELSE ml END,
  282. CASE WHEN rules.field = 'm' AND rules.cmp = '>' THEN LEAST(val, mu) ELSE mu END,
  283. CASE WHEN rules.field = 'a' AND rules.cmp = '<' THEN GREATEST(val, al) ELSE al END,
  284. CASE WHEN rules.field = 'a' AND rules.cmp = '>' THEN LEAST(val, au) ELSE au END,
  285. CASE WHEN rules.field = 's' AND rules.cmp = '<' THEN GREATEST(val, sl) ELSE sl END,
  286. CASE WHEN rules.field = 's' AND rules.cmp = '>' THEN LEAST(val, su) ELSE su END
  287. FROM region, rules
  288. WHERE region.state = rules.state
  289. AND region.priority = rules.priority
  290. ),
  291. part2(part2 NUMERIC) AS (
  292. SELECT SUM((1 + xu - xl)::BIGINT * (1 + mu - ml)::BIGINT * (1 + au - al)::BIGINT * (1 + su - sl)::BIGINT)
  293. FROM region
  294. WHERE state = 'A'
  295. ),
  296. potato(x INT) AS (SELECT 1)
  297. SELECT * FROM part1, part2;
  298. ----
  299. Explained Query:
  300. With
  301. cte l0 =
  302. Project (#0, #2, #6..=#9) // { arity: 6 }
  303. Map (array_index(regexp_split_to_array[",", case_insensitive=false](#1{trans}), integer_to_bigint(#2{priority})), substr(#3{rule}, 2, 1), ((#4 = "<") OR (#4 = ">")), case when #5 then substr(#3, 1, 1) else "x" end, case when #5 then substr(#3, 2, 1) else ">" end, case when #5 then text_to_integer(array_index(regexp_split_to_array[":", case_insensitive=false](substr(#3, 3)), 1)) else 0 end, case when #5 then array_index(regexp_split_to_array[":", case_insensitive=false](substr(#3, 3)), 2) else #3 end) // { arity: 10 }
  304. FlatMap generate_series(1, (regexp_split_to_array[",", case_insensitive=false](#1{trans}) array_length 1), 1) // { arity: 3 }
  305. Project (#3, #4) // { arity: 2 }
  306. Filter (#3) IS NOT NULL // { arity: 5 }
  307. Map (regexp_split_to_array["\{", case_insensitive=false](#1{line}), array_index(#2, 1), btrim(array_index(#2, 2), "}")) // { arity: 5 }
  308. FlatMap unnest_array(regexp_split_to_array["\n", case_insensitive=false](#0{block1})) // { arity: 2 }
  309. Project (#1) // { arity: 1 }
  310. Map (array_index(regexp_split_to_array["\n\n", case_insensitive=false](#0{input}), 1)) // { arity: 2 }
  311. ReadStorage materialize.public.input // { arity: 1 }
  312. Return // { arity: 2 }
  313. With Mutually Recursive
  314. cte l1 =
  315. Union // { arity: 5 }
  316. Project (#7, #3..=#6) // { arity: 5 }
  317. Map (regexp_split_to_array[",", case_insensitive=false](btrim(btrim(#1{unnest}, "\}"), "\{")), text_to_integer(substr(array_index(#2, 1), 3)), text_to_integer(substr(array_index(#2, 2), 3)), text_to_integer(substr(array_index(#2, 3), 3)), text_to_integer(substr(array_index(#2, 4), 3)), "in") // { arity: 8 }
  318. FlatMap unnest_array(regexp_split_to_array["\n", case_insensitive=false](#0{block2})) // { arity: 2 }
  319. Project (#1) // { arity: 1 }
  320. Map (array_index(regexp_split_to_array["\n\n", case_insensitive=false](#0{input}), 2)) // { arity: 2 }
  321. ReadStorage materialize.public.input // { arity: 1 }
  322. Project (#6, #1..=#4) // { arity: 5 }
  323. TopK group_by=[#0, #1, #2, #3, #4] order_by=[#5 asc nulls_last] limit=1 // { arity: 7 }
  324. Project (#0..=#4, #6, #10) // { arity: 7 }
  325. Filter case when (#8{cmp} = "<") then case when (#7{field} = "x") then (#1{x} < #9{val}) else case when (#7{field} = "m") then (#2{m} < #9{val}) else case when (#7{field} = "a") then (#3{a} < #9{val}) else case when (#7{field} = "s") then (#4{s} < #9{val}) else false end end end end else case when (#8{cmp} = ">") then case when (#7{field} = "x") then (#1{x} > #9{val}) else case when (#7{field} = "m") then (#2{m} > #9{val}) else case when (#7{field} = "a") then (#3{a} > #9{val}) else case when (#7{field} = "s") then (#4{s} > #9{val}) else false end end end end else false end end // { arity: 11 }
  326. Join on=(#0{state} = #5{state}) type=differential // { arity: 11 }
  327. implementation
  328. %0:l1[#0{state}]K » %1:l0[#0{state}]K
  329. ArrangeBy keys=[[#0{state}]] // { arity: 5 }
  330. Filter (#0{state}) IS NOT NULL // { arity: 5 }
  331. Get l1 // { arity: 5 }
  332. ArrangeBy keys=[[#0{state}]] // { arity: 6 }
  333. Get l0 // { arity: 6 }
  334. cte l2 =
  335. Reduce aggregates=[sum((((#0{x} + #1{m}) + #2{a}) + #3{s}))] // { arity: 1 }
  336. Project (#1..=#4) // { arity: 4 }
  337. Filter (#0{state} = "A") // { arity: 5 }
  338. Get l1 // { arity: 5 }
  339. cte l3 =
  340. Project (#0..=#9, #12..=#15) // { arity: 14 }
  341. Join on=(#0{state} = #10{state} AND #1{priority} = #11{priority}) type=differential // { arity: 16 }
  342. implementation
  343. %0:l4[#0{state}, #1{priority}]KK » %1:l0[#0{state}, #1{priority}]KK
  344. ArrangeBy keys=[[#0{state}, #1{priority}]] // { arity: 10 }
  345. Filter (#0{state}) IS NOT NULL // { arity: 10 }
  346. Get l4 // { arity: 10 }
  347. ArrangeBy keys=[[#0{state}, #1{priority}]] // { arity: 6 }
  348. Get l0 // { arity: 6 }
  349. cte l4 =
  350. Union // { arity: 10 }
  351. Project (#13, #28, #16, #18, #20, #21, #23, #24, #26, #27) // { arity: 10 }
  352. Map ((#10{field} = "x"), (#11{cmp} = ">"), case when (#14 AND #15) then greatest((#12{val} + 1), #2{xl}) else #2{xl} end, (#11{cmp} = "<"), case when (#14 AND #17) then least((#12{val} - 1), #3{xu}) else #3{xu} end, (#10{field} = "m"), case when (#15 AND #19) then greatest((#12{val} + 1), #4{ml}) else #4{ml} end, case when (#17 AND #19) then least((#12{val} - 1), #5{mu}) else #5{mu} end, (#10{field} = "a"), case when (#15 AND #22) then greatest((#12{val} + 1), #6{al}) else #6{al} end, case when (#17 AND #22) then least((#12{val} - 1), #7{au}) else #7{au} end, (#10{field} = "s"), case when (#15 AND #25) then greatest((#12{val} + 1), #8{sl}) else #8{sl} end, case when (#17 AND #25) then least((#12{val} - 1), #9{su}) else #9{su} end, 1) // { arity: 29 }
  353. Get l3 // { arity: 14 }
  354. Project (#0, #14, #17, #19, #21, #22, #24, #25, #27, #28) // { arity: 10 }
  355. Map ((#1{priority} + 1), (#10{field} = "x"), (#11{cmp} = "<"), case when (#15 AND #16) then greatest(#12{val}, #2{xl}) else #2{xl} end, (#11{cmp} = ">"), case when (#15 AND #18) then least(#12{val}, #3{xu}) else #3{xu} end, (#10{field} = "m"), case when (#16 AND #20) then greatest(#12{val}, #4{ml}) else #4{ml} end, case when (#18 AND #20) then least(#12{val}, #5{mu}) else #5{mu} end, (#10{field} = "a"), case when (#16 AND #23) then greatest(#12{val}, #6{al}) else #6{al} end, case when (#18 AND #23) then least(#12{val}, #7{au}) else #7{au} end, (#10{field} = "s"), case when (#16 AND #26) then greatest(#12{val}, #8{sl}) else #8{sl} end, case when (#18 AND #26) then least(#12{val}, #9{su}) else #9{su} end) // { arity: 29 }
  356. Get l3 // { arity: 14 }
  357. Constant // { arity: 10 }
  358. - ("in", 1, 1, 4000, 1, 4000, 1, 4000, 1, 4000)
  359. Return // { arity: 2 }
  360. With
  361. cte l5 =
  362. Reduce aggregates=[sum((((integer_to_bigint(((1 + #1{xu}) - #0{xl})) * integer_to_bigint(((1 + #3{mu}) - #2{ml}))) * integer_to_bigint(((1 + #5{au}) - #4{al}))) * integer_to_bigint(((1 + #7{su}) - #6{sl}))))] // { arity: 1 }
  363. Project (#2..=#9) // { arity: 8 }
  364. Filter (#0{state} = "A") // { arity: 10 }
  365. Get l4 // { arity: 10 }
  366. Return // { arity: 2 }
  367. CrossJoin type=differential // { arity: 2 }
  368. implementation
  369. %0[×]U » %1[×]U
  370. ArrangeBy keys=[[]] // { arity: 1 }
  371. Union // { arity: 1 }
  372. Get l2 // { arity: 1 }
  373. Map (null) // { arity: 1 }
  374. Union // { arity: 0 }
  375. Negate // { arity: 0 }
  376. Project () // { arity: 0 }
  377. Get l2 // { arity: 1 }
  378. Constant // { arity: 0 }
  379. - ()
  380. ArrangeBy keys=[[]] // { arity: 1 }
  381. Union // { arity: 1 }
  382. Get l5 // { arity: 1 }
  383. Map (null) // { arity: 1 }
  384. Union // { arity: 0 }
  385. Negate // { arity: 0 }
  386. Project () // { arity: 0 }
  387. Get l5 // { arity: 1 }
  388. Constant // { arity: 0 }
  389. - ()
  390. Source materialize.public.input
  391. Target cluster: quickstart
  392. EOF