Skip to content

Commit d5de132

Browse files
committed
in work
1 parent 3d58fb5 commit d5de132

File tree

11 files changed

+315
-133
lines changed

11 files changed

+315
-133
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,6 @@ export class CubeEvaluator extends CubeSymbols {
885885
});
886886
}
887887
}
888-
889888
return {
890889
allowNonStrictDateRangeMatch: aggregation.allowNonStrictDateRangeMatch,
891890
dimensions:

packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,46 +2866,100 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
28662866
console.log(query.buildSqlAndParams());
28672867

28682868
return dbRunner.testQuery(query.buildSqlAndParams()).then(res => {
2869-
console.log(JSON.stringify(res));
2869+
console.log(res);
28702870

28712871
const expected = getEnv('nativeSqlPlanner') ?
2872+
28722873
[
2874+
{
2875+
vc__id: 1,
2876+
vc__created_at_day: '2017-01-02T00:00:00.000Z',
2877+
vc__visitor_checkins_count: null,
2878+
vc__visitor_checkins_rolling: 1
2879+
},
2880+
{
2881+
vc__id: 1,
2882+
vc__created_at_day: '2017-01-03T00:00:00.000Z',
2883+
vc__visitor_checkins_count: null,
2884+
vc__visitor_checkins_rolling: 1
2885+
},
2886+
{
2887+
vc__id: 1,
2888+
vc__created_at_day: '2017-01-04T00:00:00.000Z',
2889+
vc__visitor_checkins_count: null,
2890+
vc__visitor_checkins_rolling: 1
2891+
},
2892+
{
2893+
vc__id: 1,
2894+
vc__created_at_day: '2017-01-05T00:00:00.000Z',
2895+
vc__visitor_checkins_count: null,
2896+
vc__visitor_checkins_rolling: 1
2897+
},
2898+
{
2899+
vc__id: 1,
2900+
vc__created_at_day: '2017-01-06T00:00:00.000Z',
2901+
vc__visitor_checkins_count: null,
2902+
vc__visitor_checkins_rolling: 1
2903+
},
2904+
{
2905+
vc__id: 2,
2906+
vc__created_at_day: '2017-01-03T00:00:00.000Z',
2907+
vc__visitor_checkins_count: null,
2908+
vc__visitor_checkins_rolling: 1
2909+
},
2910+
{
2911+
vc__id: 2,
2912+
vc__created_at_day: '2017-01-04T00:00:00.000Z',
2913+
vc__visitor_checkins_count: null,
2914+
vc__visitor_checkins_rolling: 1
2915+
},
2916+
{
2917+
vc__id: 2,
2918+
vc__created_at_day: '2017-01-05T00:00:00.000Z',
2919+
vc__visitor_checkins_count: null,
2920+
vc__visitor_checkins_rolling: 1
2921+
},
2922+
{
2923+
vc__id: 2,
2924+
vc__created_at_day: '2017-01-06T00:00:00.000Z',
2925+
vc__visitor_checkins_count: null,
2926+
vc__visitor_checkins_rolling: 1
2927+
},
28732928
{
28742929
vc__id: 3,
28752930
vc__created_at_day: '2017-01-04T00:00:00.000Z',
28762931
vc__visitor_checkins_count: 1,
28772932
vc__visitor_checkins_rolling: 1
28782933
},
28792934
{
2880-
vc__created_at_day: '2017-01-05T00:00:00.000Z',
28812935
vc__id: 3,
2936+
vc__created_at_day: '2017-01-05T00:00:00.000Z',
28822937
vc__visitor_checkins_count: null,
2883-
vc__visitor_checkins_rolling: 1,
2938+
vc__visitor_checkins_rolling: 1
28842939
},
28852940
{
2886-
vc__created_at_day: '2017-01-06T00:00:00.000Z',
28872941
vc__id: 3,
2942+
vc__created_at_day: '2017-01-06T00:00:00.000Z',
28882943
vc__visitor_checkins_count: null,
2889-
vc__visitor_checkins_rolling: 1,
2944+
vc__visitor_checkins_rolling: 1
28902945
},
28912946
{
28922947
vc__id: 4,
28932948
vc__created_at_day: '2017-01-04T00:00:00.000Z',
28942949
vc__visitor_checkins_count: 1,
28952950
vc__visitor_checkins_rolling: 1
2896-
28972951
},
28982952
{
2899-
vc__created_at_day: '2017-01-05T00:00:00.000Z',
29002953
vc__id: 4,
2954+
vc__created_at_day: '2017-01-05T00:00:00.000Z',
29012955
vc__visitor_checkins_count: null,
2902-
vc__visitor_checkins_rolling: 1,
2956+
vc__visitor_checkins_rolling: 1
29032957
},
29042958
{
2905-
vc__created_at_day: '2017-01-06T00:00:00.000Z',
29062959
vc__id: 4,
2960+
vc__created_at_day: '2017-01-06T00:00:00.000Z',
29072961
vc__visitor_checkins_count: null,
2908-
vc__visitor_checkins_rolling: 1,
2962+
vc__visitor_checkins_rolling: 1
29092963
},
29102964
{
29112965
vc__id: 5,
@@ -2914,49 +2968,37 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
29142968
vc__visitor_checkins_rolling: 1
29152969
},
29162970
{
2917-
vc__created_at_day: '2017-01-05T00:00:00.000Z',
29182971
vc__id: 5,
2972+
vc__created_at_day: '2017-01-05T00:00:00.000Z',
29192973
vc__visitor_checkins_count: null,
2920-
vc__visitor_checkins_rolling: 1,
2974+
vc__visitor_checkins_rolling: 1
29212975
},
29222976
{
2923-
vc__created_at_day: '2017-01-06T00:00:00.000Z',
29242977
vc__id: 5,
2978+
vc__created_at_day: '2017-01-06T00:00:00.000Z',
29252979
vc__visitor_checkins_count: null,
2926-
vc__visitor_checkins_rolling: 1,
2980+
vc__visitor_checkins_rolling: 1
29272981
},
29282982
{
29292983
vc__id: 6,
29302984
vc__created_at_day: '2017-01-05T00:00:00.000Z',
29312985
vc__visitor_checkins_count: 1,
29322986
vc__visitor_checkins_rolling: 1
29332987
},
2934-
29352988
{
2936-
vc__created_at_day: '2017-01-06T00:00:00.000Z',
29372989
vc__id: 6,
2990+
vc__created_at_day: '2017-01-06T00:00:00.000Z',
29382991
vc__visitor_checkins_count: null,
2939-
vc__visitor_checkins_rolling: 1,
2940-
},
2941-
{
2942-
vc__created_at_day: '2017-01-01T00:00:00.000Z',
2943-
vc__id: null,
2944-
vc__visitor_checkins_count: null,
2945-
vc__visitor_checkins_rolling: null,
2946-
},
2947-
{
2948-
vc__created_at_day: '2017-01-02T00:00:00.000Z',
2949-
vc__id: null,
2950-
vc__visitor_checkins_count: null,
2951-
vc__visitor_checkins_rolling: null,
2992+
vc__visitor_checkins_rolling: 1
29522993
},
29532994
{
2954-
vc__created_at_day: '2017-01-03T00:00:00.000Z',
29552995
vc__id: null,
2996+
vc__created_at_day: '2017-01-01T00:00:00.000Z',
29562997
vc__visitor_checkins_count: null,
2957-
vc__visitor_checkins_rolling: null,
2958-
},
2998+
vc__visitor_checkins_rolling: null
2999+
}
29593000
]
3001+
29603002
: [
29613003
{
29623004
vc__id: 3,

packages/cubejs-schema-compiler/test/integration/postgres/yaml-compiler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ cubes:
333333
);
334334
});
335335

336-
it('joins', async () => {
336+
it('joins 1', async () => {
337337
const { compiler, joinGraph, cubeEvaluator } = prepareYamlCompiler(`
338338
cubes:
339339
- name: orders

packages/cubejs-schema-compiler/test/unit/base-query.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ describe('SQL Generation', () => {
10121012
relationship: 'one_to_one'
10131013
},
10141014
}`
1015-
}).replace(`sql: \`\${CUBE}.location = 'San Francisco'\``, `sql: \`\${FILTER_PARAMS.cardsA.location.filter('location')}\``),
1015+
}).replace('sql: `${CUBE}.location = \'San Francisco\'`', 'sql: `${FILTER_PARAMS.cardsA.location.filter(\'location\')}`'),
10161016
createCubeSchema({
10171017
name: 'cardsB',
10181018
sqlTable: 'card2_tbl',

rust/cubenativeutils/src/wrappers/object_handle.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{inner_types::InnerTypes, object::NativeObject};
2-
use super::{NativeContextHolder, NativeContextHolderRef};
2+
use super::{NativeContextHolder, NativeContextHolderRef, NativeString, NativeStruct};
3+
use crate::wrappers::NativeNumber;
34
use crate::CubeError;
45

56
#[derive(Clone)]
@@ -65,6 +66,20 @@ impl<IT: InnerTypes> NativeObjectHandle<IT> {
6566
pub fn get_context(&self) -> IT::Context {
6667
self.object.get_context()
6768
}
69+
70+
pub fn convert_to_string(&self) -> Result<String, CubeError> {
71+
if let Ok(str) = self.to_string() {
72+
str.value()
73+
} else if self.is_null()? {
74+
Ok("".to_string())
75+
} else {
76+
self.to_struct()?
77+
.call_method("toString", vec![])?
78+
.into_string()?
79+
.value()
80+
}
81+
}
82+
6883
pub fn try_clone_to_context_ref(
6984
&self,
7085
context_ref: &dyn NativeContextHolderRef,

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/evaluator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub trait CubeEvaluator {
4949
fn cube_from_path(&self, cube_path: String) -> Result<Rc<dyn CubeDefinition>, CubeError>;
5050
fn is_measure(&self, path: Vec<String>) -> Result<bool, CubeError>;
5151
fn is_dimension(&self, path: Vec<String>) -> Result<bool, CubeError>;
52+
fn is_segment(&self, path: Vec<String>) -> Result<bool, CubeError>;
5253
fn cube_exists(&self, name: String) -> Result<bool, CubeError>;
5354
fn resolve_symbols_call_deps(
5455
&self,

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/member_sql.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,40 @@ use cubenativeutils::wrappers::object::{NativeFunction, NativeStruct, NativeType
1111
use cubenativeutils::wrappers::serializer::{
1212
NativeDeserialize, NativeDeserializer, NativeSerialize,
1313
};
14-
use cubenativeutils::wrappers::NativeContextHolder;
1514
use cubenativeutils::wrappers::NativeObjectHandle;
1615
use cubenativeutils::wrappers::{inner_types::InnerTypes, NativeString};
1716
use cubenativeutils::wrappers::{make_proxy, NativeContextHolderRef};
17+
use cubenativeutils::wrappers::{NativeArray, NativeContextHolder};
1818
use cubenativeutils::CubeError;
1919
use serde::{Deserialize, Serialize};
2020
use std::collections::hash_map::HashMap;
2121
use std::rc::Rc;
2222
use std::{any::Any, cell::RefCell, rc::Weak};
2323

24+
#[derive(Clone, Debug, PartialEq, Eq)]
25+
pub enum SqlTemplate {
26+
String(String),
27+
StringVec(Vec<String>),
28+
}
29+
30+
impl<IT: InnerTypes> NativeDeserialize<IT> for SqlTemplate {
31+
fn from_native(v: NativeObjectHandle<IT>) -> Result<Self, CubeError> {
32+
if let Ok(vec) = v.to_array() {
33+
let mut result = vec![];
34+
for v in vec.to_vec()? {
35+
let string_value = v.convert_to_string()?;
36+
37+
result.push(string_value);
38+
}
39+
Ok(SqlTemplate::StringVec(result))
40+
} else {
41+
let val = v.convert_to_string()?;
42+
43+
Ok(SqlTemplate::String(val))
44+
}
45+
}
46+
}
47+
2448
#[derive(Clone)]
2549
pub enum FilterParamsColumn {
2650
String(String),
@@ -284,7 +308,7 @@ pub trait MemberSql {
284308
&self,
285309
base_tools: Rc<dyn BaseTools>,
286310
security_context: Rc<dyn SecurityContext>,
287-
) -> Result<(String, SqlTemplateArgs), CubeError>;
311+
) -> Result<(SqlTemplate, SqlTemplateArgs), CubeError>;
288312
}
289313

290314
pub struct NativeMemberSql<IT: InnerTypes> {
@@ -617,7 +641,7 @@ impl<IT: InnerTypes> MemberSql for NativeMemberSql<IT> {
617641
&self,
618642
base_tools: Rc<dyn BaseTools>,
619643
security_context: Rc<dyn SecurityContext>,
620-
) -> Result<(String, SqlTemplateArgs), CubeError> {
644+
) -> Result<(SqlTemplate, SqlTemplateArgs), CubeError> {
621645
let state = ProxyState::new();
622646
let weak_state = state.weak();
623647
let context_holder = NativeContextHolder::<IT>::new(self.native_object.get_context());
@@ -662,7 +686,7 @@ impl<IT: InnerTypes> MemberSql for NativeMemberSql<IT> {
662686
}
663687
let native_func = self.native_object.to_function()?;
664688
let evaluation_result = native_func.call(proxy_args)?;
665-
let template = String::from_native(evaluation_result)?;
689+
let template = SqlTemplate::from_native(evaluation_result)?;
666690
let context_ref = context_holder.as_holder_ref();
667691
let sql_args = state.get_args()?.clone_to_context(context_ref)?;
668692

rust/cubesqlplanner/cubesqlplanner/src/planner/base_query.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<IT: InnerTypes> BaseQuery<IT> {
127127
);
128128
let disable_external_pre_aggregations =
129129
self.request.disable_external_pre_aggregations();
130-
/* if let Some(result) = pre_aggregation_optimizer
130+
if let Some(result) = pre_aggregation_optimizer
131131
.try_optimize(plan.clone(), disable_external_pre_aggregations)?
132132
{
133133
if pre_aggregation_optimizer.get_used_pre_aggregations().len() == 1 {
@@ -139,9 +139,9 @@ impl<IT: InnerTypes> BaseQuery<IT> {
139139
//TODO multiple pre-aggregations sources required changes in BaseQuery
140140
(plan.clone(), Vec::new())
141141
}
142-
} else { */
143-
(plan.clone(), Vec::new())
144-
//}
142+
} else {
143+
(plan.clone(), Vec::new())
144+
}
145145
} else {
146146
(plan.clone(), Vec::new())
147147
};

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,24 @@ impl BaseFilter {
159159
_ => None,
160160
};
161161

162-
if let Some(filter_params_column) = filters_context
163-
.filter_params_columns
164-
.get(&symbol.full_name())
165-
{
166-
return self.to_sql_for_filter_params(
167-
filter_params_column,
168-
symbol,
169-
plan_templates,
170-
filters_context,
171-
&member_type,
172-
);
162+
if !filters_context.filter_params_columns.is_empty() {
163+
let symbol_to_match = if let Ok(time_dim) = symbol.as_time_dimension() {
164+
time_dim.base_symbol().clone().resolve_reference_chain()
165+
} else {
166+
symbol.clone().resolve_reference_chain()
167+
};
168+
if let Some(filter_params_column) = filters_context
169+
.filter_params_columns
170+
.get(&symbol_to_match.full_name())
171+
{
172+
return self.to_sql_for_filter_params(
173+
filter_params_column,
174+
symbol,
175+
plan_templates,
176+
filters_context,
177+
&member_type,
178+
);
179+
}
173180
}
174181

175182
let member_sql = evaluate_with_context(&symbol, context.clone(), plan_templates)?;
@@ -183,6 +190,7 @@ impl BaseFilter {
183190
)
184191
}
185192
}
193+
186194
fn to_sql_for_filter_params(
187195
&self,
188196
column: &FilterParamsColumn,

0 commit comments

Comments
 (0)