Skip to content

Commit d7da863

Browse files
committed
join map in tesseract
1 parent b887740 commit d7da863

File tree

6 files changed

+60
-3
lines changed

6 files changed

+60
-3
lines changed

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/cube_definition.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub struct CubeDefinitionStatic {
1818
pub is_view: Option<bool>,
1919
#[serde(rename = "calendar")]
2020
pub is_calendar: Option<bool>,
21+
#[serde(rename = "joinMap")]
22+
pub join_map: Option<Vec<Vec<String>>>,
2123
}
2224

2325
impl CubeDefinitionStatic {

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

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl TraversalVisitor for JoinHintsCollector {
2727
_: &Self::State,
2828
) -> Result<Option<Self::State>, CubeError> {
2929
if node.is_multi_stage() {
30-
//We don't add multi stage members childs to join hints
30+
//We don't add multi-stage members childs to join hints
3131
return Ok(None);
3232
}
3333

@@ -83,8 +83,39 @@ impl TraversalVisitor for JoinHintsCollector {
8383
pub fn collect_join_hints(node: &Rc<MemberSymbol>) -> Result<Vec<JoinHintItem>, CubeError> {
8484
let mut visitor = JoinHintsCollector::new();
8585
visitor.apply(node, &())?;
86-
let res = visitor.extract_result();
87-
Ok(res)
86+
let mut collected_hints = visitor.extract_result();
87+
88+
let join_map = match node.as_ref() {
89+
MemberSymbol::Dimension(d) => {
90+
println!("cube_name: {}, name: {}", d.cube_name(), d.name());
91+
92+
d.join_map()
93+
},
94+
MemberSymbol::TimeDimension(d) => d.join_map(),
95+
MemberSymbol::Measure(m) => m.join_map(),
96+
_ => &None,
97+
};
98+
99+
if let Some(join_map) = join_map {
100+
for hint in collected_hints.iter_mut() {
101+
match hint {
102+
// If hints array has single element, check if it can be enriched with join hints
103+
JoinHintItem::Single(hints) => {
104+
for path in join_map.iter() {
105+
if let Some(hint_index) = path.iter().position(|p| p == hints) {
106+
*hint = JoinHintItem::Vector(path[0..=hint_index].to_vec());
107+
break;
108+
}
109+
}
110+
}
111+
// If hints is an array with multiple elements, it means it already
112+
// includes full join hint path
113+
JoinHintItem::Vector(_) => {}
114+
}
115+
}
116+
}
117+
118+
Ok(collected_hints)
88119
}
89120

90121
pub fn collect_join_hints_for_measures(

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/cube_symbol.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub struct CubeTableSymbol {
7474
member_sql: Option<Rc<SqlCall>>,
7575
alias: String,
7676
is_table_sql: bool,
77+
join_map: Option<Vec<Vec<String>>>,
7778
}
7879

7980
impl CubeTableSymbol {
@@ -82,12 +83,14 @@ impl CubeTableSymbol {
8283
member_sql: Option<Rc<SqlCall>>,
8384
alias: String,
8485
is_table_sql: bool,
86+
join_map: Option<Vec<Vec<String>>>,
8587
) -> Rc<Self> {
8688
Rc::new(Self {
8789
cube_name,
8890
member_sql,
8991
alias,
9092
is_table_sql,
93+
join_map,
9194
})
9295
}
9396

@@ -133,6 +136,10 @@ impl CubeTableSymbol {
133136
pub fn alias(&self) -> String {
134137
self.alias.clone()
135138
}
139+
140+
pub fn join_map(&self) -> &Option<Vec<Vec<String>>> {
141+
&self.join_map
142+
}
136143
}
137144

138145
pub struct CubeTableSymbolFactory {
@@ -203,6 +210,7 @@ impl SymbolFactory for CubeTableSymbolFactory {
203210
sql,
204211
alias,
205212
is_table_sql,
213+
definition.static_data().join_map.clone(),
206214
)))
207215
}
208216
}

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/dimension_symbol.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ impl DimensionSymbol {
258258
&self.definition
259259
}
260260

261+
pub fn join_map(&self) -> &Option<Vec<Vec<String>>> {
262+
self.cube.join_map()
263+
}
264+
261265
pub fn name(&self) -> &String {
262266
&self.name
263267
}

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/measure_symbol.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@ impl MeasureSymbol {
488488
pub fn cube_name(&self) -> &String {
489489
&self.cube.cube_name()
490490
}
491+
492+
pub fn join_map(&self) -> &Option<Vec<Vec<String>>> {
493+
self.cube.join_map()
494+
}
495+
491496
pub fn name(&self) -> &String {
492497
&self.name
493498
}

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/time_dimension_symbol.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ impl TimeDimensionSymbol {
175175
self.base_symbol.cube_name()
176176
}
177177

178+
pub fn join_map(&self) -> &Option<Vec<Vec<String>>> {
179+
match self.base_symbol.as_ref() {
180+
MemberSymbol::Dimension(d) => d.join_map(),
181+
_ => &None,
182+
}
183+
}
184+
178185
pub fn is_multi_stage(&self) -> bool {
179186
self.base_symbol.is_multi_stage()
180187
}

0 commit comments

Comments
 (0)