Skip to content

Commit

Permalink
chore(cubestore): Flatten union aliasing case
Browse files Browse the repository at this point in the history
  • Loading branch information
paveltiunov committed Jan 16, 2023
1 parent af2af58 commit 83906a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rust/cubestore/cubestore/src/queryplanner/flatten_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn try_remove_sub_union(
for inp in parent_inputs.iter() {
match inp {
LogicalPlan::Union { inputs, schema, .. } => {
if *schema == *&parent_schema {
if schema.to_schema_ref() == parent_schema.to_schema_ref() {
may_be_result.extend(inputs.iter().cloned());
} else {
return parent_inputs.clone();
Expand Down
2 changes: 1 addition & 1 deletion rust/cubestore/cubestore/src/sql/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod tests {
use crate::queryplanner::serialized_plan::SerializedPlan;
use crate::queryplanner::PlanningMeta;
use crate::sql::cache::SqlResultCache;
use crate::sql::{InlineTables, SqlQueryContext};
use crate::sql::SqlQueryContext;
use crate::store::DataFrame;
use crate::table::{Row, TableValue};
use crate::CubeError;
Expand Down
28 changes: 17 additions & 11 deletions rust/cubestore/cubestore/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2319,7 +2319,7 @@ mod tests {
"INSERT INTO foo.b1 (a, b, c) VALUES (2, 2, 2)"
).await.unwrap();

let result = service.exec_query("EXPLAIN SELECT a, b, sum(c) from ( \
let result = service.exec_query("EXPLAIN SELECT a `sel__a`, b `sel__b`, sum(c) `sel__c` from ( \
select * from ( \
select * from foo.a \
union all \
Expand All @@ -2334,19 +2334,25 @@ mod tests {
union all \
select * from foo.b \
) \
) group by 1, 2").await.unwrap();
) AS `lambda` where a = 1 group by 1, 2 order by 3 desc").await.unwrap();
match &result.get_rows()[0].values()[0] {
TableValue::String(s) => {
assert_eq!(s,
"Projection, [a, b, SUM(c)]\
\n Aggregate\
\n ClusterSend, indices: [[1, 2, 3, 4, 2]]\
\n Union\
\n Scan foo.a, source: CubeTable(index: default:1:[1]:sort_on[a, b]), fields: *\
\n Scan foo.b, source: CubeTable(index: default:2:[2]:sort_on[a, b]), fields: *\
\n Scan foo.a1, source: CubeTable(index: default:3:[3]:sort_on[a, b]), fields: *\
\n Scan foo.b1, source: CubeTable(index: default:4:[4]:sort_on[a, b]), fields: *\
\n Scan foo.b, source: CubeTable(index: default:2:[2]:sort_on[a, b]), fields: *"
"Sort\
\n Projection, [sel__a, sel__b, sel__c]\
\n Aggregate\
\n ClusterSend, indices: [[1, 2, 3, 4, 2]]\
\n Union\
\n Filter\
\n Scan foo.a, source: CubeTable(index: default:1:[1]:sort_on[a, b]), fields: *\
\n Filter\
\n Scan foo.b, source: CubeTable(index: default:2:[2]:sort_on[a, b]), fields: *\
\n Filter\
\n Scan foo.a1, source: CubeTable(index: default:3:[3]:sort_on[a, b]), fields: *\
\n Filter\
\n Scan foo.b1, source: CubeTable(index: default:4:[4]:sort_on[a, b]), fields: *\
\n Filter\
\n Scan foo.b, source: CubeTable(index: default:2:[2]:sort_on[a, b]), fields: *"

);
}
Expand Down

0 comments on commit 83906a7

Please sign in to comment.