Skip to content

Commit c0972cd

Browse files
committed
tesseract implementation
1 parent e5acc27 commit c0972cd

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,6 +3916,7 @@ export class BaseQuery {
39163916
like_escape: '{{ like_expr }} ESCAPE {{ escape_char }}',
39173917
within_group: '{{ fun_sql }} WITHIN GROUP (ORDER BY {{ within_group_concat }})',
39183918
concat_strings: '{{ strings | join(\' || \' ) }}',
3919+
rolling_window_expr_timestamp_cast: '{{ value }}'
39193920
},
39203921
tesseract: {
39213922
ilike: '{{ expr }} {% if negated %}NOT {% endif %}ILIKE {{ pattern }}', // May require different overloads in Tesseract than the ilike from expressions used in SQLAPI.

packages/cubejs-schema-compiler/src/adapter/BigqueryQuery.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ export class BigqueryQuery extends BaseQuery {
348348
templates.expressions.interval = 'INTERVAL {{ interval }}';
349349
templates.expressions.extract = 'EXTRACT({% if date_part == \'DOW\' %}DAYOFWEEK{% elif date_part == \'DOY\' %}DAYOFYEAR{% else %}{{ date_part }}{% endif %} FROM {{ expr }})';
350350
templates.expressions.timestamp_literal = 'TIMESTAMP(\'{{ value }}\')';
351+
templates.expressions.rolling_window_expr_timestamp_cast = 'TIMESTAMP({{ value }})';
351352
delete templates.expressions.ilike;
352353
delete templates.expressions.like_escape;
353354
templates.filters.like_pattern = 'CONCAT({% if start_wild %}\'%\'{% else %}\'\'{% endif %}, LOWER({{ value }}), {% if end_wild %}\'%\'{% else %}\'\'{% endif %})';

rust/cubesqlplanner/cubesqlplanner/src/plan/join.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ impl RegularRollingWindowJoinCondition {
5757
start_date
5858
};
5959

60+
let trailing_start = templates.rolling_window_expr_timestamp_cast(&trailing_start)?;
6061
let sign = if self.offset == "start" { ">=" } else { ">" };
6162

6263
conditions.push(format!("{date_column} {sign} {trailing_start}"));
@@ -75,6 +76,7 @@ impl RegularRollingWindowJoinCondition {
7576
end_date
7677
};
7778

79+
let leading_end = templates.rolling_window_expr_timestamp_cast(&leading_end)?;
7880
let sign = if self.offset == "end" { "<=" } else { "<" };
7981

8082
conditions.push(format!("{date_column} {sign} {leading_end}"));
@@ -109,6 +111,7 @@ impl RollingTotalJoinCondition {
109111
let date_column = self.time_dimension.to_sql(templates, context)?;
110112
let date_to =
111113
templates.column_reference(&Some(self.time_series_source.clone()), "date_to")?;
114+
let date_to = templates.rolling_window_expr_timestamp_cast(&date_to)?;
112115
let result = format!("{date_column} <= {date_to}");
113116
Ok(result)
114117
}
@@ -146,6 +149,8 @@ impl ToDateRollingWindowJoinCondition {
146149
templates.column_reference(&Some(self.time_series_source.clone()), "date_to")?;
147150
let date_to =
148151
templates.column_reference(&Some(self.time_series_source.clone()), "date_from")?;
152+
let date_from = templates.rolling_window_expr_timestamp_cast(&date_from)?;
153+
let date_to = templates.rolling_window_expr_timestamp_cast(&date_to)?;
149154
let grouped_from = templates.time_grouped_column(self.granularity.clone(), date_from)?;
150155
let result = format!("{date_column} >= {grouped_from} and {date_column} <= {date_to}");
151156
Ok(result)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ impl BaseFilter {
397397
) -> Result<(String, String), CubeError> {
398398
let from_expr = format!("min({})", plan_templates.quote_identifier("date_from")?);
399399
let to_expr = format!("max({})", plan_templates.quote_identifier("date_to")?);
400+
let from_expr = plan_templates.time_stamp_cast(from_expr)?;
401+
let to_expr = plan_templates.time_stamp_cast(to_expr)?;
400402
let alias = format!("value");
401403
let time_series_cte_name = format!("time_series"); // FIXME May be should be passed as parameter
402404

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_templates/plan.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,4 +702,13 @@ impl PlanSqlTemplates {
702702
},
703703
)
704704
}
705+
pub fn rolling_window_expr_timestamp_cast(&self, value: &str) -> Result<String, CubeError> {
706+
self.render.render_template(
707+
&"expressions/rolling_window_expr_timestamp_cast",
708+
context! {
709+
value => value
710+
711+
},
712+
)
713+
}
705714
}

0 commit comments

Comments
 (0)