Skip to content

Commit 7a820ad

Browse files
committed
fix(tesseract): Filters over proxy time dimensions
1 parent 7b4e4ad commit 7a820ad

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

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

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct BaseFilter {
2525
filter_type: FilterType,
2626
filter_operator: FilterOperator,
2727
values: Vec<Option<String>>,
28+
is_over_date_range: bool,
2829
use_raw_values: bool,
2930
templates: FilterTemplates,
3031
}
@@ -51,11 +52,31 @@ impl BaseFilter {
5152
} else {
5253
vec![]
5354
};
55+
56+
//Check if we have proxy time dimension as input
57+
let symbol_to_check = if let Ok(time_dimension) = member_evaluator.as_time_dimension() {
58+
time_dimension.base_symbol().clone()
59+
} else {
60+
member_evaluator.clone()
61+
};
62+
63+
let resolved_ref = symbol_to_check.resolve_reference_chain();
64+
let is_over_date_range = if resolved_ref.as_time_dimension().is_ok() {
65+
true
66+
} else {
67+
false
68+
};
69+
70+
71+
72+
73+
5474
Ok(Rc::new(Self {
5575
query_tools,
5676
member_evaluator,
5777
filter_type,
5878
filter_operator,
79+
is_over_date_range,
5980
values,
6081
templates,
6182
use_raw_values: false,
@@ -72,6 +93,7 @@ impl BaseFilter {
7293
query_tools: self.query_tools.clone(),
7394
member_evaluator: self.member_evaluator.clone(),
7495
filter_type: self.filter_type.clone(),
96+
is_over_date_range: self.is_over_date_range,
7597
filter_operator,
7698
values,
7799
templates: self.templates.clone(),
@@ -131,6 +153,11 @@ impl BaseFilter {
131153
context.clone(),
132154
plan_templates,
133155
)?;
156+
let member_sql = if self.is_over_date_range {
157+
plan_templates.base_tools().time_stamp_cast(member_sql.clone())?
158+
} else {
159+
member_sql
160+
};
134161
let filters_context = context.filters_context();
135162

136163
let res = match self.filter_operator {
@@ -234,7 +261,7 @@ impl BaseFilter {
234261
if self.is_array_value() {
235262
self.templates.in_where(
236263
member_sql.to_string(),
237-
self.filter_and_allocate_values(),
264+
self.filter_and_allocate_values()?,
238265
need_null_check,
239266
)
240267
} else if self.is_values_contains_null() {
@@ -254,7 +281,7 @@ impl BaseFilter {
254281
if self.is_array_value() {
255282
self.templates.not_in_where(
256283
member_sql.to_string(),
257-
self.filter_and_allocate_values(),
284+
self.filter_and_allocate_values()?,
258285
need_null_check,
259286
)
260287
} else if self.is_values_contains_null() {
@@ -433,7 +460,7 @@ impl BaseFilter {
433460
let need_null_check = self.is_need_null_chek(false);
434461
self.templates.in_where(
435462
member_sql.to_string(),
436-
self.filter_and_allocate_values(),
463+
self.filter_and_allocate_values()?,
437464
need_null_check,
438465
)
439466
}
@@ -446,7 +473,7 @@ impl BaseFilter {
446473
let need_null_check = self.is_need_null_chek(true);
447474
self.templates.not_in_where(
448475
member_sql.to_string(),
449-
self.filter_and_allocate_values(),
476+
self.filter_and_allocate_values()?,
450477
need_null_check,
451478
)
452479
}
@@ -558,7 +585,7 @@ impl BaseFilter {
558585
start_wild: bool,
559586
end_wild: bool,
560587
) -> Result<String, CubeError> {
561-
let values = self.filter_and_allocate_values();
588+
let values = self.filter_and_allocate_values()?;
562589
let like_parts = values
563590
.into_iter()
564591
.map(|v| {
@@ -655,8 +682,12 @@ impl BaseFilter {
655682
QueryDateTimeHelper::format_to_date(date, self.query_tools.clone())
656683
}
657684

658-
fn allocate_param(&self, param: &str) -> String {
659-
self.query_tools.allocate_param(param)
685+
fn allocate_param(&self, param: &str) -> Result<String, CubeError> {
686+
if self.is_over_date_range {
687+
self.allocate_timestamp_param(param, false)
688+
} else {
689+
Ok(self.query_tools.allocate_param(param))
690+
}
660691
}
661692

662693
fn allocate_timestamp_param(
@@ -682,7 +713,7 @@ impl BaseFilter {
682713
)))
683714
} else {
684715
if let Some(value) = &self.values[0] {
685-
Ok(self.allocate_param(value))
716+
self.allocate_param(value)
686717
} else {
687718
Ok("NULL".to_string())
688719
}
@@ -730,10 +761,10 @@ impl BaseFilter {
730761
self.values.len() > 1
731762
}
732763

733-
fn filter_and_allocate_values(&self) -> Vec<String> {
764+
fn filter_and_allocate_values(&self) -> Result<Vec<String>, CubeError> {
734765
self.values
735766
.iter()
736767
.filter_map(|v| v.as_ref().map(|v| self.allocate_param(&v)))
737-
.collect::<Vec<_>>()
768+
.collect::<Result<Vec<_>, _>>()
738769
}
739770
}

0 commit comments

Comments
 (0)