Skip to content

Commit c2d7d2e

Browse files
committed
in work
1 parent ed5c593 commit c2d7d2e

File tree

9 files changed

+83
-23
lines changed

9 files changed

+83
-23
lines changed

packages/cubejs-schema-compiler/src/compiler/CubeSymbols.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,9 @@ export class CubeSymbols {
10101010
return true;
10111011
}
10121012
if (cube[propertyName]) {
1013-
depsResolveFn(propertyName, parentIndex);
1013+
const index = depsResolveFn(propertyName, parentIndex);
10141014
if (cube[propertyName].type === 'time') {
1015-
return this.timeDimDependenciesProxy(parentIndex);
1015+
return this.timeDimDependenciesProxy(index);
10161016
}
10171017

10181018
return '';

rust/cubesqlplanner/cubesqlplanner/src/planner/base_dimension.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ impl BaseDimension {
123123
member_expression_definition: Option<String>,
124124
query_tools: Rc<QueryTools>,
125125
) -> Result<Rc<Self>, CubeError> {
126-
let member_expression_symbol = MemberExpressionSymbol::new(
126+
let member_expression_symbol = MemberExpressionSymbol::try_new(
127127
cube_name.clone(),
128128
name.clone(),
129129
expression,
130130
member_expression_definition.clone(),
131-
);
131+
)?;
132132
let full_name = member_expression_symbol.full_name();
133133
let member_evaluator = Rc::new(MemberSymbol::MemberExpression(member_expression_symbol));
134134
let default_alias = PlanSqlTemplates::alias_name(&name);

rust/cubesqlplanner/cubesqlplanner/src/planner/base_measure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ impl BaseMeasure {
135135
member_expression_definition: Option<String>,
136136
query_tools: Rc<QueryTools>,
137137
) -> Result<Rc<Self>, CubeError> {
138-
let member_expression_symbol = MemberExpressionSymbol::new(
138+
let member_expression_symbol = MemberExpressionSymbol::try_new(
139139
cube_name.clone(),
140140
name.clone(),
141141
expression,
142142
member_expression_definition.clone(),
143-
);
143+
)?;
144144
let full_name = member_expression_symbol.full_name();
145145
let member_evaluator = Rc::new(MemberSymbol::MemberExpression(member_expression_symbol));
146146
let default_alias = PlanSqlTemplates::alias_name(&name);

rust/cubesqlplanner/cubesqlplanner/src/planner/filter/base_segment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl BaseSegment {
2828
query_tools: Rc<QueryTools>,
2929
) -> Result<Rc<Self>, CubeError> {
3030
let member_expression_symbol =
31-
MemberExpressionSymbol::new(cube_name.clone(), name.clone(), expression, None);
31+
MemberExpressionSymbol::try_new(cube_name.clone(), name.clone(), expression, None)?;
3232
let full_name = full_name.unwrap_or(member_expression_symbol.full_name());
3333
let member_evaluator = Rc::new(MemberSymbol::MemberExpression(member_expression_symbol));
3434

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ impl DimensionSymbol {
116116
self.is_reference
117117
}
118118

119+
pub fn reference_member(&self) -> Option<Rc<MemberSymbol>> {
120+
if !self.is_reference() {
121+
return None;
122+
}
123+
let deps = self.get_dependencies();
124+
if deps.is_empty() {
125+
return None;
126+
}
127+
deps.first().cloned()
128+
}
129+
119130
pub fn get_dependencies(&self) -> Vec<Rc<MemberSymbol>> {
120131
let mut deps = vec![];
121132
if let Some(member_sql) = &self.member_sql {
@@ -192,6 +203,7 @@ pub struct DimensionSymbolFactory {
192203
name: String,
193204
sql: Option<Rc<dyn MemberSql>>,
194205
definition: Rc<dyn DimensionDefinition>,
206+
cube_evaluator: Rc<dyn CubeEvaluator>,
195207
}
196208

197209
impl DimensionSymbolFactory {
@@ -210,6 +222,7 @@ impl DimensionSymbolFactory {
210222
name,
211223
sql: definition.sql()?,
212224
definition,
225+
cube_evaluator,
213226
})
214227
}
215228
}
@@ -241,6 +254,7 @@ impl SymbolFactory for DimensionSymbolFactory {
241254
name,
242255
sql,
243256
definition,
257+
cube_evaluator,
244258
} = self;
245259
let sql = if let Some(sql) = sql {
246260
Some(compiler.compile_sql_call(&cube_name, sql)?)
@@ -299,16 +313,19 @@ impl SymbolFactory for DimensionSymbolFactory {
299313
} else {
300314
None
301315
};
316+
let cube = cube_evaluator.cube_from_path(cube_name.clone())?;
317+
let is_view = cube.static_data().is_view.unwrap_or(false);
302318
let owned_by_cube = definition.static_data().owned_by_cube.unwrap_or(true);
303319
let is_sub_query = definition.static_data().sub_query.unwrap_or(false);
304320
let is_multi_stage = definition.static_data().multi_stage.unwrap_or(false);
305-
let is_reference = !owned_by_cube
306-
&& !is_sub_query
307-
&& is_sql_direct_ref
308-
&& case.is_none()
309-
&& latitude.is_none()
310-
&& longitude.is_none()
311-
&& !is_multi_stage;
321+
let is_reference = is_view
322+
|| (!owned_by_cube
323+
&& !is_sub_query
324+
&& is_sql_direct_ref
325+
&& case.is_none()
326+
&& latitude.is_none()
327+
&& longitude.is_none()
328+
&& !is_multi_stage);
312329
Ok(MemberSymbol::new_dimension(DimensionSymbol::new(
313330
cube_name,
314331
name,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ impl MeasureSymbol {
235235
self.is_reference
236236
}
237237

238+
pub fn reference_member(&self) -> Option<Rc<MemberSymbol>> {
239+
if !self.is_reference() {
240+
return None;
241+
}
242+
let deps = self.get_dependencies();
243+
if deps.is_empty() {
244+
return None;
245+
}
246+
deps.first().cloned()
247+
}
248+
238249
pub fn measure_type(&self) -> &String {
239250
&self.definition.static_data().measure_type
240251
}

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@ pub struct MemberExpressionSymbol {
1111
expression: Rc<SqlCall>,
1212
#[allow(dead_code)]
1313
definition: Option<String>,
14+
is_reference: bool,
1415
}
1516

1617
impl MemberExpressionSymbol {
17-
pub fn new(
18+
pub fn try_new(
1819
cube_name: String,
1920
name: String,
2021
expression: Rc<SqlCall>,
2122
definition: Option<String>,
22-
) -> Self {
23-
Self {
23+
) -> Result<Self, CubeError> {
24+
25+
let is_reference = expression.is_direct_reference()?;
26+
Ok(Self {
2427
cube_name,
2528
name,
2629
expression,
2730
definition,
28-
}
31+
is_reference
32+
})
2933
}
3034

3135
pub fn evaluate_sql(
@@ -50,7 +54,18 @@ impl MemberExpressionSymbol {
5054
}
5155

5256
pub fn is_reference(&self) -> bool {
53-
false
57+
self.is_reference
58+
}
59+
60+
pub fn reference_member(&self) -> Option<Rc<MemberSymbol>> {
61+
if !self.is_reference() {
62+
return None;
63+
}
64+
let deps = self.get_dependencies();
65+
if deps.is_empty() {
66+
return None;
67+
}
68+
deps.first().cloned()
5469
}
5570

5671
pub fn get_dependencies(&self) -> Vec<Rc<MemberSymbol>> {

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,14 @@ impl MemberSymbol {
137137
}
138138

139139
pub fn reference_member(&self) -> Option<Rc<MemberSymbol>> {
140-
let deps = self.get_dependencies();
141-
if deps.is_empty() || !self.is_reference() {
142-
return None;
140+
match self {
141+
Self::Dimension(d) => d.reference_member(),
142+
Self::TimeDimension(d) => d.reference_member(),
143+
Self::Measure(m) => m.reference_member(),
144+
Self::CubeName(_) => None,
145+
Self::CubeTable(_) => None,
146+
Self::MemberExpression(e) => e.reference_member(),
143147
}
144-
deps.first().cloned()
145148
}
146149

147150
pub fn resolve_reference_chain(self: Rc<Self>) -> Rc<MemberSymbol> {

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ impl TimeDimensionSymbol {
110110
self.base_symbol.is_reference()
111111
}
112112

113+
pub fn reference_member(&self) -> Option<Rc<MemberSymbol>> {
114+
if let Some(base_symbol) = self.base_symbol.clone().reference_member() {
115+
let new_time_dim = Self::new(
116+
base_symbol,
117+
self.granularity.clone(),
118+
self.granularity_obj.clone(),
119+
self.date_range.clone(),
120+
);
121+
Some(Rc::new(MemberSymbol::TimeDimension(new_time_dim)))
122+
} else {
123+
None
124+
}
125+
}
126+
113127
pub fn name(&self) -> String {
114128
self.base_symbol.name()
115129
}

0 commit comments

Comments
 (0)