as_of.slt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 VIEW data (a, b) AS VALUES (1, 1), (2, 1), (3, 1), (1, 2)
  12. # Don't parse 'AS OF' as a table alias.
  13. statement error Expected a timestamp value after 'AS OF', found EOF
  14. SELECT * FROM data AS OF;
  15. query II
  16. SELECT * FROM data
  17. ----
  18. 1 1
  19. 1 2
  20. 2 1
  21. 3 1
  22. query error cannot call current_timestamp in AS OF
  23. SELECT * FROM data AS OF now()
  24. query II
  25. SELECT * FROM data ORDER BY a, b AS OF AT LEAST 1
  26. ----
  27. 1 1
  28. 1 2
  29. 2 1
  30. 3 1
  31. # This previously would panic on an internal conversion from numeric to
  32. # primitive int
  33. query II
  34. SELECT * FROM data AS OF 192741824E4::numeric;
  35. ----
  36. 1 1
  37. 1 2
  38. 2 1
  39. 3 1
  40. query error out of range integral type conversion attempted
  41. SELECT * FROM data AS OF -1;
  42. query error decimal cannot be expressed in target primitive type
  43. SELECT * FROM data AS OF -1::numeric;
  44. query error decimal cannot be expressed in target primitive type
  45. SELECT * FROM data AS OF 1E38;
  46. query error decimal cannot be expressed in target primitive type
  47. SELECT * FROM data AS OF 1.2;
  48. query error cannot call mz_now in AS OF
  49. SELECT * FROM data AS OF mz_now();
  50. statement ok
  51. CREATE TABLE t (i INT);
  52. statement ok
  53. CREATE DEFAULT INDEX ON t;
  54. statement ok
  55. INSERT INTO t VALUES (1);
  56. query I
  57. SELECT * FROM t;
  58. ----
  59. 1
  60. query error Timestamp \(1\) is not valid for all inputs
  61. SELECT * FROM t AS OF 1
  62. # AS OF escapes linearizability, so this could choose a timestamp before the INSERT. We're just
  63. # testing that we can type AS OF AT LEAST 1. Use a query that has the same output regardless of chosen
  64. # timestamp.
  65. query B
  66. SELECT count(*) = 2 FROM t AS OF AT LEAST 1
  67. ----
  68. false
  69. query error can't use null as a mz_timestamp for AS OF
  70. SELECT 1 AS OF NULL::timestamp;
  71. query error can't use null as a mz_timestamp for AS OF
  72. SELECT * FROM data AS OF NULL::numeric;
  73. query error can't use null as a mz_timestamp for AS OF
  74. SUBSCRIBE (SELECT 1) AS OF NULL::timestamptz;
  75. # Test that timestamps are used for constant queries with temporal filters
  76. statement ok
  77. create view events_over_time as values ('joe', 100), ('mike', 101), ('sam', 200), ('end', 18446744073709551615);
  78. statement ok
  79. create view events as select * from events_over_time where mz_now() >= column2;
  80. statement ok
  81. BEGIN
  82. statement ok
  83. DECLARE c CURSOR FOR SUBSCRIBE events AS OF 0
  84. query IITI
  85. FETCH ALL c
  86. ----
  87. 100 1 joe 100
  88. 101 1 mike 101
  89. 200 1 sam 200
  90. 18446744073709551615 1 end 18446744073709551615
  91. statement ok
  92. COMMIT
  93. query TI
  94. SELECT * FROM events AS OF 0
  95. ----
  96. query TI
  97. SELECT * FROM events AS OF 100
  98. ----
  99. joe 100
  100. query TI
  101. SELECT * FROM events AS OF 101
  102. ----
  103. joe 100
  104. mike 101
  105. statement ok
  106. BEGIN
  107. statement ok
  108. DECLARE c CURSOR FOR SUBSCRIBE (SELECT 1) AS OF 42
  109. # TODO(jkosh44) It's not entirely clear what the answer to this should be.
  110. query III
  111. FETCH ALL c
  112. ----
  113. 18446744073709551615 1 1
  114. statement ok
  115. COMMIT
  116. statement ok
  117. BEGIN
  118. statement ok
  119. DECLARE c CURSOR FOR SUBSCRIBE (SELECT 1)
  120. query III
  121. FETCH ALL c
  122. ----
  123. 18446744073709551615 1 1
  124. statement ok
  125. COMMIT