Skip to content

Commit 4f97867

Browse files
committed
in work
1 parent 040deef commit 4f97867

File tree

7 files changed

+181
-10
lines changed

7 files changed

+181
-10
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ pub enum PlanNode {
108108
MeasureSubquery(Rc<MeasureSubquery>),
109109
DimensionSubQuery(Rc<DimensionSubQuery>),
110110
KeysSubQuery(Rc<KeysSubQuery>),
111+
MultiStageGetDateRange(Rc<MultiStageGetDateRange>),
112+
MultiStageLeafMeasure(Rc<MultiStageLeafMeasure>),
113+
MultiStageMeasureCalculation(Rc<MultiStageMeasureCalculation>),
114+
MultiStageTimeSeries(Rc<MultiStageTimeSeries>),
115+
MultiStageRollingWindow(Rc<MultiStageRollingWindow>),
111116
}
112117

113118
impl PlanNode {
@@ -123,6 +128,11 @@ impl PlanNode {
123128
PlanNode::MeasureSubquery(_) => MeasureSubquery::node_name(),
124129
PlanNode::DimensionSubQuery(_) => DimensionSubQuery::node_name(),
125130
PlanNode::KeysSubQuery(_) => KeysSubQuery::node_name(),
131+
PlanNode::MultiStageGetDateRange(_) => MultiStageGetDateRange::node_name(),
132+
PlanNode::MultiStageLeafMeasure(_) => MultiStageLeafMeasure::node_name(),
133+
PlanNode::MultiStageMeasureCalculation(_) => MultiStageMeasureCalculation::node_name(),
134+
PlanNode::MultiStageTimeSeries(_) => MultiStageTimeSeries::node_name(),
135+
PlanNode::MultiStageRollingWindow(_) => MultiStageRollingWindow::node_name(),
126136
}
127137
}
128138

rust/cubesqlplanner/cubesqlplanner/src/logical_plan/multistage/calculation.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::logical_plan::*;
22
use crate::planner::query_properties::OrderByItem;
33
use crate::planner::sql_evaluator::MemberSymbol;
4+
use cubenativeutils::CubeError;
45
use itertools::Itertools;
56
use std::rc::Rc;
67

7-
#[derive(PartialEq)]
8+
#[derive(PartialEq, Clone)]
89
pub enum MultiStageCalculationType {
910
Rank,
1011
Aggregate,
@@ -21,7 +22,7 @@ impl ToString for MultiStageCalculationType {
2122
}
2223
}
2324

24-
#[derive(PartialEq)]
25+
#[derive(PartialEq, Clone)]
2526
pub enum MultiStageCalculationWindowFunction {
2627
Rank,
2728
Window,
@@ -96,3 +97,41 @@ impl PrettyPrint for MultiStageMeasureCalculation {
9697
self.source.pretty_print(result, &details_state);
9798
}
9899
}
100+
101+
impl LogicalNode for MultiStageMeasureCalculation {
102+
type InputsType = SingleNodeInput;
103+
104+
fn as_plan_node(self: &Rc<Self>) -> PlanNode {
105+
PlanNode::MultiStageMeasureCalculation(self.clone())
106+
}
107+
108+
fn inputs(&self) -> Self::InputsType {
109+
SingleNodeInput::new(self.source.as_plan_node())
110+
}
111+
112+
fn with_inputs(self: Rc<Self>, inputs: Self::InputsType) -> Result<Rc<Self>, CubeError> {
113+
let source = inputs.unpack();
114+
115+
Ok(Rc::new(Self {
116+
schema: self.schema.clone(),
117+
is_ungrouped: self.is_ungrouped,
118+
calculation_type: self.calculation_type.clone(),
119+
partition_by: self.partition_by.clone(),
120+
window_function_to_use: self.window_function_to_use.clone(),
121+
order_by: self.order_by.clone(),
122+
source: source.into_logical_node()?,
123+
}))
124+
}
125+
126+
fn node_name() -> &'static str {
127+
"MultiStageMeasureCalculation"
128+
}
129+
130+
fn try_from_plan_node(plan_node: PlanNode) -> Result<Rc<Self>, CubeError> {
131+
if let PlanNode::MultiStageMeasureCalculation(item) = plan_node {
132+
Ok(item)
133+
} else {
134+
Err(cast_error::<Self>(&plan_node))
135+
}
136+
}
137+
}

