Skip to content

Commit 64d3a36

Browse files
committed
fix
1 parent 92664e9 commit 64d3a36

File tree

6 files changed

+163
-35
lines changed

6 files changed

+163
-35
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use crate::planner::sql_evaluator::MemberSymbol;
2+
3+
use super::*;
4+
use cubenativeutils::CubeError;
5+
use std::rc::Rc;
6+
7+
#[derive(Clone)]
8+
pub struct CalcGroupDescription {
9+
symbol: Rc<MemberSymbol>,
10+
values: Vec<String>,
11+
}
12+
13+
impl PrettyPrint for CalcGroupDescription {
14+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
15+
let state = state.new_level();
16+
result.println(
17+
&format!("{}:{}", self.symbol.full_name(), self.values.join(", ")),
18+
&state,
19+
);
20+
}
21+
}
22+
23+
#[derive(Clone)]
24+
pub struct CalcGroupsCrossJoin {
25+
source: QuerySource,
26+
calc_groups: Vec<Rc<CalcGroupDescription>>,
27+
}
28+
29+
impl LogicalNode for CalcGroupsCrossJoin {
30+
fn as_plan_node(self: &Rc<Self>) -> PlanNode {
31+
PlanNode::CalcGroupsCrossJoin(self.clone())
32+
}
33+
34+
fn inputs(&self) -> Vec<PlanNode> {
35+
vec![self.source.as_plan_node()]
36+
}
37+
38+
fn with_inputs(self: Rc<Self>, inputs: Vec<PlanNode>) -> Result<Rc<Self>, CubeError> {
39+
check_inputs_len(&inputs, 1, self.node_name())?;
40+
let source = &inputs[0];
41+
42+
Ok(Rc::new(Self {
43+
calc_groups: self.calc_groups.clone(),
44+
source: self.source.with_plan_node(source.clone())?,
45+
}))
46+
}
47+
48+
fn node_name(&self) -> &'static str {
49+
"MultiStageGetDateRange"
50+
}
51+
52+
fn try_from_plan_node(plan_node: PlanNode) -> Result<Rc<Self>, CubeError> {
53+
if let PlanNode::CalcGroupsCrossJoin(item) = plan_node {
54+
Ok(item)
55+
} else {
56+
Err(cast_error(&plan_node, "MultiStageGetDateRange"))
57+
}
58+
}
59+
}
60+
61+
impl PrettyPrint for CalcGroupsCrossJoin {
62+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
63+
let state = state.new_level();
64+
result.println("CaclGroupsCrossJoin: ", &state);
65+
let state = state.new_level();
66+
result.println("Groups: ", &state);
67+
let details_state = state.new_level();
68+
for group in &self.calc_groups {
69+
group.pretty_print(result, &details_state);
70+
}
71+
result.println("Source: ", &state);
72+
self.source.pretty_print(result, &details_state);
73+
}
74+
}

