createdrop.td 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #
  11. # Test basic create and drop functionality
  12. $ set schema={
  13. "name": "row",
  14. "type": "record",
  15. "fields": [
  16. {"name": "X", "type": "long"},
  17. {"name": "Y", "type": "long"}
  18. ]
  19. }
  20. $ kafka-create-topic topic=data
  21. > CREATE CONNECTION kafka_conn
  22. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  23. > CREATE SOURCE s
  24. IN CLUSTER ${arg.single-replica-cluster}
  25. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  26. FORMAT AVRO USING SCHEMA '${schema}'
  27. $ kafka-ingest format=avro topic=data schema=${schema}
  28. {"X": 1, "Y": 1}
  29. {"X": 2, "Y": 1}
  30. {"X": 3, "Y": 1}
  31. {"X": 1, "Y": 2}
  32. > CREATE MATERIALIZED VIEW v AS SELECT 42 AS a
  33. > CREATE MATERIALIZED VIEW v2 AS SELECT 0 AS x
  34. > CREATE INDEX i ON v(a)
  35. > CREATE INDEX j on s("X");
  36. # Test that creating objects of the same name does not work
  37. ! CREATE MATERIALIZED VIEW i AS SELECT 1.5 AS c
  38. contains:index "materialize.public.i" already exists
  39. ! CREATE INDEX i ON s("Y")
  40. contains:index "materialize.public.i" already exists
  41. ! CREATE INDEX j on v2(x)
  42. contains:index "materialize.public.j" already exists
  43. ! CREATE INDEX v ON v2(x)
  44. contains:materialized view "materialize.public.v" already exists
  45. $ set dummy={
  46. "type": "record",
  47. "name": "envelope",
  48. "fields": [
  49. {
  50. "name": "before",
  51. "type": [
  52. {
  53. "name": "row",
  54. "type": "record",
  55. "fields": [
  56. {"name": "X",
  57. "type": {
  58. "type": "bytes",
  59. "scale": 3,
  60. "precision": 10,
  61. "logicalType": "decimal"
  62. }}
  63. ]
  64. },
  65. "null"
  66. ]
  67. },
  68. { "name": "after", "type": ["row", "null"] }
  69. ]
  70. }
  71. ! CREATE SOURCE v2
  72. IN CLUSTER ${arg.single-replica-cluster}
  73. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  74. FORMAT AVRO USING SCHEMA '${dummy}'
  75. contains:materialized view "materialize.public.v2" already exists
  76. ! CREATE SOURCE i
  77. IN CLUSTER ${arg.single-replica-cluster}
  78. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  79. FORMAT AVRO USING SCHEMA '${dummy}'
  80. contains:index "materialize.public.i" already exists
  81. ! CREATE INDEX s ON v2(x)
  82. contains:source "materialize.public.s" already exists
  83. ! CREATE MATERIALIZED VIEW s AS SELECT 'bloop' AS d
  84. contains:source "materialize.public.s" already exists
  85. # Test that objects do not get dropped if the drop command does not specify the correct type
  86. ! DROP SOURCE v
  87. exact:v is a materialized view not a source
  88. ! DROP SOURCE IF EXISTS v
  89. exact:v is a materialized view not a source
  90. ! DROP INDEX v
  91. exact:v is a materialized view not an index
  92. ! DROP INDEX IF EXISTS v
  93. exact:v is a materialized view not an index
  94. ! DROP SOURCE i
  95. exact:i is an index not a source
  96. ! DROP SOURCE IF EXISTS i
  97. exact:i is an index not a source
  98. ! DROP VIEW i
  99. exact:i is an index not a view
  100. ! DROP VIEW IF EXISTS i
  101. exact:i is an index not a view
  102. ! DROP INDEX s
  103. exact:s is a source not an index
  104. ! DROP INDEX IF EXISTS s
  105. exact:s is a source not an index
  106. ! DROP VIEW s
  107. exact:s is a source not a view
  108. ! DROP VIEW IF EXISTS s
  109. exact:s is a source not a view
  110. # Delete objects
  111. > DROP INDEX j
  112. > DROP INDEX i
  113. > DROP MATERIALIZED VIEW v
  114. > DROP SOURCE s CASCADE
  115. # test that the names of the deleted objects can be used to create objects of other types
  116. > CREATE MATERIALIZED VIEW s AS SELECT 84 AS b
  117. > CREATE SOURCE i
  118. IN CLUSTER ${arg.single-replica-cluster}
  119. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  120. FORMAT AVRO USING SCHEMA '${schema}'
  121. > CREATE INDEX v ON s(b)
  122. # Test that if exists works when the referred objects exist
  123. > DROP INDEX IF EXISTS v
  124. > DROP MATERIALIZED VIEW IF EXISTS s
  125. > DROP SOURCE IF EXISTS i CASCADE
  126. # Test that if exists works when the referred objects do not exist
  127. > DROP INDEX IF EXISTS nonexistent
  128. > DROP VIEW IF EXISTS nonexistent
  129. > DROP SOURCE IF EXISTS nonexistent CASCADE
  130. # Test that drop without if exists does not work if the object does not exist
  131. ! DROP INDEX nonexistent
  132. contains:unknown catalog item 'nonexistent'
  133. ! DROP VIEW nonexistent
  134. contains:unknown catalog item 'nonexistent'
  135. ! DROP SOURCE nonexistent
  136. contains:unknown catalog item 'nonexistent'
  137. # Test CREATE VIEW IF NOT EXISTS
  138. > CREATE VIEW IF NOT EXISTS test1 AS SELECT 42 AS a
  139. ! CREATE VIEW test1 AS SELECT 43 AS b
  140. contains:view "materialize.public.test1" already exists
  141. > SELECT * FROM test1
  142. a
  143. -----------
  144. 42
  145. > CREATE VIEW IF NOT EXISTS test1 AS SELECT 42 AS a
  146. > DROP VIEW test1