rust/cubesqlplanner/cubesqlplanner/src/logical_plan/multistage/get_date_range.rs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,46 @@
11
use crate::logical_plan::*;
22
use crate::planner::sql_evaluator::MemberSymbol;
3+
use cubenativeutils::CubeError;
34
use std::rc::Rc;
5+
46
pub struct MultiStageGetDateRange {
57
pub time_dimension: Rc<MemberSymbol>,
6-
pub dimension_subqueries: Vec<Rc<DimensionSubQuery>>,
78
pub source: Rc<LogicalJoin>,
89
}
910

11+
impl LogicalNode for MultiStageGetDateRange {
12+
type InputsType = SingleNodeInput;
13+
14+
fn as_plan_node(self: &Rc<Self>) -> PlanNode {
15+
PlanNode::MultiStageGetDateRange(self.clone())
16+
}
17+
18+
fn inputs(&self) -> Self::InputsType {
19+
SingleNodeInput::new(self.source.as_plan_node())
20+
}
21+
22+
fn with_inputs(self: Rc<Self>, inputs: Self::InputsType) -> Result<Rc<Self>, CubeError> {
23+
let source = inputs.unpack();
24+
25+
Ok(Rc::new(Self {
26+
time_dimension: self.time_dimension.clone(),
27+
source: source.into_logical_node()?,
28+
}))
29+
}
30+
31+
fn node_name() -> &'static str {
32+
"MultiStageGetDateRange"
33+
}
34+
35+
fn try_from_plan_node(plan_node: PlanNode) -> Result<Rc<Self>, CubeError> {
36+
if let PlanNode::MultiStageGetDateRange(item) = plan_node {
37+
Ok(item)
38+
} else {
39+
Err(cast_error::<Self>(&plan_node))
40+
}
41+
}
42+
}
43+
1044
impl PrettyPrint for MultiStageGetDateRange {
1145
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
1246
result.println("Get Date Range", state);
@@ -16,12 +50,6 @@ impl PrettyPrint for MultiStageGetDateRange {
1650
&format!("time_dimension: {}", self.time_dimension.full_name()),
1751
&details_state,
1852
);
19-
if !self.dimension_subqueries.is_empty() {
20-
result.println("dimension_subqueries:", &state);
21-
for subquery in self.dimension_subqueries.iter() {
22-
subquery.pretty_print(result, &details_state);
23-
}
24-
}
2553
result.println("source:", &state);
2654
self.source.pretty_print(result, &details_state);
2755
}

rust/cubesqlplanner/cubesqlplanner/src/logical_plan/multistage/leaf_measure.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::logical_plan::*;
22
use crate::planner::planners::multi_stage::TimeShiftState;
33
use crate::planner::sql_evaluator::MemberSymbol;
4+
use cubenativeutils::CubeError;
45
use std::rc::Rc;
56

67
pub struct MultiStageLeafMeasure {
@@ -47,3 +48,39 @@ impl PrettyPrint for MultiStageLeafMeasure {
4748
self.query.pretty_print(result, &details_state);
4849
}
4950
}
51+
52+
impl LogicalNode for MultiStageLeafMeasure {
53+
type InputsType = SingleNodeInput;
54+
55+
fn as_plan_node(self: &Rc<Self>) -> PlanNode {
56+
PlanNode::MultiStageLeafMeasure(self.clone())
57+
}
58+
59+
fn inputs(&self) -> Self::InputsType {
60+
SingleNodeInput::new(self.query.as_plan_node())
61+
}
62+
63+
fn with_inputs(self: Rc<Self>, inputs: Self::InputsType) -> Result<Rc<Self>, CubeError> {
64+
let query = inputs.unpack();
65+
66+
Ok(Rc::new(Self {
67+
measure: self.measure.clone(),
68+
render_measure_as_state: self.render_measure_as_state,
69+
render_measure_for_ungrouped: self.render_measure_for_ungrouped,
70+
time_shifts: self.time_shifts.clone(),
71+
query: query.into_logical_node()?,
72+
}))
73+
}
74+
75+
fn node_name() -> &'static str {
76+
"MultiStageLeafMeasure"
77+
}
78+
79+
fn try_from_plan_node(plan_node: PlanNode) -> Result<Rc<Self>, CubeError> {
80+
if let PlanNode::MultiStageLeafMeasure(item) = plan_node {
81+
Ok(item)
82+
} else {
83+
Err(cast_error::<Self>(&plan_node))
84+
}
85+
}
86+
}

