ct_various.slt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. mode cockroach
  10. statement ok
  11. CREATE TABLE input (key INT)
  12. statement ok
  13. CREATE CONTINUAL TASK ct (key INT) ON INPUT input AS (
  14. INSERT INTO ct SELECT * FROM input;
  15. )
  16. statement ok
  17. COMMENT ON CONTINUAL TASK ct IS 'foo'
  18. query TTT
  19. SHOW CONTINUAL TASKS;
  20. ----
  21. ct quickstart foo
  22. # Creating in other databases/schemas
  23. statement ok
  24. CREATE SCHEMA x
  25. statement ok
  26. CREATE DATABASE y
  27. statement ok
  28. CREATE SCHEMA y.z
  29. statement ok
  30. CREATE CONTINUAL TASK x.ct (key INT) ON INPUT input AS (
  31. INSERT INTO x.ct SELECT * FROM input;
  32. )
  33. statement ok
  34. CREATE CONTINUAL TASK y.z.ct (key INT) ON INPUT input AS (
  35. INSERT INTO y.z.ct SELECT i.key FROM input i JOIN x.ct x_ct ON i.key = x_ct.key;
  36. )
  37. statement ok
  38. INSERT INTO input VALUES (1);
  39. query T
  40. SELECT * FROM x.ct;
  41. ----
  42. 1
  43. query T
  44. SELECT * FROM y.z.ct;
  45. ----
  46. 1
  47. # Crazy names
  48. statement ok
  49. CREATE DATABASE "--";
  50. statement ok
  51. CREATE SCHEMA "--"."</script><script>alert(123)</script>";
  52. statement ok
  53. CREATE TABLE "--"."</script><script>alert(123)</script>"."1;DROP TABLE users" (count int);
  54. statement ok
  55. INSERT INTO "--"."</script><script>alert(123)</script>"."1;DROP TABLE users" VALUES (1);
  56. statement ok
  57. CREATE CONTINUAL TASK "--"."</script><script>alert(123)</script>"."┬─┬ノ( º _ ºノ)"
  58. FROM TRANSFORM "--"."</script><script>alert(123)</script>"."1;DROP TABLE users"
  59. USING (SELECT MAX(COUNT) FROM "--"."</script><script>alert(123)</script>"."1;DROP TABLE users");
  60. query T
  61. SELECT * FROM "--"."</script><script>alert(123)</script>"."┬─┬ノ( º _ ºノ)";
  62. ----
  63. 1
  64. # Regression test for a bug where we'd panic if no CT inputs were referenced.
  65. statement ok
  66. CREATE CONTINUAL TASK no_input_refs (key INT) ON INPUT input AS (
  67. INSERT INTO no_input_refs SELECT null::INT
  68. )
  69. query I
  70. SELECT * FROM no_input_refs;
  71. ----
  72. # INSERT will put in a cast if necessary
  73. statement ok
  74. CREATE CONTINUAL TASK cast_int_to_string (key STRING) ON INPUT input AS (
  75. INSERT INTO cast_int_to_string SELECT * FROM input WHERE key > 1;
  76. )
  77. statement ok
  78. INSERT INTO input VALUES (2);
  79. query T
  80. SELECT * FROM cast_int_to_string;
  81. ----
  82. 2
  83. # Regression test for a bug where we'd incorrectly optimize (and panic at
  84. # runtime) a CT with a monotonic input.
  85. statement ok
  86. CREATE SOURCE counter FROM LOAD GENERATOR COUNTER
  87. statement ok
  88. CREATE CONTINUAL TASK input_not_monotonic FROM TRANSFORM counter USING
  89. (SELECT max(counter) FROM counter)
  90. # Give the load generator time to produce some data.
  91. statement ok
  92. SELECT mz_unsafe.mz_sleep(3)
  93. # Ensure that we don't get a "monotonic reduction on non-monotonic input" error
  94. query T
  95. SELECT COUNT(*) > 0 FROM input_not_monotonic;
  96. ----
  97. true
  98. # Regression test for a bug where the TRANSFORM USING sugar did not roundtrip
  99. # the cluster through the catalog's `create_sql`.
  100. statement ok
  101. CREATE CLUSTER c2 SIZE '1'
  102. statement ok
  103. SET CLUSTER TO c2
  104. statement ok
  105. CREATE CONTINUAL TASK ct_c2 FROM TRANSFORM input USING (SELECT * FROM input)
  106. query T
  107. SELECT * FROM ct_c2
  108. ----
  109. 1
  110. 2
  111. # Confirm that the catalog knows the ct is in the right cluster.
  112. statement error cannot drop cluster "c2" because other objects depend on it
  113. DROP CLUSTER c2;
  114. # Regression test for constant MV (upper of empty antichain). The dataflow
  115. # previously hung at runtime.
  116. statement ok
  117. CREATE MATERIALIZED VIEW mv_const AS SELECT 1 AS value
  118. statement ok
  119. CREATE CONTINUAL TASK ct_const_mv FROM TRANSFORM mv_const USING (SELECT MIN(value) FROM mv_const)
  120. query T
  121. SELECT * FROM ct_const_mv
  122. ----
  123. 1