rust/cubesqlplanner/cubesqlplanner/src/logical_plan/logical_node.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub enum PlanNode {
2626
MeasureSubquery(Rc<MeasureSubquery>),
2727
DimensionSubQuery(Rc<DimensionSubQuery>),
2828
KeysSubQuery(Rc<KeysSubQuery>),
29+
CalcGroupsCrossJoin(Rc<CalcGroupsCrossJoin>),
2930
MultiStageGetDateRange(Rc<MultiStageGetDateRange>),
3031
MultiStageLeafMeasure(Rc<MultiStageLeafMeasure>),
3132
MultiStageMeasureCalculation(Rc<MultiStageMeasureCalculation>),
@@ -48,6 +49,7 @@ macro_rules! match_plan_node {
4849
PlanNode::MeasureSubquery($node) => $block,
4950
PlanNode::DimensionSubQuery($node) => $block,
5051
PlanNode::KeysSubQuery($node) => $block,
52+
PlanNode::CalcGroupsCrossJoin($node) => $block,
5153
PlanNode::MultiStageGetDateRange($node) => $block,
5254
PlanNode::MultiStageLeafMeasure($node) => $block,
5355
PlanNode::MultiStageMeasureCalculation($node) => $block,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use super::*;
2+
use cubenativeutils::CubeError;
3+
use std::rc::Rc;
4+
5+
pub trait LogicalSource: Sized {
6+
fn as_plan_node(&self) -> PlanNode;
7+
fn with_plan_node(&self, plan_node: PlanNode) -> Result<Self, CubeError>;
8+
}
9+
10+
/* test example */
11+
12+
pub enum TestSouce {
13+
Cube(Rc<Cube>),
14+
MeasureSubquery(Rc<MeasureSubquery>),
15+
}
16+
17+
impl LogicalSource for TestSouce {
18+
fn as_plan_node(&self) -> PlanNode {
19+
match self {
20+
Self::Cube(item) => item.as_plan_node(),
21+
Self::MeasureSubquery(item) => item.as_plan_node(),
22+
}
23+
}
24+
fn with_plan_node(&self, plan_node: PlanNode) -> Result<Self, CubeError> {
25+
Ok(match self {
26+
Self::Cube(_) => Self::Cube(plan_node.into_logical_node()?),
27+
Self::MeasureSubquery(_) => Self::MeasureSubquery(plan_node.into_logical_node()?),
28+
})
29+
}
30+
}
31+
32+
impl From<Rc<Cube>> for TestSouce {
33+
fn from(value: Rc<Cube>) -> Self {
34+
Self::Cube(value)
35+
}
36+
}
37+
38+
impl From<Rc<MeasureSubquery>> for TestSouce {
39+
fn from(value: Rc<MeasureSubquery>) -> Self {
40+
Self::MeasureSubquery(value)
41+
}
42+
}

rust/cubesqlplanner/cubesqlplanner/src/logical_plan/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod aggregate_multiplied_subquery;
2+
mod calc_groups_cross_join;
23
mod cube;
34
mod dimension_subquery;
45
mod filter;
@@ -7,17 +8,20 @@ mod join;
78
mod keys_subquery;
89
mod logical_node;
910
mod logical_query_modifers;
11+
mod logical_source;
1012
mod measure_subquery;
1113
mod multistage;
1214
pub mod optimizers;
1315
mod pre_aggregation;
1416
pub mod pretty_print;
1517
mod query;
18+
mod query_source;
1619
mod resolve_multiplied_measures;
1720
mod schema;
1821
pub mod visitor;
1922

2023
pub use aggregate_multiplied_subquery::*;
24+
pub use calc_groups_cross_join::*;
2125
pub use cube::*;
2226
pub use dimension_subquery::*;
2327
pub use filter::*;
@@ -26,11 +30,13 @@ pub use join::*;
2630
pub use keys_subquery::*;
2731
pub use logical_node::*;
2832
pub use logical_query_modifers::*;
33+
pub use logical_source::*;
2934
pub use measure_subquery::*;
3035
pub use multistage::*;
3136
pub use optimizers::*;
3237
pub use pre_aggregation::*;
3338
pub use pretty_print::*;
3439
pub use query::*;
40+
pub use query_source::*;
3541
pub use resolve_multiplied_measures::*;
3642
pub use schema::*;

rust/cubesqlplanner/cubesqlplanner/src/logical_plan/query.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,6 @@ use super::*;
22
use cubenativeutils::CubeError;
33
use std::rc::Rc;
44

5-
#[derive(Clone)]
6-
pub enum QuerySource {
7-
LogicalJoin(Rc<LogicalJoin>),
8-
FullKeyAggregate(Rc<FullKeyAggregate>),
9-
PreAggregation(Rc<PreAggregation>),
10-
}
11-
12-
impl QuerySource {
13-
fn as_plan_node(&self) -> PlanNode {
14-
match self {
15-
Self::LogicalJoin(item) => item.as_plan_node(),
16-
Self::FullKeyAggregate(item) => item.as_plan_node(),
17-
Self::PreAggregation(item) => item.as_plan_node(),
18-
}
19-
}
20-
fn with_plan_node(&self, plan_node: PlanNode) -> Result<Self, CubeError> {
21-
Ok(match self {
22-
Self::LogicalJoin(_) => Self::LogicalJoin(plan_node.into_logical_node()?),
23-
Self::FullKeyAggregate(_) => Self::FullKeyAggregate(plan_node.into_logical_node()?),
24-
Self::PreAggregation(_) => Self::PreAggregation(plan_node.into_logical_node()?),
25-
})
26-
}
27-
}
28-
29-
impl PrettyPrint for QuerySource {
30-
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
31-
match self {
32-
QuerySource::LogicalJoin(join) => join.pretty_print(result, state),
33-
QuerySource::FullKeyAggregate(full_key) => full_key.pretty_print(result, state),
34-
QuerySource::PreAggregation(pre_aggregation) => {
35-
pre_aggregation.pretty_print(result, state)
36-
}
37-
}
38-
}
39-
}
405
#[derive(Clone)]
416
pub struct Query {
427
pub multistage_members: Vec<Rc<LogicalMultiStageMember>>,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use super::*;
2+
use cubenativeutils::CubeError;
3+
use std::rc::Rc;
4+
5+
#[derive(Clone)]
6+
pub enum QuerySource {
7+
LogicalJoin(Rc<LogicalJoin>),
8+
FullKeyAggregate(Rc<FullKeyAggregate>),
9+
PreAggregation(Rc<PreAggregation>),
10+
}
11+
12+
impl QuerySource {
13+
pub fn as_plan_node(&self) -> PlanNode {
14+
match self {
15+
Self::LogicalJoin(item) => item.as_plan_node(),
16+
Self::FullKeyAggregate(item) => item.as_plan_node(),
17+
Self::PreAggregation(item) => item.as_plan_node(),
18+
}
19+
}
20+
pub fn with_plan_node(&self, plan_node: PlanNode) -> Result<Self, CubeError> {
21+
Ok(match self {
22+
Self::LogicalJoin(_) => Self::LogicalJoin(plan_node.into_logical_node()?),
23+
Self::FullKeyAggregate(_) => Self::FullKeyAggregate(plan_node.into_logical_node()?),
24+
Self::PreAggregation(_) => Self::PreAggregation(plan_node.into_logical_node()?),
25+
})
26+
}
27+
}
28+
29+
impl PrettyPrint for QuerySource {
30+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
31+
match self {
32+
QuerySource::LogicalJoin(join) => join.pretty_print(result, state),
33+
QuerySource::FullKeyAggregate(full_key) => full_key.pretty_print(result, state),
34+
QuerySource::PreAggregation(pre_aggregation) => {
35+
pre_aggregation.pretty_print(result, state)
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)