@intentius/chant-lexicon-sql 0.124.45 → 0.124.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (360) hide show
  1. package/dist/change-set.d.ts +1 -1
  2. package/dist/change-set.d.ts.map +1 -1
  3. package/dist/change-set.js +2 -1
  4. package/dist/clickhouse/apply/statements.d.ts +9 -0
  5. package/dist/clickhouse/apply/statements.d.ts.map +1 -1
  6. package/dist/clickhouse/apply/statements.js +24 -0
  7. package/dist/clickhouse/import/live-export.d.ts +7 -3
  8. package/dist/clickhouse/import/live-export.d.ts.map +1 -1
  9. package/dist/clickhouse/import/live-export.js +21 -5
  10. package/dist/clickhouse/live/named-collections.d.ts +27 -0
  11. package/dist/clickhouse/live/named-collections.d.ts.map +1 -0
  12. package/dist/clickhouse/live/named-collections.js +53 -0
  13. package/dist/clickhouse/live/undeclarable.d.ts +15 -3
  14. package/dist/clickhouse/live/undeclarable.d.ts.map +1 -1
  15. package/dist/clickhouse/live/undeclarable.js +18 -4
  16. package/dist/clickhouse/named-collections.d.ts +83 -0
  17. package/dist/clickhouse/named-collections.d.ts.map +1 -0
  18. package/dist/clickhouse/named-collections.js +203 -0
  19. package/dist/clickhouse/parser.d.ts.map +1 -1
  20. package/dist/clickhouse/parser.js +1 -1
  21. package/dist/clickhouse/plan/commands.d.ts +2 -1
  22. package/dist/clickhouse/plan/commands.d.ts.map +1 -1
  23. package/dist/clickhouse/plan/commands.js +17 -2
  24. package/dist/clickhouse/plan/diff.d.ts +15 -0
  25. package/dist/clickhouse/plan/diff.d.ts.map +1 -1
  26. package/dist/clickhouse/plan/diff.js +43 -1
  27. package/dist/clickhouse/plan/disruption.d.ts.map +1 -1
  28. package/dist/clickhouse/plan/disruption.js +5 -0
  29. package/dist/clickhouse/plan/rebuild-handoff.d.ts.map +1 -1
  30. package/dist/clickhouse/plan/rebuild-handoff.js +4 -0
  31. package/dist/clickhouse/plan/report.d.ts.map +1 -1
  32. package/dist/clickhouse/plan/report.js +6 -1
  33. package/dist/clickhouse/plan/rules.d.ts +5 -1
  34. package/dist/clickhouse/plan/rules.d.ts.map +1 -1
  35. package/dist/clickhouse/plan/rules.js +7 -3
  36. package/dist/clickhouse/plan/stream.d.ts +40 -0
  37. package/dist/clickhouse/plan/stream.d.ts.map +1 -0
  38. package/dist/clickhouse/plan/stream.js +107 -0
  39. package/dist/clickhouse/rebuild/observe.d.ts +3 -1
  40. package/dist/clickhouse/rebuild/observe.d.ts.map +1 -1
  41. package/dist/clickhouse/rebuild/observe.js +14 -1
  42. package/dist/clickhouse/review-catalog.d.ts +213 -0
  43. package/dist/clickhouse/review-catalog.d.ts.map +1 -0
  44. package/dist/clickhouse/review-catalog.js +330 -0
  45. package/dist/codegen/classifier-page.d.ts.map +1 -1
  46. package/dist/codegen/classifier-page.js +21 -4
  47. package/dist/codegen/clickhouse-module.d.ts.map +1 -1
  48. package/dist/codegen/clickhouse-module.js +3 -0
  49. package/dist/codegen/coverage-page.d.ts.map +1 -1
  50. package/dist/codegen/coverage-page.js +5 -3
  51. package/dist/codegen/docs.js +1 -1
  52. package/dist/codegen/postgres-classifier-page.js +1 -1
  53. package/dist/codegen/registry.d.ts.map +1 -1
  54. package/dist/codegen/registry.js +5 -0
  55. package/dist/composites/catalog.d.ts.map +1 -1
  56. package/dist/composites/catalog.js +100 -0
  57. package/dist/composites/clickhouse.d.ts +2 -0
  58. package/dist/composites/clickhouse.d.ts.map +1 -1
  59. package/dist/composites/clickhouse.js +2 -0
  60. package/dist/composites/otel-tables.d.ts +100 -0
  61. package/dist/composites/otel-tables.d.ts.map +1 -0
  62. package/dist/composites/otel-tables.js +282 -0
  63. package/dist/composites/stream-ingest.d.ts +63 -0
  64. package/dist/composites/stream-ingest.d.ts.map +1 -0
  65. package/dist/composites/stream-ingest.js +39 -0
  66. package/dist/coverage/clickhouse.json +1 -1
  67. package/dist/coverage/postgres.json +7 -7
  68. package/dist/coverage.d.ts +16 -6
  69. package/dist/coverage.d.ts.map +1 -1
  70. package/dist/coverage.js +10 -5
  71. package/dist/drizzle-command.d.ts +17 -0
  72. package/dist/drizzle-command.d.ts.map +1 -0
  73. package/dist/drizzle-command.js +91 -0
  74. package/dist/drizzle.d.ts +70 -0
  75. package/dist/drizzle.d.ts.map +1 -0
  76. package/dist/drizzle.js +684 -0
  77. package/dist/files/clickhouse.d.ts.map +1 -1
  78. package/dist/files/clickhouse.js +8 -1
  79. package/dist/files/common.d.ts +13 -0
  80. package/dist/files/common.d.ts.map +1 -1
  81. package/dist/files/common.js +5 -0
  82. package/dist/files/postgres.js +12 -2
  83. package/dist/generated/clickhouse.d.ts +2 -0
  84. package/dist/generated/clickhouse.d.ts.map +1 -1
  85. package/dist/generated/clickhouse.js +2 -0
  86. package/dist/import-parser.d.ts +21 -1
  87. package/dist/import-parser.d.ts.map +1 -1
  88. package/dist/import-parser.js +79 -5
  89. package/dist/index.d.ts +1 -1
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +1 -1
  92. package/dist/integrity.json +6 -5
  93. package/dist/lint/post-synth/audit-entries.d.ts.map +1 -1
  94. package/dist/lint/post-synth/audit-entries.js +1 -0
  95. package/dist/lint/post-synth/index.d.ts.map +1 -1
  96. package/dist/lint/post-synth/index.js +2 -0
  97. package/dist/lint/post-synth/sqlch128.d.ts +18 -0
  98. package/dist/lint/post-synth/sqlch128.d.ts.map +1 -0
  99. package/dist/lint/post-synth/sqlch128.js +222 -0
  100. package/dist/lint/rules/postgres-templates.js +2 -2
  101. package/dist/lsp/postgres-template.d.ts.map +1 -1
  102. package/dist/lsp/postgres-template.js +11 -0
  103. package/dist/manifest.json +1 -1
  104. package/dist/mcp/postgres.js +1 -1
  105. package/dist/meta.json +25 -0
  106. package/dist/migrate/from-postgres/detect.d.ts +4 -0
  107. package/dist/migrate/from-postgres/detect.d.ts.map +1 -0
  108. package/dist/migrate/from-postgres/detect.js +7 -0
  109. package/dist/migrate/from-postgres/emit.d.ts +26 -0
  110. package/dist/migrate/from-postgres/emit.d.ts.map +1 -0
  111. package/dist/migrate/from-postgres/emit.js +86 -0
  112. package/dist/migrate/from-postgres/index.d.ts +51 -0
  113. package/dist/migrate/from-postgres/index.d.ts.map +1 -0
  114. package/dist/migrate/from-postgres/index.js +115 -0
  115. package/dist/migrate/from-postgres/translate.d.ts +73 -0
  116. package/dist/migrate/from-postgres/translate.d.ts.map +1 -0
  117. package/dist/migrate/from-postgres/translate.js +261 -0
  118. package/dist/migrate/from-postgres/types.d.ts +51 -0
  119. package/dist/migrate/from-postgres/types.d.ts.map +1 -0
  120. package/dist/migrate/from-postgres/types.js +211 -0
  121. package/dist/migration-replay.d.ts +73 -0
  122. package/dist/migration-replay.d.ts.map +1 -0
  123. package/dist/migration-replay.js +294 -0
  124. package/dist/okf/index.md +6 -0
  125. package/dist/okf/rules/SQLCH128.md +11 -0
  126. package/dist/okf/types/PostgresForeignDataWrapper.md +9 -0
  127. package/dist/okf/types/PostgresForeignServer.md +9 -0
  128. package/dist/okf/types/PostgresOperator.md +9 -0
  129. package/dist/okf/types/PostgresPublication.md +9 -0
  130. package/dist/okf/types/PostgresStatistics.md +9 -0
  131. package/dist/op/activities/postgres-migration.d.ts.map +1 -1
  132. package/dist/op/activities/postgres-migration.js +4 -0
  133. package/dist/op/activity-contracts.d.ts +20 -0
  134. package/dist/op/activity-contracts.d.ts.map +1 -1
  135. package/dist/op/activity-contracts.js +2 -0
  136. package/dist/plugin.d.ts.map +1 -1
  137. package/dist/plugin.js +36 -2
  138. package/dist/postgres/apply/apply.js +8 -1
  139. package/dist/postgres/apply/statements.d.ts.map +1 -1
  140. package/dist/postgres/apply/statements.js +87 -2
  141. package/dist/postgres/constraint-names.d.ts +30 -0
  142. package/dist/postgres/constraint-names.d.ts.map +1 -0
  143. package/dist/postgres/constraint-names.js +72 -0
  144. package/dist/postgres/entities.d.ts +110 -1
  145. package/dist/postgres/entities.d.ts.map +1 -1
  146. package/dist/postgres/entities.js +146 -0
  147. package/dist/postgres/entity-types.d.ts +5 -0
  148. package/dist/postgres/entity-types.d.ts.map +1 -1
  149. package/dist/postgres/entity-types.js +5 -0
  150. package/dist/postgres/import/generator.d.ts.map +1 -1
  151. package/dist/postgres/import/generator.js +50 -2
  152. package/dist/postgres/import/live-export.d.ts.map +1 -1
  153. package/dist/postgres/import/live-export.js +2 -0
  154. package/dist/postgres/live/catalog-kinds.d.ts +14 -0
  155. package/dist/postgres/live/catalog-kinds.d.ts.map +1 -1
  156. package/dist/postgres/live/catalog-kinds.js +206 -0
  157. package/dist/postgres/live/catalog.d.ts +2 -0
  158. package/dist/postgres/live/catalog.d.ts.map +1 -1
  159. package/dist/postgres/live/catalog.js +3 -1
  160. package/dist/postgres/live/describe-resources.d.ts.map +1 -1
  161. package/dist/postgres/live/describe-resources.js +10 -2
  162. package/dist/postgres/migrate/backfill.d.ts +2 -0
  163. package/dist/postgres/migrate/backfill.d.ts.map +1 -1
  164. package/dist/postgres/migrate/backfill.js +7 -1
  165. package/dist/postgres/migrate/carry.d.ts +45 -1
  166. package/dist/postgres/migrate/carry.d.ts.map +1 -1
  167. package/dist/postgres/migrate/carry.js +72 -8
  168. package/dist/postgres/migrate/observe.d.ts +28 -4
  169. package/dist/postgres/migrate/observe.d.ts.map +1 -1
  170. package/dist/postgres/migrate/observe.js +41 -12
  171. package/dist/postgres/migrate/op.d.ts +26 -1
  172. package/dist/postgres/migrate/op.d.ts.map +1 -1
  173. package/dist/postgres/migrate/op.js +3 -1
  174. package/dist/postgres/migrate/steps.d.ts +35 -2
  175. package/dist/postgres/migrate/steps.d.ts.map +1 -1
  176. package/dist/postgres/migrate/steps.js +158 -12
  177. package/dist/postgres/parser.d.ts +72 -1
  178. package/dist/postgres/parser.d.ts.map +1 -1
  179. package/dist/postgres/parser.js +194 -2
  180. package/dist/postgres/plan/deep.d.ts.map +1 -1
  181. package/dist/postgres/plan/deep.js +29 -1
  182. package/dist/postgres/plan/diff.d.ts.map +1 -1
  183. package/dist/postgres/plan/diff.js +39 -1
  184. package/dist/postgres/plan/normalize.d.ts +17 -2
  185. package/dist/postgres/plan/normalize.d.ts.map +1 -1
  186. package/dist/postgres/plan/normalize.js +109 -1
  187. package/dist/postgres/plan/rules.d.ts +1 -0
  188. package/dist/postgres/plan/rules.d.ts.map +1 -1
  189. package/dist/postgres/plan/rules.js +3 -2
  190. package/dist/postgres/plan/schema.js +1 -1
  191. package/dist/postgres/secret-options.d.ts +10 -0
  192. package/dist/postgres/secret-options.d.ts.map +1 -0
  193. package/dist/postgres/secret-options.js +9 -0
  194. package/dist/postgres/testing/roundtrip-schema.d.ts +3 -2
  195. package/dist/postgres/testing/roundtrip-schema.d.ts.map +1 -1
  196. package/dist/postgres/testing/roundtrip-schema.js +13 -1
  197. package/dist/postgres.d.ts +1 -1
  198. package/dist/postgres.d.ts.map +1 -1
  199. package/dist/postgres.js +1 -1
  200. package/dist/rules/audit-entries.ts +1 -0
  201. package/dist/rules/postgres-templates.ts +2 -2
  202. package/dist/rules/sqlch128.ts +230 -0
  203. package/dist/serializer.d.ts +5 -0
  204. package/dist/serializer.d.ts.map +1 -1
  205. package/dist/serializer.js +13 -2
  206. package/dist/sql-types-command.d.ts +13 -0
  207. package/dist/sql-types-command.d.ts.map +1 -1
  208. package/dist/sql-types-command.js +31 -16
  209. package/dist/sql-types.d.ts +22 -0
  210. package/dist/sql-types.d.ts.map +1 -1
  211. package/dist/sql-types.js +10 -6
  212. package/dist/sqlserver/lexer.d.ts +37 -0
  213. package/dist/sqlserver/lexer.d.ts.map +1 -0
  214. package/dist/sqlserver/lexer.js +254 -0
  215. package/dist/sqlserver/parse.d.ts +185 -0
  216. package/dist/sqlserver/parse.d.ts.map +1 -0
  217. package/dist/sqlserver/parse.js +767 -0
  218. package/dist/sqlserver/translate.d.ts +34 -0
  219. package/dist/sqlserver/translate.d.ts.map +1 -0
  220. package/dist/sqlserver/translate.js +495 -0
  221. package/dist/sqlserver/types.d.ts +44 -0
  222. package/dist/sqlserver/types.d.ts.map +1 -0
  223. package/dist/sqlserver/types.js +133 -0
  224. package/dist/sqlserver/validate.d.ts +31 -0
  225. package/dist/sqlserver/validate.d.ts.map +1 -0
  226. package/dist/sqlserver/validate.js +67 -0
  227. package/dist/validate.d.ts.map +1 -1
  228. package/dist/validate.js +5 -0
  229. package/package.json +2 -2
  230. package/src/change-set.ts +2 -1
  231. package/src/clickhouse/apply/statements.ts +25 -0
  232. package/src/clickhouse/import/live-export.ts +20 -5
  233. package/src/clickhouse/live/named-collections.e2e.test.ts +88 -0
  234. package/src/clickhouse/live/named-collections.ts +61 -0
  235. package/src/clickhouse/live/undeclarable.e2e.test.ts +5 -3
  236. package/src/clickhouse/live/undeclarable.ts +20 -4
  237. package/src/clickhouse/named-collections.test.ts +187 -0
  238. package/src/clickhouse/named-collections.ts +224 -0
  239. package/src/clickhouse/parser.ts +2 -1
  240. package/src/clickhouse/plan/commands.ts +17 -2
  241. package/src/clickhouse/plan/diff.ts +57 -1
  242. package/src/clickhouse/plan/disruption.ts +5 -0
  243. package/src/clickhouse/plan/rebuild-handoff.ts +3 -0
  244. package/src/clickhouse/plan/report.ts +6 -1
  245. package/src/clickhouse/plan/rules.ts +14 -4
  246. package/src/clickhouse/plan/stream-s3queue.e2e.test.ts +148 -0
  247. package/src/clickhouse/plan/stream.test.ts +237 -0
  248. package/src/clickhouse/plan/stream.ts +111 -0
  249. package/src/clickhouse/rebuild/observe.ts +15 -1
  250. package/src/clickhouse/review-catalog.test.ts +181 -0
  251. package/src/clickhouse/review-catalog.ts +489 -0
  252. package/src/codegen/classifier-page.ts +21 -4
  253. package/src/codegen/clickhouse-module.ts +3 -0
  254. package/src/codegen/coverage-page.ts +5 -3
  255. package/src/codegen/docs.ts +1 -1
  256. package/src/codegen/postgres-classifier-page.ts +1 -1
  257. package/src/codegen/registry.ts +5 -0
  258. package/src/composites/catalog.test.ts +6 -1
  259. package/src/composites/catalog.ts +100 -0
  260. package/src/composites/clickhouse.ts +2 -0
  261. package/src/composites/composites.test.ts +1 -1
  262. package/src/composites/otel-tables.test.ts +118 -0
  263. package/src/composites/otel-tables.ts +339 -0
  264. package/src/composites/stream-ingest.test.ts +114 -0
  265. package/src/composites/stream-ingest.ts +82 -0
  266. package/src/core/undeclarable.test.ts +6 -5
  267. package/src/coverage/clickhouse.json +1 -1
  268. package/src/coverage/postgres.json +7 -7
  269. package/src/coverage.test.ts +27 -2
  270. package/src/coverage.ts +18 -7
  271. package/src/drizzle-command.ts +94 -0
  272. package/src/drizzle-kit.e2e.test.ts +89 -0
  273. package/src/drizzle-types.e2e.test.ts +67 -0
  274. package/src/drizzle.test.ts +358 -0
  275. package/src/drizzle.ts +737 -0
  276. package/src/files/clickhouse.ts +8 -1
  277. package/src/files/common.ts +14 -1
  278. package/src/files/postgres.ts +12 -2
  279. package/src/generated/clickhouse.ts +3 -0
  280. package/src/generated/lexicon-sql.json +25 -0
  281. package/src/import-parser.sqlserver.test.ts +92 -0
  282. package/src/import-parser.ts +79 -5
  283. package/src/index.ts +1 -1
  284. package/src/lint/post-synth/audit-entries.ts +1 -0
  285. package/src/lint/post-synth/index.ts +2 -0
  286. package/src/lint/post-synth/sqlch128.test.ts +107 -0
  287. package/src/lint/post-synth/sqlch128.ts +230 -0
  288. package/src/lint/rules/postgres-templates.ts +2 -2
  289. package/src/lsp/postgres-template.ts +11 -0
  290. package/src/mcp/postgres.ts +1 -1
  291. package/src/migrate/from-postgres/cli.test.ts +165 -0
  292. package/src/migrate/from-postgres/detect.ts +7 -0
  293. package/src/migrate/from-postgres/emit.ts +96 -0
  294. package/src/migrate/from-postgres/example.test.ts +205 -0
  295. package/src/migrate/from-postgres/index.ts +122 -0
  296. package/src/migrate/from-postgres/translate.test.ts +242 -0
  297. package/src/migrate/from-postgres/translate.ts +359 -0
  298. package/src/migrate/from-postgres/types.test.ts +116 -0
  299. package/src/migrate/from-postgres/types.ts +236 -0
  300. package/src/migrate/from-postgres/validate.e2e.test.ts +44 -0
  301. package/src/migrate/from-postgres/workspace.e2e.test.ts +114 -0
  302. package/src/migration-replay.e2e.test.ts +155 -0
  303. package/src/migration-replay.test.ts +173 -0
  304. package/src/migration-replay.ts +289 -0
  305. package/src/op/__snapshots__/watch-pipeline.test.ts.snap +2 -2
  306. package/src/op/activities/postgres-migration.ts +4 -0
  307. package/src/op/activity-contracts.ts +2 -0
  308. package/src/plugin.ts +37 -2
  309. package/src/postgres/apply/apply.ts +9 -1
  310. package/src/postgres/apply/statements.ts +74 -1
  311. package/src/postgres/constraint-names.ts +71 -0
  312. package/src/postgres/database-kinds.test.ts +384 -0
  313. package/src/postgres/entities.ts +266 -1
  314. package/src/postgres/entity-types.ts +5 -0
  315. package/src/postgres/import/generator.ts +42 -2
  316. package/src/postgres/import/live-export.ts +1 -0
  317. package/src/postgres/live/catalog-kinds.ts +223 -0
  318. package/src/postgres/live/catalog.ts +6 -1
  319. package/src/postgres/live/database-kinds.e2e.test.ts +164 -0
  320. package/src/postgres/live/describe-resources.ts +11 -2
  321. package/src/postgres/live/undeclarable.e2e.test.ts +13 -6
  322. package/src/postgres/migrate/backfill.ts +13 -1
  323. package/src/postgres/migrate/carry.ts +103 -8
  324. package/src/postgres/migrate/followups.e2e.test.ts +218 -0
  325. package/src/postgres/migrate/followups.test.ts +199 -0
  326. package/src/postgres/migrate/kinds.e2e.test.ts +5 -5
  327. package/src/postgres/migrate/observe.ts +53 -14
  328. package/src/postgres/migrate/op.ts +28 -1
  329. package/src/postgres/migrate/partition.e2e.test.ts +129 -0
  330. package/src/postgres/migrate/partition.test.ts +206 -0
  331. package/src/postgres/migrate/steps.ts +157 -12
  332. package/src/postgres/parser.ts +234 -2
  333. package/src/postgres/plan/deep.ts +28 -1
  334. package/src/postgres/plan/diff.ts +36 -1
  335. package/src/postgres/plan/normalize.ts +122 -1
  336. package/src/postgres/plan/rules.ts +10 -3
  337. package/src/postgres/plan/schema.ts +1 -1
  338. package/src/postgres/secret-options.ts +10 -0
  339. package/src/postgres/testing/roundtrip-schema.ts +13 -1
  340. package/src/postgres.ts +16 -0
  341. package/src/serializer.ts +13 -2
  342. package/src/skills/chant-sql-postgres-migration.md +3 -3
  343. package/src/skills/chant-sql-postgres.md +6 -1
  344. package/src/skills/chant-sql.md +2 -1
  345. package/src/sql-types-command.ts +38 -16
  346. package/src/sql-types.ts +11 -6
  347. package/src/sqlserver/fixture.test.ts +186 -0
  348. package/src/sqlserver/import-cli.test.ts +61 -0
  349. package/src/sqlserver/lexer.ts +260 -0
  350. package/src/sqlserver/parse.ts +865 -0
  351. package/src/sqlserver/translate.test.ts +396 -0
  352. package/src/sqlserver/translate.ts +558 -0
  353. package/src/sqlserver/types.test.ts +102 -0
  354. package/src/sqlserver/types.ts +154 -0
  355. package/src/sqlserver/validate.e2e.test.ts +32 -0
  356. package/src/sqlserver/validate.test.ts +49 -0
  357. package/src/sqlserver/validate.ts +76 -0
  358. package/src/validate.ts +5 -0
  359. package/src/workspace-kinds.test.ts +11 -0
  360. package/workspace-kinds.json +100 -2
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Stream engines (#4396): Kafka, S3Queue, AzureQueue, RabbitMQ, NATS and
3
+ * FileLog. A table on one of them stores no rows. It is a consumer: the
4
+ * materialized views that read it pull messages (or files) through it into a
5
+ * target, and the position it has reached lives outside the table, in the
6
+ * broker's committed offsets or in Keeper.
7
+ *
8
+ * What follows from that, and what this file holds:
9
+ *
10
+ * - There is no ALTER for the engine's arguments, and nothing to copy to a
11
+ * new table, so a change is neither `metadata` nor a `rebuild`: the table is
12
+ * replaced, with the views that read it detached around the replacement
13
+ * (SQLCH225, `./rules.ts`).
14
+ * - A replacement can lose the table's position. The two changes that do
15
+ * are found here and reported on the change as a note.
16
+ */
17
+ /** The stream engines, as `system.tables.engine` names them. */
18
+ export const STREAM_ENGINES = new Set(["Kafka", "S3Queue", "AzureQueue", "RabbitMQ", "NATS", "FileLog"]);
19
+ /** Whether an engine name is a stream engine. */
20
+ export const isStreamEngine = (engine) => engine !== undefined && STREAM_ENGINES.has(engine);
21
+ /** Whether a canonical table is on a stream engine. */
22
+ export const isStreamTable = (o) => o.kind === "table" && isStreamEngine(o.engineName);
23
+ /** The arguments inside an engine's parentheses, split at top-level commas, string quotes removed. Empty when it has none. */
24
+ export function streamEngineArguments(engine) {
25
+ const open = engine?.indexOf("(") ?? -1;
26
+ if (engine === undefined || open < 0 || !engine.endsWith(")"))
27
+ return [];
28
+ const inner = engine.slice(open + 1, -1);
29
+ const out = [];
30
+ let depth = 0;
31
+ let quote;
32
+ let cur = "";
33
+ for (let i = 0; i < inner.length; i++) {
34
+ const ch = inner[i];
35
+ if (quote) {
36
+ cur += ch;
37
+ if (ch === "\\")
38
+ cur += inner[++i] ?? "";
39
+ else if (ch === quote)
40
+ quote = undefined;
41
+ continue;
42
+ }
43
+ if (ch === "'" || ch === '"' || ch === "`")
44
+ quote = ch;
45
+ if (ch === "(" || ch === "[")
46
+ depth++;
47
+ if (ch === ")" || ch === "]")
48
+ depth--;
49
+ if (ch === "," && depth === 0) {
50
+ out.push(cur.trim());
51
+ cur = "";
52
+ }
53
+ else
54
+ cur += ch;
55
+ }
56
+ if (cur.trim())
57
+ out.push(cur.trim());
58
+ return out.map((a) => (/^'.*'$/.test(a) ? a.slice(1, -1) : a));
59
+ }
60
+ /** Kafka's positional arguments, in the order the engine takes them. */
61
+ const KAFKA_POSITIONAL = ["kafka_broker_list", "kafka_topic_list", "kafka_group_name", "kafka_format"];
62
+ /** A Kafka setting, from SETTINGS or from the engine's positional arguments. */
63
+ function kafkaSetting(o, name) {
64
+ const at = KAFKA_POSITIONAL.indexOf(name);
65
+ return o.settings[name] ?? (at >= 0 ? streamEngineArguments(o.engine)[at] : undefined);
66
+ }
67
+ /**
68
+ * What a replacement would lose, in a sentence each (#4396):
69
+ *
70
+ * - a different `kafka_group_name` is a different consumer group: it starts
71
+ * from the group's committed offsets, or from the topic's start when the
72
+ * group has none (`auto.offset.reset`);
73
+ * - a different S3Queue `keeper_path` is a different place for the table's
74
+ * record of processed files, so every file already seen is processed again.
75
+ *
76
+ * Neither is a refusal: a new group or path is sometimes the point.
77
+ */
78
+ export function positionWarnings(before, after) {
79
+ const out = [];
80
+ if (before.engineName === "Kafka" && after.engineName === "Kafka") {
81
+ const b = kafkaSetting(before, "kafka_group_name");
82
+ const a = kafkaSetting(after, "kafka_group_name");
83
+ if (b !== a) {
84
+ out.push(`kafka_group_name changes from ${b ?? "none"} to ${a ?? "none"}: the new group starts from its own committed offsets, or from the start of the topic when it has none, ` +
85
+ "so messages already consumed may be read again or skipped");
86
+ }
87
+ }
88
+ if (before.engineName === "S3Queue" && after.engineName === "S3Queue") {
89
+ const b = before.settings.keeper_path;
90
+ const a = after.settings.keeper_path;
91
+ if (b !== a) {
92
+ out.push(`keeper_path changes from ${b ?? "none"} to ${a ?? "none"}: the new path holds no record of processed files, so every file already seen is processed again`);
93
+ }
94
+ }
95
+ return out;
96
+ }
97
+ /** Whether a materialized view reads from the table: its SELECT names the table, qualified or, in the table's own database, bare. */
98
+ export function readsTable(view, table) {
99
+ if (view.kind !== "materializedView" || view.select === undefined)
100
+ return false;
101
+ const escaped = table.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
102
+ const sameDatabase = view.database === table.database;
103
+ const database = table.database?.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
104
+ // The canonical SELECT drops the view's own database from a name, so a bare name is a table in the view's database.
105
+ const names = [...(sameDatabase ? [escaped] : []), ...(database ? [`${database}\\s*\\.\\s*${escaped}`] : [])];
106
+ return names.some((n) => new RegExp(`(?:^|[^\\w.])${n}(?![\\w.])`).test(view.select));
107
+ }
@@ -27,7 +27,9 @@
27
27
  *
28
28
  * Anything else is refused with a {@link RebuildRefusal}: a database that is
29
29
  * neither Atomic nor Replicated, a table that is not there, a change that is
30
- * not a rebuild, a working object chant did not make.
30
+ * not a rebuild, a working object chant did not make, a table on a stream
31
+ * engine (Kafka, S3Queue, AzureQueue, RabbitMQ, NATS, FileLog), which holds no
32
+ * rows to copy and is replaced by the applier instead (#4396).
31
33
  *
32
34
  * A Replicated database (#3249) is Atomic on every replica, with its DDL run
33
35
  * on each through Keeper, so the same EXCHANGE swaps the table everywhere.
@@ -1 +1 @@
1
- {"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../../src/clickhouse/rebuild/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAmB,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAKxD,OAAO,EAAE,KAAK,EAAwC,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvG,gFAAgF;AAChF,MAAM,MAAM,SAAS,GACjB;IACE;;;;;;;;;;;;;;OAcG;IACH,IAAI,EAAE,mBAAmB,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACD;IACE;;;;;OAKG;IACH,IAAI,EAAE,KAAK,CAAC;CACb,CAAC;AAEN,iGAAiG;AACjG,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,uDAAuD;AACvD,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,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I,EAAE,eAAe,EAAE,EAAE,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAGzI;AA4BD,+DAA+D;AAC/D,wBAAsB,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,GAAG,SAAS,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6EzJ;AAoCD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,kBAAkB,EAAE,SAAS,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASvG;AAED,eAAO,MAAM,iBAAiB,GAAI,GAAG,kBAAkB,EAAE,WAAW,SAAS,KAAG,MAAmF,CAAC;AAEpK,mEAAmE;AACnE,OAAO,EAAE,KAAK,EAAE,CAAC"}
@@ -27,7 +27,9 @@
27
27
  *
28
28
  * Anything else is refused with a {@link RebuildRefusal}: a database that is
29
29
  * neither Atomic nor Replicated, a table that is not there, a change that is
30
- * not a rebuild, a working object chant did not make.
30
+ * not a rebuild, a working object chant did not make, a table on a stream
31
+ * engine (Kafka, S3Queue, AzureQueue, RabbitMQ, NATS, FileLog), which holds no
32
+ * rows to copy and is replaced by the applier instead (#4396).
31
33
  *
32
34
  * A Replicated database (#3249) is Atomic on every replica, with its DDL run
33
35
  * on each through Keeper, so the same EXCHANGE swaps the table everywhere.
@@ -44,6 +46,7 @@ import { dropFormattingOnly } from "../plan/server-format.js";
44
46
  import { CLASSIFIER_RULES } from "../plan/rules.js";
45
47
  import { CLICKHOUSE_ENTITY_TYPES } from "../entities.js";
46
48
  import { carriesMarker, readTrailerPairs, REBUILD_TRAILER_KEY, stripMarkerFromStatement } from "../ownership.js";
49
+ import { isStreamEngine } from "../plan/stream.js";
47
50
  import { ident, isRebuild, qualifiedIdent, sqlString } from "../apply/statements.js";
48
51
  /** A refusal: the rebuild cannot start, or cannot go on, for a reason a person has to act on. */
49
52
  export class RebuildRefusal extends Error {
@@ -140,10 +143,18 @@ function ownWorkingObject(o, names, role, marker) {
140
143
  }
141
144
  return o;
142
145
  }
146
+ /** The refusal for a stream-engine table, naming the engine and where its change goes instead (#4396). */
147
+ function streamRefusal(key, engine, side) {
148
+ return new RebuildRefusal(`${key} is ${side === "declared" ? "declared on" : "on the server as"} the ${engine} engine, a stream engine: it stores no rows, so there is nothing to backfill, and a direct SELECT from it either fails ` +
149
+ `or consumes messages. A change to it is SQLCH225 (replace a stream table), which the applier makes in place: it detaches the materialized views that read the table, drops and creates it, and attaches the views again ` +
150
+ `(ApplyOp with target "clickhouse").`);
151
+ }
143
152
  /** Observe the rebuild of the declared table on the server. */
144
153
  export async function observeRebuild(target, declared, marker) {
145
154
  const database = declared.canonical.database ?? target.defaultDatabase;
146
155
  const names = rebuildNames(database, declared.canonical.name);
156
+ if (isStreamEngine(declared.canonical.engineName))
157
+ throw streamRefusal(names.key, declared.canonical.engineName, "declared");
147
158
  const [db] = await clickhouseQuery(target.endpoint, `SELECT engine FROM system.databases WHERE name = ${sqlString(database)}`);
148
159
  if (!db)
149
160
  throw new RebuildRefusal(`database ${database} is not on the server, so there is no ${names.key} to rebuild; the applier creates it`);
@@ -160,6 +171,8 @@ export async function observeRebuild(target, declared, marker) {
160
171
  // Between EXCHANGE and the end of the swap, the table's own name holds the
161
172
  // new table, still carrying role=new, and the new table's name holds the
162
173
  // old table until it is renamed; the swap step finishes that.
174
+ if (isStreamEngine(liveRow.engine))
175
+ throw streamRefusal(names.key, liveRow.engine, "live");
163
176
  const exchanged = liveRow.pairs?.get(REBUILD_TRAILER_KEY) === names.key && liveRow.pairs.get("role") === "new";
164
177
  const newTable = exchanged ? undefined : ownWorkingObject(objects.get(names.newName), names, "new", marker);
165
178
  const exchangedOld = exchanged ? objects.get(names.newName) : undefined;
@@ -0,0 +1,213 @@
1
+ /**
2
+ * The needs-review catalog: the judgment calls that turn a table from another
3
+ * database into a ClickHouse table, each as a finding with the evidence it
4
+ * used. A source reader (`chant import` of SQL Server, #4398; `chant migrate`
5
+ * of Postgres, #4399) does the mechanical work, a type map and a rename,
6
+ * and asks this module for everything that is a decision.
7
+ *
8
+ * Nothing here knows a source dialect. A reader describes its table in the
9
+ * neutral facts below (a candidate sort key, a column's nullability, a
10
+ * constraint) and gets back the ClickHouse choice, a finding to report, and
11
+ * for a constraint the comment lines to keep in the DDL. The rules are the
12
+ * same whichever database the table came from.
13
+ *
14
+ * ## API
15
+ *
16
+ * - {@link sortKeyReview}: `ORDER BY` from the candidates the source offers,
17
+ * in the priority `explicit-order`, `clustering-key`, `primary-key`,
18
+ * `unique-key`, then `tuple()`. Returns `orderBy`, the `settings` the key
19
+ * needs (`allow_nullable_key` when a key column is `Nullable`), and a
20
+ * finding that names the chosen candidate and the others it passed over.
21
+ * - {@link engineReview}: `MergeTree` for an append-only table;
22
+ * `ReplacingMergeTree(_version, _deleted)` for a CDC mirror, with the two
23
+ * columns it adds in `extraColumns`. `cdcColumns` names them otherwise
24
+ * (the Postgres pair uses the `CdcMirror` composite's `_is_deleted`).
25
+ * - {@link nullableReview}: a column's final type. A `NOT NULL` column keeps
26
+ * its type with no finding. A nullable column becomes `Nullable(T)` with a
27
+ * finding; when it has a default the finding says the default could
28
+ * replace `Nullable`.
29
+ * - {@link lowCardinalityReview}: a finding for a `String` column whose name
30
+ * and declared length suggest few distinct values. It never changes the
31
+ * type; offline, the name and the type are all there is to read.
32
+ * - {@link constraintReview}: foreign keys, checks, unique and exclusion
33
+ * constraints, which ClickHouse does not enforce. Returns `comments` (SQL `--` lines to
34
+ * put before the `CREATE`) and one finding per constraint.
35
+ * - {@link REVIEW_RULES}: every rule id with its summary and the ClickHouse
36
+ * documentation it rests on, for report metadata.
37
+ * - {@link findingText}: a finding as one line (object, message, evidence,
38
+ * suggestion), the form a SARIF `message` takes.
39
+ *
40
+ * A finding's `severity` is `warning` for a decision the author must confirm
41
+ * and `info` for a note that changes nothing. The caller maps findings to its
42
+ * own diagnostic type; `at` carries the source line and column when the
43
+ * reader knows them.
44
+ *
45
+ * Every ClickHouse type and engine this module writes is checked against the
46
+ * pinned catalog (`src/generated/clickhouse.ts`, ClickHouse 26.8) in
47
+ * `review-catalog.test.ts`, so a pin move that drops one fails there.
48
+ *
49
+ * Sources: the MergeTree sorting key and `allow_nullable_key`
50
+ * (https://clickhouse.com/docs/engines/table-engines/mergetree-family/mergetree),
51
+ * `ReplacingMergeTree(ver, is_deleted)`
52
+ * (https://clickhouse.com/docs/engines/table-engines/mergetree-family/replacingmergetree),
53
+ * `Nullable` (https://clickhouse.com/docs/sql-reference/data-types/nullable),
54
+ * `LowCardinality`
55
+ * (https://clickhouse.com/docs/sql-reference/data-types/lowcardinality).
56
+ */
57
+ export type ReviewSeverity = "warning" | "info";
58
+ export type ReviewRuleId = "SQLRV001" | "SQLRV002" | "SQLRV003" | "SQLRV004" | "SQLRV005" | "SQLRV006" | "SQLRV007" | "SQLRV008" | "SQLRV009" | "SQLRV010" | "SQLRV011" | "SQLRV012";
59
+ export interface ReviewRule {
60
+ id: ReviewRuleId;
61
+ name: string;
62
+ summary: string;
63
+ docs: readonly string[];
64
+ }
65
+ /**
66
+ * The rules. SQLRV001 to SQLRV005 are the shared ones; the rest are raised by
67
+ * a source reader for what only its dialect has, and live here so a report
68
+ * lists one catalog.
69
+ */
70
+ export declare const REVIEW_RULES: Readonly<Record<ReviewRuleId, ReviewRule>>;
71
+ export interface SourcePosition {
72
+ /** 1-based. */
73
+ line: number;
74
+ /** 1-based. */
75
+ column: number;
76
+ }
77
+ export interface ReviewFinding {
78
+ ruleId: ReviewRuleId;
79
+ severity: ReviewSeverity;
80
+ /** The table or view the finding is about, as the source names it. */
81
+ object: string;
82
+ /** The column, when the finding is about one. */
83
+ column?: string;
84
+ message: string;
85
+ /** What the decision was read from: each entry is a fact in the source. */
86
+ evidence: readonly string[];
87
+ suggestion?: string;
88
+ at?: SourcePosition;
89
+ }
90
+ /** A finding as one line. */
91
+ export declare function findingText(f: ReviewFinding): string;
92
+ /**
93
+ * Where a candidate sort key came from, strongest first. `explicit-order` is
94
+ * an ordering the author declared for storage (a columnstore `ORDER`),
95
+ * `clustering-key` the key the source stores rows in (a clustered index),
96
+ * then the primary key and the first unique key.
97
+ */
98
+ export type SortKeyKind = "explicit-order" | "clustering-key" | "primary-key" | "unique-key";
99
+ export interface SortKeyCandidate {
100
+ kind: SortKeyKind;
101
+ /** The index or constraint name, for the evidence. */
102
+ name?: string;
103
+ columns: readonly string[];
104
+ /** Columns the source sorts descending; ClickHouse's `ORDER BY` drops the direction. */
105
+ descending?: readonly string[];
106
+ /** The fact this candidate was read from, e.g. `CREATE CLUSTERED INDEX CX_t`. */
107
+ source: string;
108
+ }
109
+ export interface SortKeyInput {
110
+ object: string;
111
+ candidates: readonly SortKeyCandidate[];
112
+ /** Each column's ClickHouse type, by name; `Nullable(...)` marks a nullable key column. */
113
+ columnTypes: Readonly<Record<string, string>>;
114
+ at?: SourcePosition;
115
+ }
116
+ export interface SortKeyResult {
117
+ orderBy: string[];
118
+ /** MergeTree settings the key needs. */
119
+ settings: Record<string, string>;
120
+ finding: ReviewFinding;
121
+ }
122
+ export declare function sortKeyReview(input: SortKeyInput): SortKeyResult;
123
+ export interface EngineInput {
124
+ object: string;
125
+ /**
126
+ * `append` for a table that is loaded and queried, `cdc` for a mirror of a
127
+ * table that changes in place (#4399): rows arrive as new versions and a
128
+ * delete arrives as a marker row.
129
+ */
130
+ mode: "append" | "cdc";
131
+ /** Facts about the source table that bear on the choice, as plain sentences. */
132
+ facts?: readonly string[];
133
+ /** The columns the source enforces unique, when it does. */
134
+ uniqueKey?: readonly string[];
135
+ /**
136
+ * For `cdc`, the names of the version and deleted columns, when the pipeline
137
+ * or the `CdcMirror` composite names them other than `_version` and
138
+ * `_deleted`. The names are the caller's; the catalog only writes them.
139
+ */
140
+ cdcColumns?: {
141
+ version: string;
142
+ deleted: string;
143
+ };
144
+ at?: SourcePosition;
145
+ }
146
+ export interface EngineResult {
147
+ /** The text after `ENGINE =`. */
148
+ engine: string;
149
+ /** Columns the engine needs and the source does not have. */
150
+ extraColumns: Array<{
151
+ name: string;
152
+ type: string;
153
+ }>;
154
+ finding: ReviewFinding;
155
+ }
156
+ export declare const CDC_VERSION_COLUMN: {
157
+ readonly name: "_version";
158
+ readonly type: "UInt64";
159
+ };
160
+ export declare const CDC_DELETED_COLUMN: {
161
+ readonly name: "_deleted";
162
+ readonly type: "UInt8";
163
+ };
164
+ export declare function engineReview(input: EngineInput): EngineResult;
165
+ export interface NullableInput {
166
+ object: string;
167
+ column: string;
168
+ /** The column's ClickHouse type before `Nullable`. */
169
+ type: string;
170
+ sourceNullable: boolean;
171
+ /** The default as the ClickHouse expression it became, or the source text when it did not translate. */
172
+ defaultExpr?: string;
173
+ at?: SourcePosition;
174
+ }
175
+ export interface NullableResult {
176
+ type: string;
177
+ finding?: ReviewFinding;
178
+ }
179
+ export declare function nullableReview(input: NullableInput): NullableResult;
180
+ export interface LowCardinalityInput {
181
+ object: string;
182
+ column: string;
183
+ /** The ClickHouse type as emitted. Only `String` and `Nullable(String)` are candidates. */
184
+ type: string;
185
+ /** The source's declared maximum length, when it has one. */
186
+ maxLength?: number;
187
+ at?: SourcePosition;
188
+ }
189
+ /** The longest declared length that still counts as supporting evidence. */
190
+ export declare const LOW_CARDINALITY_MAX_LENGTH = 50;
191
+ export declare function lowCardinalityReview(input: LowCardinalityInput): ReviewFinding | undefined;
192
+ export interface ConstraintFact {
193
+ kind: "foreign-key" | "check" | "unique" | "exclusion";
194
+ name?: string;
195
+ columns?: readonly string[];
196
+ references?: {
197
+ table: string;
198
+ columns: readonly string[];
199
+ };
200
+ /** A check's expression, or an exclusion's `USING method (element WITH operator, ...)`, as the source wrote it. */
201
+ expression?: string;
202
+ at?: SourcePosition;
203
+ }
204
+ export interface ConstraintResult {
205
+ /** `-- ` lines to put before the `CREATE`; never contain a line break. */
206
+ comments: string[];
207
+ findings: ReviewFinding[];
208
+ }
209
+ export declare function constraintReview(input: {
210
+ object: string;
211
+ constraints: readonly ConstraintFact[];
212
+ }): ConstraintResult;
213
+ //# sourceMappingURL=review-catalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"review-catalog.d.ts","sourceRoot":"","sources":["../../src/clickhouse/review-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,MAAM,CAAC;AAEhD,MAAM,MAAM,YAAY,GACpB,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,GACV,UAAU,CAAC;AAEf,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,YAAY,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB;AAID;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAyEnE,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,eAAe;IACf,IAAI,EAAE,MAAM,CAAC;IACb,eAAe;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,cAAc,CAAC;IACzB,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,EAAE,CAAC,EAAE,cAAc,CAAC;CACrB;AAED,6BAA6B;AAC7B,wBAAgB,WAAW,CAAC,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