Skip to content

Commit

Permalink
fix(cubestore): Aggregate function MERGE not allowed for column type …
Browse files Browse the repository at this point in the history
…bytes (#5166)
  • Loading branch information
waralexrom committed Sep 22, 2022
1 parent ae78a8d commit 7626ed5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
60 changes: 60 additions & 0 deletions rust/cubestore/cubestore-sql-tests/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ pub fn sql_tests() -> Vec<(&'static str, TestFn)> {
planning_filter_index_selection,
),
t("planning_aggregate_index", planning_aggregate_index),

t("aggregate_index", aggregate_index),
t("aggregate_index_hll", aggregate_index_hll),
t("aggregate_index_with_hll_bytes", aggregate_index_with_hll_bytes),
t("aggregate_index_errors", aggregate_index_errors),
t("inline_tables", inline_tables),
t("inline_tables_2x", inline_tables_2x),
Expand Down Expand Up @@ -5497,6 +5499,64 @@ async fn aggregate_index(service: Box<dyn SqlClient>) {
);
}

async fn aggregate_index_with_hll_bytes(service: Box<dyn SqlClient>) {
service.exec_query("CREATE SCHEMA s").await.unwrap();
service
.exec_query(
"CREATE TABLE s.Orders(a int, b int, hll bytes)
AGGREGATIONS(merge(hll))
AGGREGATE INDEX agg_index (a, b)
",
)
.await
.unwrap();
let sparse = "X'020C0200C02FF58941D5F0C6'";
let dense = "X'030C004020000001000000000000000000000000000000000000050020000001030100000410000000004102100000000000000051000020000020003220000003102000000000001200042000000001000200000002000000100000030040000000010040003010000000000100002000000000000000000031000020000000000000000000100000200302000000000000000000001002000000000002204000000001000001000200400000000000001000020031100000000080000000002003000000100000000100110000000000000000000010000000000000000000000020000001320205000100000612000000000004100020100000000000000000001000000002200000100000001000001020000000000020000000000000001000010300060000010000000000070100003000000000000020000000000001000010000104000000000000000000101000100000001401000000000000000000000000000100010000000000000000000000000400020000000002002300010000000000040000041000200005100000000000001000000000100000203010000000000000000000000000001006000100000000000000300100001000100254200000000000101100040000000020000010000050000000501000000000101020000000010000000003000000000200000102100000000204007000000200010000033000000000061000000000000000000000000000000000100001000001000000013000000003000000000002000000000000010001000000000000000000020010000020000000100001000000000000001000103000000000000000000020020000001000000000100001000000000000000020220200200000001001000010100000000200000000000001000002000000011000000000101200000000000000000000000000000000000000100130000000000000000000100000120000300040000000002000000000000000000000100000000070000100000000301000000401200002020000000000601030001510000000000000110100000000000000000050000000010000100000000000000000100022000100000101054010001000000000000001000001000000002000000000100000000000021000001000002000000000100000000000000000000951000000100000000000000000000000000102000200000000000000010000010000000000100002000000000000000000010000000000000010000000010000000102010000000010520100000021010100000030000000000000000100000001000000022000330051000000100000000000040003020000010000020000100000013000000102020000000050000000020010000000000000000101200C000100000001200400000000010000001000000000100010000000001000001000000100000000010000000004000000002000013102000100000000000000000000000600000010000000000000020000000000001000000000030000000000000020000000001000001000000000010000003002000003000200070001001003030010000000003000000000000020000006000000000000000011000000010000200000000000500000000000000020500000000003000000000000000004000030000100000000103000001000000000000200002004200000020000000030000000000000000000000002000100000000000000002000000000000000010020101000000005250000010000000000023010000001000000000000500002001000123100030011000020001310600000000000021000023000003000000000000000001000000000000220200000000004040000020201000000010201000000000020000400010000050000000000000000000000010000020000000000000000000000000000000000102000010000000000000000000000002010000200200000000000000000000000000100000000000000000200400000000010000000000000000000000000000000010000200300000000000100110000000000000000000000000010000030000001000000000010000010200013000000000000200000001000001200010000000010000000000001000000000000100000000410000040000001000100010000100000002001010000000000000000001000000000000010000000000000000000000002000000000001100001000000001010000000000000002200000000004000000000000100010000000000600000000100300000000000000000000010000003000000000000000000310000010100006000010001000000000000001010101000100000000000000000000000000000201000000000000000700010000030000000000000021000000000000000001020000000030000100001000000000000000000000004010100000000000000000000004000000040100000040100100001000000000300000100000000010010000300000200000000000001302000000000000000000100100000400030000001001000100100002300000004030000002010000220100000000000002000000010010000000003010500000000300000000005020102000200000000000000020100000000000000000000000011000000023000000000010000101000000000000010020040200040000020000004000020000000001000000000100000200000010000000000030100010001000000100000000000600400000000002000000000000132000000900010000000030021400000000004100006000304000000000000010000106000001300020000'";

service
.exec_query(
&format!("INSERT INTO s.Orders (a, b, hll) VALUES (1, 10, {s}), \
(2, 20, {d}), \
(1, 10, {d}), \
(2, 30, {s}), \
(1, 10, {d}), \
(2, 20, {s}) \
",
s = sparse,
d = dense
),
)
.await
.unwrap();

let res = service
.exec_query("SELECT a, b, cardinality(merge(hll)) FROM s.Orders GROUP BY 1, 2 ORDER BY 1, 2")
.await
.unwrap();

assert_eq!(
to_rows(&res),
[
[
TableValue::Int(1),
TableValue::Int(10),
TableValue::Int(657),
],
[
TableValue::Int(2),
TableValue::Int(20),
TableValue::Int(657),
],
[
TableValue::Int(2),
TableValue::Int(30),
TableValue::Int(2),
],
]
);

}

async fn aggregate_index_hll(service: Box<dyn SqlClient>) {
service.exec_query("CREATE SCHEMA s").await.unwrap();
service
Expand Down
1 change: 1 addition & 0 deletions rust/cubestore/cubestore/src/metastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ impl AggregateFunction {
},
Self::MERGE => match col_type {
ColumnType::HyperLogLog(_) => true,
ColumnType::Bytes => true,
_ => false,
},
}
Expand Down

0 comments on commit 7626ed5

Please sign in to comment.