temporary.td 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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-regex match=cluster1|quickstart replacement=<CLUSTER_NAME>
  10. > CREATE VIEW v AS VALUES (1, 'foo'), (2, 'bar'), (3, 'foo'), (1, 'bar')
  11. > SELECT * FROM v
  12. 1 "foo"
  13. 1 "bar"
  14. 2 "bar"
  15. 3 "foo"
  16. > CREATE TEMPORARY VIEW temp_v AS SELECT * FROM v
  17. > SELECT * FROM temp_v
  18. 1 "foo"
  19. 1 "bar"
  20. 2 "bar"
  21. 3 "foo"
  22. > SELECT * FROM mz_temp.temp_v
  23. 1 "foo"
  24. 1 "bar"
  25. 2 "bar"
  26. 3 "foo"
  27. ! CREATE VIEW non_temp AS SELECT * FROM temp_v
  28. contains:non-temporary items cannot depend on temporary item
  29. > CREATE TEMP VIEW double_temp_v AS SELECT * FROM temp_v
  30. ! CREATE TEMP VIEW double_temp_v AS SELECT * FROM temp_v
  31. contains:view "mz_temp.double_temp_v" already exists
  32. > CREATE OR REPLACE TEMP VIEW double_temp_v AS SELECT * FROM temp_v
  33. ! CREATE OR REPLACE VIEW double_temp_v AS SELECT * FROM temp_v
  34. contains:non-temporary items cannot depend on temporary item
  35. > SELECT * FROM double_temp_v
  36. 1 "foo"
  37. 1 "bar"
  38. 2 "bar"
  39. 3 "foo"
  40. > SELECT * FROM mz_temp.double_temp_v
  41. 1 "foo"
  42. 1 "bar"
  43. 2 "bar"
  44. 3 "foo"
  45. # A temporary view should mask a normal view with the same name
  46. > CREATE VIEW v1 AS SELECT 1 AS f1;
  47. > CREATE TEMPORARY VIEW v1 AS SELECT 2 AS f2;
  48. > SELECT * FROM v1;
  49. f2
  50. ----
  51. 2
  52. > DROP VIEW v1;
  53. > SELECT * FROM v1;
  54. f1
  55. ----
  56. 1
  57. > DROP VIEW v1;
  58. ! SELECT * FROM v1;
  59. contains:unknown catalog item 'v1'
  60. # Rename temporary view
  61. > CREATE TEMPORARY VIEW v1 AS SELECT 1 AS f1;
  62. > ALTER VIEW v1 RENAME TO v2;
  63. ! SELECT * FROM v1;
  64. contains:unknown catalog item 'v1'
  65. > SELECT * FROM v2;
  66. f1
  67. ----
  68. 1
  69. > DROP VIEW v2;
  70. #####################################################################
  71. # Temporary tables
  72. > CREATE TEMPORARY TABLE temp_t (a int, b text NOT NULL)
  73. ! CREATE TEMP TABLE temp_t (a int, b text NOT NULL)
  74. contains:table "mz_temp.temp_t" already exists
  75. > INSERT INTO temp_t VALUES (1, 'testing')
  76. > SHOW INDEXES ON temp_t
  77. # Blocked on https://github.com/MaterializeInc/database-issues/issues/1017.
  78. #
  79. # > CREATE TEMPORARY DEFAULT INDEX ON temp_t
  80. #
  81. # > SHOW INDEXES ON temp_t
  82. # on_name key_name seq_in_index column_name expression nullable
  83. # name on cluster key
  84. # --------------------------------------------------------------------------------
  85. # temp_t_primary_idx d quickstart {a, b}
  86. > DROP TABLE temp_t
  87. # A temporary table should mask a normal table with the same name
  88. > CREATE TABLE t1 (f1 INTEGER);
  89. > INSERT INTO t1 VALUES (1);
  90. > CREATE TEMPORARY TABLE t1 (f2 INTEGER);
  91. > INSERT INTO t1 VALUES (2);
  92. > SELECT * FROM t1;
  93. f2
  94. ----
  95. 2
  96. > SELECT * FROM public.t1;
  97. f1
  98. ----
  99. 1
  100. > DROP TABLE t1;
  101. > SELECT * FROM t1;
  102. f1
  103. ----
  104. 1
  105. > DROP TABLE t1;
  106. # Rename temporary table
  107. > CREATE TEMPORARY TABLE t1 (f1 INTEGER);
  108. > INSERT INTO t1 VALUES (1);
  109. > ALTER TABLE t1 RENAME TO t2;
  110. ! SELECT * FROM t1;
  111. contains:unknown catalog item 't1'
  112. > SELECT * FROM t2;
  113. f1
  114. ----
  115. 1
  116. > DROP TABLE t2;
  117. # A non-temporary view can not depend on a temporary table
  118. > CREATE TEMPORARY TABLE t1 (f1 INTEGER);
  119. ! CREATE VIEW non_temp AS SELECT * FROM t1;
  120. contains:non-temporary items cannot depend on temporary item
  121. ! CREATE VIEW non_temp AS SELECT (SELECT * FROM t1);
  122. contains:non-temporary items cannot depend on temporary item
  123. > DROP TABLE t1;
  124. #####################################################################
  125. # Make sure the mz_temp schema is protected
  126. ! DROP SCHEMA mz_temp
  127. contains:cannot drop schema mz_temp because it is required by the database system
  128. ! CREATE TABLE mz_temp.table_in_mz_temp (f1 INTEGER)
  129. contains:unknown schema 'mz_temp'
  130. #####################################################################
  131. # Test things we shouldn't be able to make temporary.
  132. ##### Temporary sources.
  133. $ set schema={
  134. "type": "record",
  135. "name": "envelope",
  136. "fields": [{},]
  137. }
  138. > CREATE CONNECTION kafka_conn
  139. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  140. ! CREATE TEMPORARY SOURCE data_schema_inline
  141. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-data-${testdrive.seed}')
  142. FORMAT AVRO USING SCHEMA '${schema}'
  143. ENVELOPE DEBEZIUM
  144. contains:Expected TABLE, or VIEW after CREATE TEMPORARY, found SOURCE
  145. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  146. URL '${testdrive.schema-registry-url}'
  147. );
  148. ##### Temporary sinks.
  149. ! CREATE TEMPORARY SINK data_sink FROM data
  150. INTO KAFKA BROKER '${testdrive.kafka-addr}' TOPIC 'testdrive-data-sink-${testdrive.seed}'
  151. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  152. contains:Expected TABLE, or VIEW after CREATE TEMPORARY, found SINK
  153. #####################################################################
  154. ! DROP VIEW temp_v;
  155. contains:cannot drop view "temp_v": still depended upon by view "double_temp_v"
  156. > DROP VIEW double_temp_v;
  157. ! SELECT * FROM double_temp_v;
  158. contains:unknown catalog item 'double_temp_v'
  159. > DISCARD TEMP
  160. > SELECT * FROM mz_indexes WHERE name = 'foo_primary_idx'
  161. > SELECT * FROM mz_indexes WHERE name = 'temp_t_primary_idx'
  162. ! SELECT * FROM temp_v;
  163. contains:unknown catalog item 'temp_v'
  164. ! CREATE TEMP VIEW mz_catalog.a AS SELECT 1
  165. contains:cannot create temporary item in non-temporary schema