exec_window.slt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/exec_window
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. # not supported yet
  20. halt
  21. mode cockroach
  22. statement ok
  23. CREATE TABLE t (a INT, b STRING, PRIMARY KEY (b,a))
  24. statement ok
  25. INSERT INTO t VALUES
  26. (0, 'a'),
  27. (1, 'a'),
  28. (0, 'b'),
  29. (1, 'b')
  30. # We sort the output on all queries to get deterministic results.
  31. query ITI
  32. SELECT a, b, row_number() OVER () FROM t ORDER BY b, a
  33. ----
  34. 0 a 1
  35. 1 a 2
  36. 0 b 3
  37. 1 b 4
  38. query ITI
  39. SELECT a, b, row_number() OVER (ORDER BY a, b) FROM t ORDER BY b, a
  40. ----
  41. 0 a 1
  42. 1 a 3
  43. 0 b 2
  44. 1 b 4
  45. query ITI
  46. SELECT a, b, row_number() OVER (PARTITION BY a) FROM t ORDER BY b, a
  47. ----
  48. 0 a 1
  49. 1 a 1
  50. 0 b 2
  51. 1 b 2
  52. query ITI
  53. SELECT a, b, row_number() OVER (PARTITION BY a, b) FROM t ORDER BY b, a
  54. ----
  55. 0 a 1
  56. 1 a 1
  57. 0 b 1
  58. 1 b 1
  59. query ITI
  60. SELECT a, b, rank() OVER () FROM t ORDER BY b, a
  61. ----
  62. 0 a 1
  63. 1 a 1
  64. 0 b 1
  65. 1 b 1
  66. query ITI
  67. SELECT a, b, rank() OVER (ORDER BY a) FROM t ORDER BY b, a
  68. ----
  69. 0 a 1
  70. 1 a 3
  71. 0 b 1
  72. 1 b 3
  73. query ITI
  74. SELECT a, b, rank() OVER (PARTITION BY a ORDER BY b) FROM t ORDER BY b, a
  75. ----
  76. 0 a 1
  77. 1 a 1
  78. 0 b 2
  79. 1 b 2
  80. query ITI
  81. SELECT a, b, dense_rank() OVER () FROM t ORDER BY b, a
  82. ----
  83. 0 a 1
  84. 1 a 1
  85. 0 b 1
  86. 1 b 1
  87. query ITI
  88. SELECT a, b, dense_rank() OVER (ORDER BY a) FROM t ORDER BY b, a
  89. ----
  90. 0 a 1
  91. 1 a 2
  92. 0 b 1
  93. 1 b 2
  94. query ITI
  95. SELECT a, b, dense_rank() OVER (PARTITION BY a ORDER BY b) FROM t ORDER BY b, a
  96. ----
  97. 0 a 1
  98. 1 a 1
  99. 0 b 2
  100. 1 b 2