Skip to content

Commit fa48e92

Browse files
authored
fix(cubestore): COUNT(*) don't work on subquery with aggregation (#7117)
1 parent 49ea3cf commit fa48e92

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

rust/cubestore/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/cubestore/cubestore/src/sql/mod.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,6 +4093,66 @@ mod tests {
40934093

40944094
}).await;
40954095
}
4096+
4097+
#[tokio::test]
4098+
async fn total_count_over_groupping() {
4099+
Config::test("total_count_over_groupping")
4100+
.start_test(async move |services| {
4101+
let service = services.sql_service;
4102+
4103+
let _ = service.exec_query("CREATE SCHEMA test").await.unwrap();
4104+
4105+
service
4106+
.exec_query("CREATE TABLE test.test (id int, created timestamp, value int)")
4107+
.await
4108+
.unwrap();
4109+
4110+
service
4111+
.exec_query(
4112+
"INSERT INTO test.test (id, created, value) values \
4113+
(1, '2022-01-01T00:00:00Z', 1),\
4114+
(2, '2022-01-02T00:00:00Z', 1),\
4115+
(1, '2022-02-03T00:00:00Z', 1),\
4116+
(2, '2022-02-03T00:00:00Z', 2),\
4117+
(2, '2022-01-02T00:00:00Z', 1)\
4118+
",
4119+
)
4120+
.await
4121+
.unwrap();
4122+
let res = service
4123+
.exec_query(
4124+
"SELECT count(*) cnt FROM \
4125+
(\
4126+
SELECT \
4127+
date_trunc('month', created) as month,
4128+
sum(value) as v
4129+
from test.test
4130+
group by 1
4131+
order by 2
4132+
) tmp",
4133+
)
4134+
.await
4135+
.unwrap();
4136+
assert_eq!(res.get_rows(), &vec![Row::new(vec![TableValue::Int(2)])]);
4137+
4138+
let res = service
4139+
.exec_query(
4140+
"SELECT count(*) cnt FROM \
4141+
(\
4142+
SELECT \
4143+
created as month,
4144+
sum(value) as v
4145+
from test.test
4146+
group by 1
4147+
order by 2
4148+
) tmp",
4149+
)
4150+
.await
4151+
.unwrap();
4152+
assert_eq!(res.get_rows(), &vec![Row::new(vec![TableValue::Int(3)])]);
4153+
})
4154+
.await;
4155+
}
40964156
}
40974157

40984158
impl SqlServiceImpl {

0 commit comments

Comments
 (0)