StarRocks / starrocks

StarRocks, a Linux Foundation project, is a next-generation sub-second MPP OLAP database for full analytics scenarios, including multi-dimensional analytics, real-time analytics, and ad-hoc queries.
https://starrocks.io
Apache License 2.0
8.67k stars 1.75k forks source link

[Bug] Range window function result error #7318

Closed liuyehcf closed 2 years ago

liuyehcf commented 2 years ago

Steps to reproduce the behavior (Required)

CREATE DATABASE IF NOT EXISTS `analytic`;
DROP TABLE IF EXISTS `analytic`.`t0`;
CREATE TABLE IF NOT EXISTS `analytic`.`t0` (
  `v1` int(11) NOT NULL,
  `v2` int(11) NOT NULL,
  `v3` int(11) NOT NULL
) ENGINE=OLAP
DUPLICATE KEY(`v1`)
DISTRIBUTED BY HASH(`v1`) BUCKETS 10
PROPERTIES (
 "replication_num" = "1"
);

INSERT INTO `analytic`.`t0` (v1, v2, v3) values
    (1, 1, 1),
    (1, 1, 2),
    (1, 1, 3),
    (1, 2, 4),
    (1, 2, 5),
    (1, 2, 6),
    (2, 3, 7),
    (2, 3, 8),
    (2, 3, 9),
    (2, 4, 10),
    (2, 4, 11),
    (2, 4, 12);

SELECT AVG(v1) OVER (ORDER BY v2 RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) AS wv, v1, v2 FROM analytic.t0 ORDER BY v2;

Expected behavior (Required)

+-----+----+----+
| wv  | v1 | v2 |
+-----+----+----+
| 1.0 | 1  | 1  |
| 1.0 | 1  | 1  |
| 1.0 | 1  | 1  |
| 1.0 | 1  | 2  |
| 1.0 | 1  | 2  |
| 1.0 | 1  | 2  |
| 1.5 | 2  | 3  |
| 1.5 | 2  | 3  |
| 1.5 | 2  | 3  |
| 1.5 | 2  | 4  |
| 1.5 | 2  | 4  |
| 1.5 | 2  | 4  |
+-----+----+----+

Real behavior (Required)

+--------------------+------+------+
| wv                 | v1   | v2   |
+--------------------+------+------+
|                  1 |    1 |    1 |
|                  1 |    1 |    1 |
|                  1 |    1 |    1 |
|                  1 |    1 |    2 |
|                  1 |    1 |    2 |
|                  1 |    1 |    2 |
| 1.3333333333333333 |    2 |    3 |
| 1.3333333333333333 |    2 |    3 |
| 1.3333333333333333 |    2 |    3 |
|                1.5 |    2 |    4 |
|                1.5 |    2 |    4 |
|                1.5 |    2 |    4 |
+--------------------+------+------+

StarRocks version (Required)

+-------------------+
| current_version() |
+-------------------+
| UNKNOWN 6f3a93f08 |
+-------------------+
liuyehcf commented 2 years ago

I misunderstood the meaning of CURRENT ROW in range window

liuyehcf commented 2 years ago

There is no bug here, just close