Skip to content

Commit 3a99bef

Browse files
committed
update
1 parent 2c7342a commit 3a99bef

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

rust/cubesqlplanner/cubesqlplanner/src/planner/planners/join_planner.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{CommonUtils, DimensionSubqueryPlanner};
22
use crate::cube_bridge::join_definition::JoinDefinition;
33
use crate::cube_bridge::join_hints::JoinHintItem;
4-
use crate::cube_bridge::member_sql::MemberSql;
4+
use crate::cube_bridge::join_item::JoinItem;
55
use crate::plan::{From, JoinBuilder, JoinCondition};
66
use crate::planner::query_tools::QueryTools;
77
use crate::planner::sql_evaluator::SqlCall;
@@ -49,9 +49,7 @@ impl JoinPlanner {
4949
);
5050
dimension_subquery_planner.add_joins_for_cube(&mut join_builder, root.name())?;
5151
for join in joins.iter() {
52-
let definition = join.join()?;
53-
let sql_call = self
54-
.compile_join_condition(&join.static_data().original_from, definition.sql()?)?;
52+
let sql_call = self.compile_join_condition(join.clone())?;
5553
let on = JoinCondition::new_base_join(SqlJoinCondition::try_new(
5654
self.query_tools.clone(),
5755
sql_call,
@@ -71,13 +69,14 @@ impl JoinPlanner {
7169
}
7270
}
7371

74-
fn compile_join_condition(
72+
pub fn compile_join_condition(
7573
&self,
76-
cube_name: &String,
77-
sql: Rc<dyn MemberSql>,
74+
join_item: Rc<dyn JoinItem>,
7875
) -> Result<Rc<SqlCall>, CubeError> {
76+
let definition = join_item.join()?;
7977
let evaluator_compiler_cell = self.query_tools.evaluator_compiler().clone();
8078
let mut evaluator_compiler = evaluator_compiler_cell.borrow_mut();
81-
evaluator_compiler.compile_sql_call(&cube_name, sql)
79+
evaluator_compiler
80+
.compile_sql_call(&join_item.static_data().original_from, definition.sql()?)
8281
}
8382
}

rust/cubesqlplanner/cubesqlplanner/src/planner/planners/multiplied_measures_query_planner.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ impl MultipliedMeasuresQueryPlanner {
111111
) -> Result<Rc<Select>, CubeError> {
112112
let subquery_dimensions = collect_sub_query_dimensions_from_members(
113113
&BaseMemberHelper::iter_as_base_member(measures).collect_vec(),
114+
&self.join_planner,
115+
&key_join,
114116
self.query_tools.clone(),
115117
)?;
116118

@@ -312,6 +314,8 @@ impl MultipliedMeasuresQueryPlanner {
312314
) -> Result<Rc<Select>, CubeError> {
313315
let subquery_dimensions = collect_sub_query_dimensions_from_symbols(
314316
&self.query_properties.all_member_symbols(false),
317+
&self.join_planner,
318+
&join,
315319
self.query_tools.clone(),
316320
)?;
317321

@@ -378,6 +382,8 @@ impl MultipliedMeasuresQueryPlanner {
378382

379383
let subquery_dimensions = collect_sub_query_dimensions_from_symbols(
380384
&symbols_for_subquery_dimensions,
385+
&self.join_planner,
386+
&key_join,
381387
self.query_tools.clone(),
382388
)?;
383389

rust/cubesqlplanner/cubesqlplanner/src/planner/planners/simple_query_planer.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ impl SimpleQueryPlanner {
3030
}
3131

3232
pub fn plan(&self) -> Result<Rc<Select>, CubeError> {
33+
let join = self.query_properties.simple_query_join()?;
3334
let subquery_dimensions = collect_sub_query_dimensions_from_symbols(
3435
&self.query_properties.all_member_symbols(false),
36+
&self.join_planner,
37+
&join,
3538
self.query_tools.clone(),
3639
)?;
3740
let dimension_subquery_planner = DimensionSubqueryPlanner::try_new(
@@ -49,11 +52,9 @@ impl SimpleQueryPlanner {
4952
})
5053
};
5154
let mut context_factory = self.context_factory.clone();
52-
let from = self.join_planner.make_join_node_impl(
53-
&None,
54-
self.query_properties.simple_query_join()?,
55-
&dimension_subquery_planner,
56-
)?;
55+
let from =
56+
self.join_planner
57+
.make_join_node_impl(&None, join, &dimension_subquery_planner)?;
5758
let mut select_builder = SelectBuilder::new(from.clone());
5859

5960
for member in self

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/collectors/sub_query_dimensions.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::cube_bridge::join_definition::JoinDefinition;
2+
use crate::planner::planners::JoinPlanner;
13
use crate::planner::query_tools::QueryTools;
24
use crate::planner::sql_evaluator::{DimensionSymbol, MemberSymbol, TraversalVisitor};
35
use crate::planner::{BaseDimension, BaseMember};
@@ -60,20 +62,30 @@ impl TraversalVisitor for SubQueryDimensionsCollector {
6062

6163
pub fn collect_sub_query_dimensions_from_members(
6264
members: &Vec<Rc<dyn BaseMember>>,
65+
join_planner: &JoinPlanner,
66+
join: &Rc<dyn JoinDefinition>,
6367
query_tools: Rc<QueryTools>,
6468
) -> Result<Vec<Rc<BaseDimension>>, CubeError> {
6569
let symbols = members.iter().map(|m| m.member_evaluator()).collect_vec();
66-
collect_sub_query_dimensions_from_symbols(&symbols, query_tools)
70+
collect_sub_query_dimensions_from_symbols(&symbols, join_planner, join, query_tools)
6771
}
6872

6973
pub fn collect_sub_query_dimensions_from_symbols(
7074
members: &Vec<Rc<MemberSymbol>>,
75+
join_planner: &JoinPlanner,
76+
join: &Rc<dyn JoinDefinition>,
7177
query_tools: Rc<QueryTools>,
7278
) -> Result<Vec<Rc<BaseDimension>>, CubeError> {
7379
let mut visitor = SubQueryDimensionsCollector::new();
7480
for member in members.iter() {
7581
visitor.apply(&member, &())?;
7682
}
83+
for join_item in join.joins()? {
84+
let condition = join_planner.compile_join_condition(join_item.clone())?;
85+
for dep in condition.get_dependencies() {
86+
visitor.apply(&dep, &())?;
87+
}
88+
}
7789
visitor
7890
.extract_result()
7991
.into_iter()

0 commit comments

Comments
 (0)