dependencies.td 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. FORMAT AVRO USING SCHEMA '${schema}'
  35. ! CREATE SOURCE s
  36. IN CLUSTER ${arg.single-replica-cluster}
  37. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-blah-${testdrive.seed}')
  38. FORMAT AVRO USING SCHEMA '${schema}'
  39. contains:source "materialize.public.s" already exists
  40. > CREATE SOURCE IF NOT EXISTS s
  41. IN CLUSTER ${arg.single-replica-cluster}
  42. FROM KAFKA CONNECTION kafka_conn (TOPIC '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;
  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. FORMAT AVRO USING SCHEMA '${schema}'
  86. > CREATE SINK s1
  87. IN CLUSTER ${arg.single-replica-cluster}
  88. FROM s
  89. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-v-${testdrive.seed}')
  90. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  91. ENVELOPE DEBEZIUM
  92. ! CREATE SINK s1
  93. IN CLUSTER ${arg.single-replica-cluster}
  94. FROM s
  95. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-v-${testdrive.seed}')
  96. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  97. ENVELOPE DEBEZIUM
  98. contains:sink "materialize.public.s1" already exists
  99. > CREATE SINK IF NOT EXISTS s1
  100. IN CLUSTER ${arg.single-replica-cluster}
  101. FROM s
  102. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-v2-${testdrive.seed}')
  103. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  104. ENVELOPE DEBEZIUM
  105. > CREATE SINK s2
  106. IN CLUSTER ${arg.single-replica-cluster}
  107. FROM s
  108. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-v3-${testdrive.seed}')
  109. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  110. ENVELOPE DEBEZIUM
  111. # Test that sinks cannot be depended upon.
  112. ! CREATE VIEW v2 AS SELECT * FROM s1;
  113. contains:catalog item 'materialize.public.s1' is a sink and so cannot be depended upon
  114. > CREATE VIEW v2 AS SELECT X from s;
  115. > CREATE VIEW v2a AS SELECT X+1 as X from v2;
  116. > CREATE INDEX i1 ON v2(x);
  117. # Test that indexes cannot be depended upon
  118. ! CREATE VIEW v3 as SELECT * FROM i1;
  119. contains:catalog item 'materialize.public.i1' is an index and so cannot be depended upon
  120. > CREATE INDEX i2 ON v2a(x*2);
  121. > SHOW INDEXES ON v2a;
  122. name on cluster key comment
  123. ---------------------------------------------------------------------------------------
  124. i2 v2a <CLUSTER_NAME> "{x * 2}" ""
  125. > SHOW INDEXES ON v2;
  126. name on cluster key comment
  127. ------------------------------------------------------------------------------------
  128. i1 v2 <CLUSTER_NAME> {x} ""
  129. # Test that dependent indexes do not prevent view deletion when restrict is specified
  130. # but do not cause deletion of dependent views
  131. > DROP VIEW v2a;
  132. ! DROP VIEW v2a;
  133. contains:unknown catalog item 'v2a'
  134. > SHOW INDEXES ON v2;
  135. name on cluster key comment
  136. -----------------------------------------------------------------------------------
  137. i1 v2 <CLUSTER_NAME> {x} ""
  138. ! DROP INDEX i2;
  139. contains:unknown catalog item 'i2'
  140. > CREATE VIEW v4 AS SELECT x, y from s;
  141. > CREATE VIEW v4a AS SELECT y from v4;
  142. > CREATE INDEX i3 ON v4a(y);
  143. > SHOW INDEXES ON v4a;
  144. name on cluster key comment
  145. ------------------------------------------------------------------------------------
  146. i3 v4a <CLUSTER_NAME> {y} ""
  147. > CREATE INDEX i4 ON v4(x);
  148. > SHOW INDEXES ON v4;
  149. name on cluster key comment
  150. ----------------------------------------------------------------------------------
  151. i4 v4 <CLUSTER_NAME> {x} ""
  152. # Test cascade deletes associated indexes as well
  153. > DROP VIEW v4a CASCADE;
  154. ! DROP VIEW v4a;
  155. contains:unknown catalog item 'v4a'
  156. ! DROP INDEX i3;
  157. contains:unknown catalog item 'i3'
  158. > SHOW INDEXES ON v4;
  159. name on cluster key comment
  160. ----------------------------------------------------------------------------------
  161. i4 v4 <CLUSTER_NAME> {x} ""
  162. > CREATE VIEW v5 AS SELECT substr(y, 3, 2) as substr from v4;
  163. > CREATE INDEX i5 ON v5(substr);
  164. > SHOW INDEXES ON v5;
  165. name on cluster key comment
  166. ----------------------------------------------------------------------------------
  167. i5 v5 <CLUSTER_NAME> {substr} ""
  168. > CREATE VIEW multicol AS SELECT 'a' AS a, 'b' AS b, 'c' AS c, 'd' AS d
  169. > CREATE INDEX i6 ON multicol (2, a, 4)
  170. > SHOW INDEXES ON multicol
  171. name on cluster key comment
  172. -------------------------------------------------------------------------------
  173. i6 multicol <CLUSTER_NAME> {b,a,d} ""
  174. # Test cascade deletes all indexes associated with cascaded views
  175. > DROP VIEW v4 CASCADE;
  176. ! DROP VIEW v4;
  177. contains:unknown catalog item 'v4'
  178. ! DROP INDEX i5;
  179. contains:unknown catalog item 'i5'
  180. ! DROP VIEW v5;
  181. contains:unknown catalog item 'v5'
  182. ! DROP INDEX i4;
  183. contains:unknown catalog item 'i4'
  184. # Test that dropping indexes even with cascade does not cause the underlying view to be dropped
  185. > DROP INDEX i1 CASCADE;
  186. > DROP VIEW v2;
  187. # Materialized source tests
  188. > CREATE SOURCE s3
  189. IN CLUSTER ${arg.single-replica-cluster}
  190. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  191. FORMAT AVRO USING SCHEMA '${schema}'
  192. # Test that dependent indexes do not prevent source deletion when restrict is specified
  193. > CREATE INDEX j1 on s3(ascii(y))
  194. > SHOW INDEXES ON s3;
  195. name on cluster key comment
  196. ----------------------------------------------------------------------------------------------
  197. j1 s3 <CLUSTER_NAME> "{pg_catalog.ascii(y)}" ""
  198. > DROP SOURCE s3 CASCADE;
  199. ! DROP SOURCE s3;
  200. contains:unknown catalog item 's3'
  201. ! DROP INDEX j1;
  202. contains:unknown catalog item 'j1'
  203. # Test cascade deletes all indexes associated with cascaded sources and views
  204. > CREATE SOURCE s4
  205. IN CLUSTER ${arg.single-replica-cluster}
  206. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  207. FORMAT AVRO USING SCHEMA '${schema}'
  208. > CREATE INDEX j2 on s4(x+2);
  209. > CREATE VIEW w as SELECT y, x + 2 as z from s4;
  210. > CREATE INDEX j3 on w(z);
  211. > SHOW INDEXES ON s4;
  212. name on cluster key comment
  213. ------------------------------------------------------------------------------------
  214. j2 s4 <CLUSTER_NAME> "{x + 2}" ""
  215. > SHOW INDEXES ON w;
  216. name on cluster key comment
  217. -----------------------------------------------------------------------------
  218. j3 w <CLUSTER_NAME> {z} ""
  219. > DROP SOURCE s4 CASCADE;
  220. ! DROP VIEW w;
  221. contains:unknown catalog item 'w'
  222. ! DROP INDEX j3;
  223. contains:unknown catalog item 'j3'
  224. ! DROP SOURCE s4;
  225. contains:unknown catalog item 's4'
  226. ! DROP INDEX j2;
  227. contains:unknown catalog item 'j2'
  228. # Test that dropping indexes even with cascade does not cause the underlying source to be dropped
  229. > CREATE SOURCE s5
  230. IN CLUSTER ${arg.single-replica-cluster}
  231. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  232. FORMAT AVRO USING SCHEMA '${schema}'
  233. > CREATE DEFAULT INDEX ON s5;
  234. > DROP INDEX s5_primary_idx CASCADE;
  235. > DROP SOURCE s5 CASCADE;
  236. # https://github.com/MaterializeInc/database-issues/issues/1714
  237. > CREATE TYPE int4_list AS LIST (ELEMENT TYPE = int4)
  238. > CREATE VIEW v1 AS SELECT CAST('{2}' AS int4_list)
  239. ! DROP TYPE int4_list
  240. contains:cannot drop type "int4_list": still depended upon by view "v1"
  241. > DROP VIEW v1
  242. > CREATE TABLE t1 (custom int4_list)
  243. ! DROP TYPE int4_list
  244. contains:cannot drop type "int4_list": still depended upon by table "t1"
  245. > DROP TABLE t1
  246. > SHOW TABLES
  247. > CREATE VIEW v1 AS SELECT * FROM ( SELECT CAST('{2}' AS int4_list) )
  248. ! DROP TYPE int4_list
  249. contains:cannot drop type "int4_list": still depended upon by view "v1"
  250. > DROP VIEW v1
  251. > CREATE VIEW v1 AS SELECT CAST(CAST('{2}' AS int4_list) AS text)
  252. ! DROP TYPE int4_list
  253. contains:cannot drop type "int4_list": still depended upon by view "v1"
  254. > DROP VIEW v1
  255. > CREATE VIEW v1 AS VALUES (CAST('{2}' AS int4_list))
  256. ! DROP TYPE int4_list
  257. contains:cannot drop type "int4_list": still depended upon by view "v1"
  258. > DROP VIEW v1
  259. > CREATE VIEW v1 AS SELECT MIN(CAST(CAST('{1}' AS int4_list) AS string))
  260. ! DROP TYPE int4_list
  261. contains:cannot drop type "int4_list": still depended upon by view "v1"
  262. > DROP VIEW v1
  263. > CREATE TABLE t1 (f1 TEXT DEFAULT CAST ('{}' AS int4_list))
  264. > DROP TABLE t1
  265. > CREATE TEMPORARY TABLE t1 (f1 int4_list)
  266. ! DROP TYPE int4_list
  267. contains:cannot drop type "int4_list": still depended upon by table "t1"
  268. > DROP TABLE t1
  269. > CREATE TABLE t1 (f1 TEXT)
  270. > CREATE INDEX i1 ON t1 (CAST(f1 AS int4_list))
  271. ! DROP TYPE int4_list
  272. contains:cannot drop type "int4_list": still depended upon by index "i1"
  273. > DROP TABLE t1
  274. > CREATE TYPE int4_list_list AS LIST (ELEMENT TYPE = int4_list)
  275. ! DROP TYPE int4_list
  276. contains:cannot drop type "int4_list": still depended upon by type "int4_list_list"
  277. > DROP TYPE int4_list_list
  278. #cleanup
  279. > DROP SINK s1;
  280. > DROP SINK s2;
  281. > DROP SOURCE s CASCADE;
  282. # Test CREATE OR REPLACE view.
  283. > CREATE OR REPLACE VIEW v3 AS SELECT 1
  284. > SELECT * FROM v3
  285. 1
  286. > CREATE OR REPLACE VIEW v3 AS SELECT 2
  287. > SELECT * FROM v3
  288. 2
  289. > CREATE OR REPLACE VIEW v4 AS SELECT * FROM v3
  290. > SELECT * FROM v4
  291. 2
  292. ! CREATE OR REPLACE VIEW v3 AS SELECT 3
  293. contains:cannot drop view "v3": still depended upon by view "v4"
  294. > CREATE OR REPLACE VIEW v4 AS SELECT 3
  295. > SELECT * FROM v4
  296. 3
  297. > SELECT * FROM v3
  298. 2
  299. > CREATE OR REPLACE VIEW v3 AS SELECT 4
  300. > SELECT * FROM v3
  301. 4
  302. # Test CREATE VIEW IF NOT EXISTS
  303. > CREATE VIEW test1 AS SELECT 1;
  304. > CREATE VIEW test2 AS SELECT * FROM test1;
  305. ! DROP VIEW test1;
  306. contains:cannot drop view "test1": still depended upon by view "test2"
  307. # Succeeds even though it's dependent on.
  308. > CREATE VIEW IF NOT EXISTS test1 AS SELECT 2 as b;
  309. > SELECT * FROM test1;
  310. 1
  311. > DROP VIEW test2;
  312. > DROP VIEW test1;