rust/cubesqlplanner/cubesqlplanner/src/logical_plan/multistage/rolling_window.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::logical_plan::*;
22
use crate::planner::query_properties::OrderByItem;
33
use crate::planner::sql_evaluator::MemberSymbol;
44
use crate::planner::Granularity;
5+
use cubenativeutils::CubeError;
56
use std::rc::Rc;
67

78
pub struct MultiStageRegularRollingWindow {
@@ -110,3 +111,31 @@ impl PrettyPrint for MultiStageRollingWindow {
110111
);
111112
}
112113
}
114+
115+
impl LogicalNode for MultiStageRollingWindow {
116+
type InputsType = EmptyNodeInput;
117+
118+
fn as_plan_node(self: &Rc<Self>) -> PlanNode {
119+
PlanNode::MultiStageRollingWindow(self.clone())
120+
}
121+
122+
fn inputs(&self) -> Self::InputsType {
123+
EmptyNodeInput::new()
124+
}
125+
126+
fn with_inputs(self: Rc<Self>, _inputs: Self::InputsType) -> Result<Rc<Self>, CubeError> {
127+
Ok(self)
128+
}
129+
130+
fn node_name() -> &'static str {
131+
"MultiStageRollingWindow"
132+
}
133+
134+
fn try_from_plan_node(plan_node: PlanNode) -> Result<Rc<Self>, CubeError> {
135+
if let PlanNode::MultiStageRollingWindow(item) = plan_node {
136+
Ok(item)
137+
} else {
138+
Err(cast_error::<Self>(&plan_node))
139+
}
140+
}
141+
}

rust/cubesqlplanner/cubesqlplanner/src/logical_plan/multistage/time_series.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::logical_plan::*;
22
use crate::planner::sql_evaluator::MemberSymbol;
3+
use cubenativeutils::CubeError;
34
use std::rc::Rc;
45
pub struct MultiStageTimeSeries {
56
pub time_dimension: Rc<MemberSymbol>,
@@ -32,3 +33,31 @@ impl PrettyPrint for MultiStageTimeSeries {
3233
}
3334
}
3435
}
36+
37+
impl LogicalNode for MultiStageTimeSeries {
38+
type InputsType = EmptyNodeInput;
39+
40+
fn as_plan_node(self: &Rc<Self>) -> PlanNode {
41+
PlanNode::MultiStageTimeSeries(self.clone())
42+
}
43+
44+
fn inputs(&self) -> Self::InputsType {
45+
EmptyNodeInput::new()
46+
}
47+
48+
fn with_inputs(self: Rc<Self>, _inputs: Self::InputsType) -> Result<Rc<Self>, CubeError> {
49+
Ok(self)
50+
}
51+
52+
fn node_name() -> &'static str {
53+
"MultiStageTimeSeries"
54+
}
55+
56+
fn try_from_plan_node(plan_node: PlanNode) -> Result<Rc<Self>, CubeError> {
57+
if let PlanNode::MultiStageTimeSeries(item) = plan_node {
58+
Ok(item)
59+
} else {
60+
Err(cast_error::<Self>(&plan_node))
61+
}
62+
}
63+
}

rust/cubesqlplanner/cubesqlplanner/src/planner/planners/multi_stage/member_query_planner.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl MultiStageMemberQueryPlanner {
8282

8383
let result = MultiStageGetDateRange {
8484
time_dimension: time_dimension.clone(),
85-
dimension_subqueries: source.dimension_subqueries.clone(),
8685
source,
8786
};
8887
let member = LogicalMultiStageMember {

0 commit comments

Comments
 (0)