dependencies.td 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. $ set-arg-default single-replica-cluster=quickstart
  10. # Test that a dependency chain with multiple links is properly maintained
  11. # across creation and deletion.
  12. $ set-regex match=cluster1|quickstart replacement=<CLUSTER_NAME>
  13. $ kafka-create-topic topic=data partitions=1
  14. $ kafka-create-topic topic=data-blah partitions=1
  15. $ kafka-create-topic topic=v partitions=1
  16. $ kafka-create-topic topic=v2 partitions=1
  17. $ kafka-create-topic topic=v3 partitions=1
  18. $ set schema={
  19. "name": "row",
  20. "type": "record",
  21. "fields": [
  22. {"name": "x", "type": "long"},
  23. {"name": "y", "type": "string"}
  24. ]
  25. }
  26. > CREATE CONNECTION kafka_conn
  27. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  28. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  29. URL '${testdrive.schema-registry-url}'
  30. );
  31. > CREATE SOURCE s
  32. IN CLUSTER ${arg.single-replica-cluster}
  33. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  34. ! CREATE SOURCE s
  35. IN CLUSTER ${arg.single-replica-cluster}
  36. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-blah-${testdrive.seed}')
  37. contains:source "materialize.public.s" already exists
  38. > DROP SOURCE s
  39. > CREATE SOURCE s
  40. IN CLUSTER ${arg.single-replica-cluster}
  41. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-blah-${testdrive.seed}')
  42. > CREATE TABLE s_tbl FROM SOURCE s (REFERENCE "testdrive-data-blah-${testdrive.seed}")
  43. FORMAT AVRO USING SCHEMA '${schema}'
  44. > CREATE VIEW test1 AS SELECT 1;
  45. > CREATE VIEW test2 AS SELECT * FROM test1;
  46. > CREATE VIEW test3a AS SELECT * FROM test2;
  47. > CREATE VIEW test3b AS SELECT * FROM test2;
  48. ! DROP VIEW test1;
  49. contains:cannot drop view "test1": still depended upon by view "test2"
  50. ! DROP VIEW test2;
  51. contains:cannot drop view "test2": still depended upon by view "test3a"
  52. > DROP VIEW test3a;
  53. ! DROP VIEW test1;
  54. contains:cannot drop view "test1": still depended upon by view "test2"
  55. ! DROP VIEW test2;
  56. contains:cannot drop view "test2": still depended upon by view "test3b"
  57. > DROP VIEW test3b;
  58. ! DROP VIEW test1;
  59. contains:cannot drop view "test1": still depended upon by view "test2"
  60. > DROP VIEW test2;
  61. > DROP VIEW test1;
  62. # Test that CASCADE causes all dependent views to be dropped along with the
  63. # named view.
  64. > CREATE VIEW test1 AS SELECT 1;
  65. > CREATE VIEW test2 AS SELECT * FROM test1;
  66. > DROP VIEW test1 CASCADE;
  67. # TODO(benesch): when we have a system stream that has the names of all
  68. # available views, we can verify there that views are actually dropped,
  69. # rather than verifying the drop by checking whether DROP VIEW fails.
  70. ! DROP VIEW test1;
  71. contains:unknown catalog item 'test1'
  72. ! DROP VIEW test2;
  73. contains:unknown catalog item 'test2'
  74. # Test that DROP VIEW IF EXISTS succeeds even if the view does not exist.
  75. > DROP VIEW IF EXISTS test1;
  76. # Test that CASCADE causes all dependent views to be dropped along with the
  77. # named source.
  78. > CREATE VIEW test4 as SELECT * FROM s_tbl;
  79. > DROP SOURCE s CASCADE;
  80. ! DROP VIEW test4;
  81. contains:unknown catalog item 'test4'
  82. > CREATE SOURCE s
  83. IN CLUSTER ${arg.single-replica-cluster}
  84. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  85. > CREATE TABLE s_tbl FROM SOURCE s (REFERENCE "testdrive-data-${testdrive.seed}")
  86. FORMAT AVRO USING SCHEMA '${schema}'
  87. > CREATE SINK s1
  88. IN CLUSTER ${arg.single-replica-cluster}
  89. FROM s_tbl
  90. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-v-${testdrive.seed}')
  91. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  92. ENVELOPE DEBEZIUM
  93. ! CREATE SINK s1
  94. IN CLUSTER ${arg.single-replica-cluster}
  95. FROM s_tbl
  96. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-v-${testdrive.seed}')
  97. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  98. ENVELOPE DEBEZIUM
  99. contains:sink "materialize.public.s1" already exists
  100. > CREATE SINK IF NOT EXISTS s1
  101. IN CLUSTER ${arg.single-replica-cluster}
  102. FROM s_tbl
  103. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-v2-${testdrive.seed}')
  104. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  105. ENVELOPE DEBEZIUM
  106. > CREATE SINK s2
  107. IN CLUSTER ${arg.single-replica-cluster}
  108. FROM s_tbl
  109. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-v3-${testdrive.seed}')
  110. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  111. ENVELOPE DEBEZIUM
  112. # Test that sinks cannot be depended upon.
  113. ! CREATE VIEW v2 AS SELECT * FROM s1;
  114. contains:catalog item 'materialize.public.s1' is a sink and so cannot be depended upon
  115. > CREATE VIEW v2 AS SELECT X from s_tbl;
  116. > CREATE VIEW v2a AS SELECT X+1 as X from v2;
  117. > CREATE INDEX i1 ON v2(x);
  118. # Test that indexes cannot be depended upon
  119. ! CREATE VIEW v3 as SELECT * FROM i1;
  120. contains:catalog item 'materialize.public.i1' is an index and so cannot be depended upon
  121. > CREATE INDEX i2 ON v2a(x*2);
  122. > SHOW INDEXES ON v2a;
  123. name on cluster key comment
  124. ---------------------------------------------------------------------------------------
  125. i2 v2a <CLUSTER_NAME> "{x * 2}" ""
  126. > SHOW INDEXES ON v2;
  127. name on cluster key comment
  128. ------------------------------------------------------------------------------------
  129. i1 v2 <CLUSTER_NAME> {x} ""
  130. # Test that dependent indexes do not prevent view deletion when restrict is specified
  131. # but do not cause deletion of dependent views
  132. > DROP VIEW v2a;
  133. ! DROP VIEW v2a;
  134. contains:unknown catalog item 'v2a'
  135. > SHOW INDEXES ON v2;
  136. name on cluster key comment
  137. -----------------------------------------------------------------------------------
  138. i1 v2 <CLUSTER_NAME> {x} ""
  139. ! DROP INDEX i2;
  140. contains:unknown catalog item 'i2'
  141. > CREATE VIEW v4 AS SELECT x, y from s_tbl;
  142. > CREATE VIEW v4a AS SELECT y from v4;
  143. > CREATE INDEX i3 ON v4a(y);
  144. > SHOW INDEXES ON v4a;
  145. name on cluster key comment
  146. ------------------------------------------------------------------------------------
  147. i3 v4a <CLUSTER_NAME> {y} ""
  148. > CREATE INDEX i4 ON v4(x);
  149. > SHOW INDEXES ON v4;
  150. name on cluster key comment
  151. ----------------------------------------------------------------------------------
  152. i4 v4 <CLUSTER_NAME> {x} ""
  153. # Test cascade deletes associated indexes as well
  154. > DROP VIEW v4a CASCADE;
  155. ! DROP VIEW v4a;
  156. contains:unknown catalog item 'v4a'
  157. ! DROP INDEX i3;
  158. contains:unknown catalog item 'i3'
  159. > SHOW INDEXES ON v4;
  160. name on cluster key comment
  161. ----------------------------------------------------------------------------------
  162. i4 v4 <CLUSTER_NAME> {x} ""
  163. > CREATE VIEW v5 AS SELECT substr(y, 3, 2) as substr from v4;
  164. > CREATE INDEX i5 ON v5(substr);
  165. > SHOW INDEXES ON v5;
  166. name on cluster key comment
  167. ----------------------------------------------------------------------------------
  168. i5 v5 <CLUSTER_NAME> {substr} ""
  169. > CREATE VIEW multicol AS SELECT 'a' AS a, 'b' AS b, 'c' AS c, 'd' AS d
  170. > CREATE INDEX i6 ON multicol (2, a, 4)
  171. > SHOW INDEXES ON multicol
  172. name on cluster key comment
  173. -------------------------------------------------------------------------------
  174. i6 multicol <CLUSTER_NAME> {b,a,d} ""
  175. # Test cascade deletes all indexes associated with cascaded views
  176. > DROP VIEW v4 CASCADE;
  177. ! DROP VIEW v4;
  178. contains:unknown catalog item 'v4'
  179. ! DROP INDEX i5;
  180. contains:unknown catalog item 'i5'
  181. ! DROP VIEW v5;
  182. contains:unknown catalog item 'v5'
  183. ! DROP INDEX i4;
  184. contains:unknown catalog item 'i4'
  185. # Test that dropping indexes even with cascade does not cause the underlying view to be dropped
  186. > DROP INDEX i1 CASCADE;
  187. > DROP VIEW v2;
  188. > DROP TABLE s_tbl CASCADE;
  189. # Materialized source tests
  190. > CREATE SOURCE s3
  191. IN CLUSTER ${arg.single-replica-cluster}
  192. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  193. > CREATE TABLE s3_tbl FROM SOURCE s3 (REFERENCE "testdrive-data-${testdrive.seed}")
  194. FORMAT AVRO USING SCHEMA '${schema}'
  195. # Test that dependent indexes do not prevent source deletion when restrict is specified
  196. > CREATE INDEX j1 on s3_tbl(ascii(y))
  197. > SHOW INDEXES ON s3_tbl;
  198. name on cluster key comment
  199. ----------------------------------------------------------------------------------------------
  200. j1 s3_tbl <CLUSTER_NAME> "{pg_catalog.ascii(y)}" ""
  201. > DROP SOURCE s3 CASCADE;
  202. ! DROP SOURCE s3;
  203. contains:unknown catalog item 's3'
  204. ! DROP INDEX j1;
  205. contains:unknown catalog item 'j1'
  206. # Test cascade deletes all indexes associated with cascaded sources and views
  207. > CREATE SOURCE s4
  208. IN CLUSTER ${arg.single-replica-cluster}
  209. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  210. > CREATE TABLE s4_tbl FROM SOURCE s4 (REFERENCE "testdrive-data-${testdrive.seed}")
  211. FORMAT AVRO USING SCHEMA '${schema}'
  212. > CREATE INDEX j2 on s4_tbl(x+2);
  213. > CREATE VIEW w as SELECT y, x + 2 as z from s4_tbl;
  214. > CREATE INDEX j3 on w(z);
  215. > SHOW INDEXES ON s4_tbl;
  216. name on cluster key comment
  217. ------------------------------------------------------------------------------------
  218. j2 s4_tbl <CLUSTER_NAME> "{x + 2}" ""
  219. > SHOW INDEXES ON w;
  220. name on cluster key comment
  221. -----------------------------------------------------------------------------
  222. j3 w <CLUSTER_NAME> {z} ""
  223. > DROP SOURCE s4 CASCADE;
  224. ! DROP VIEW w;
  225. contains:unknown catalog item 'w'
  226. ! DROP INDEX j3;
  227. contains:unknown catalog item 'j3'
  228. ! DROP SOURCE s4;
  229. contains:unknown catalog item 's4'
  230. ! DROP INDEX j2;
  231. contains:unknown catalog item 'j2'
  232. # Test that dropping indexes even with cascade does not cause the underlying source to be dropped
  233. > CREATE SOURCE s5
  234. IN CLUSTER ${arg.single-replica-cluster}
  235. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  236. > CREATE TABLE s5_tbl FROM SOURCE s5 (REFERENCE "testdrive-data-${testdrive.seed}")
  237. FORMAT AVRO USING SCHEMA '${schema}'
  238. > CREATE DEFAULT INDEX ON s5_tbl;
  239. > DROP INDEX s5_tbl_primary_idx CASCADE;
  240. > DROP SOURCE s5 CASCADE;
  241. # https://github.com/MaterializeInc/database-issues/issues/1714
  242. > CREATE TYPE int4_list AS LIST (ELEMENT TYPE = int4)
  243. > CREATE VIEW v1 AS SELECT CAST('{2}' AS int4_list)
  244. ! DROP TYPE int4_list
  245. contains:cannot drop type "int4_list": still depended upon by view "v1"
  246. > DROP VIEW v1
  247. > CREATE TABLE t1 (custom int4_list)
  248. ! DROP TYPE int4_list
  249. contains:cannot drop type "int4_list": still depended upon by table "t1"
  250. > DROP TABLE t1
  251. > SHOW TABLES
  252. > CREATE VIEW v1 AS SELECT * FROM ( SELECT CAST('{2}' AS int4_list) )
  253. ! DROP TYPE int4_list
  254. contains:cannot drop type "int4_list": still depended upon by view "v1"
  255. > DROP VIEW v1
  256. > CREATE VIEW v1 AS SELECT CAST(CAST('{2}' AS int4_list) AS text)
  257. ! DROP TYPE int4_list
  258. contains:cannot drop type "int4_list": still depended upon by view "v1"
  259. > DROP VIEW v1
  260. > CREATE VIEW v1 AS VALUES (CAST('{2}' AS int4_list))
  261. ! DROP TYPE int4_list
  262. contains:cannot drop type "int4_list": still depended upon by view "v1"
  263. > DROP VIEW v1
  264. > CREATE VIEW v1 AS SELECT MIN(CAST(CAST('{1}' AS int4_list) AS string))
  265. ! DROP TYPE int4_list
  266. contains:cannot drop type "int4_list": still depended upon by view "v1"
  267. > DROP VIEW v1
  268. > CREATE TABLE t1 (f1 TEXT DEFAULT CAST ('{}' AS int4_list))
  269. > DROP TABLE t1
  270. > CREATE TEMPORARY TABLE t1 (f1 int4_list)
  271. ! DROP TYPE int4_list
  272. contains:cannot drop type "int4_list": still depended upon by table "t1"
  273. > DROP TABLE t1
  274. > CREATE TABLE t1 (f1 TEXT)
  275. > CREATE INDEX i1 ON t1 (CAST(f1 AS int4_list))
  276. ! DROP TYPE int4_list
  277. contains:cannot drop type "int4_list": still depended upon by index "i1"
  278. > DROP TABLE t1
  279. > CREATE TYPE int4_list_list AS LIST (ELEMENT TYPE = int4_list)
  280. ! DROP TYPE int4_list
  281. contains:cannot drop type "int4_list": still depended upon by type "int4_list_list"
  282. > DROP TYPE int4_list_list
  283. #cleanup
  284. > DROP SINK IF EXISTS s1;
  285. > DROP SINK IF EXISTS s2;
  286. > DROP SOURCE s CASCADE;
  287. # Test CREATE OR REPLACE view.
  288. > CREATE OR REPLACE VIEW v3 AS SELECT 1
  289. > SELECT * FROM v3
  290. 1
  291. > CREATE OR REPLACE VIEW v3 AS SELECT 2
  292. > SELECT * FROM v3
  293. 2
  294. > CREATE OR REPLACE VIEW v4 AS SELECT * FROM v3
  295. > SELECT * FROM v4
  296. 2
  297. ! CREATE OR REPLACE VIEW v3 AS SELECT 3
  298. contains:cannot drop view "v3": still depended upon by view "v4"
  299. > CREATE OR REPLACE VIEW v4 AS SELECT 3
  300. > SELECT * FROM v4
  301. 3
  302. > SELECT * FROM v3
  303. 2
  304. > CREATE OR REPLACE VIEW v3 AS SELECT 4
  305. > SELECT * FROM v3
  306. 4
  307. # Test CREATE VIEW IF NOT EXISTS
  308. > CREATE VIEW test1 AS SELECT 1;
  309. > CREATE VIEW test2 AS SELECT * FROM test1;
  310. ! DROP VIEW test1;
  311. contains:cannot drop view "test1": still depended upon by view "test2"
  312. # Succeeds even though it's dependent on.
  313. > CREATE VIEW IF NOT EXISTS test1 AS SELECT 2 as b;
  314. > SELECT * FROM test1;
  315. 1
  316. > DROP VIEW test2;
  317. > DROP VIEW test1;