Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
waralexrom committed Sep 18, 2024
1 parent 5a745c9 commit 73c8dcb
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,29 @@ export class BaseQuery {
return false;
}

buildSqlAndParamsTest(exportAnnotatedSql) {
if (!this.options.preAggregationQuery && !this.options.disableExternalPreAggregations && this.externalQueryClass) {
if (this.externalPreAggregationQuery()) { // TODO performance
return this.externalQuery().buildSqlAndParams(exportAnnotatedSql);
}
}
const rr = this.compilers.compiler.withQuery(
this,
() => this.cacheValue(
['buildSqlAndParams', exportAnnotatedSql],
() => this.paramAllocator.buildSqlAndParams(
this.buildParamAnnotatedSql(),
exportAnnotatedSql,
this.shouldReuseParams
),
{ cache: this.queryCache }
)
);
console.log('!! js result: ', rr);
const r = this.buildSqlAndParamsRust(exportAnnotatedSql);
console.log('!! rust result: ', r);
return { rust: r, js: rr };
}

/**
* Returns an array of SQL query strings for the query.
Expand Down Expand Up @@ -3101,7 +3124,11 @@ export class BaseQuery {
not_set_where: '{{ column }} IS NULL',
in: '{{ column }} IN ({{ values_concat }}){{ is_null_check }}',
not_in: '{{ column }} NOT IN ({{ values_concat }}){{ is_null_check }}',
time_range_filter: '{{ column }} >= {{ from_timestamp }} AND {{ column }} <= {{ to_timestamp }}'
time_range_filter: '{{ column }} >= {{ from_timestamp }} AND {{ column }} <= {{ to_timestamp }}',
gt: '{{ column }} > {{ param }}',
gte: '{{ column }} >= {{ param }}',
lt: '{{ column }} < {{ param }}',
lte: '{{ column }} <= {{ param }}'

},
quotes: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ impl BaseFilter {
FilterOperator::Equal => self.equals_where(&member_sql)?,
FilterOperator::NotEqual => self.not_equals_where(&member_sql)?,
FilterOperator::InDateRange => self.in_date_range(&member_sql)?,
FilterOperator::In => self.in_where(&member_sql)?,
FilterOperator::NotIn => self.not_in_where(&member_sql)?,
FilterOperator::Set => self.set_where(&member_sql)?,
FilterOperator::NotSet => self.not_set_where(&member_sql)?,
FilterOperator::Gt => self.gt_where(&member_sql)?,
FilterOperator::Gte => self.gte_where(&member_sql)?,
FilterOperator::Lt => self.lt_where(&member_sql)?,
FilterOperator::Lte => self.lte_where(&member_sql)?,
};
Ok(res)
}
Expand Down Expand Up @@ -110,6 +118,52 @@ impl BaseFilter {
.time_range_filter(member_sql.to_string(), from, to)
}

fn in_where(&self, member_sql: &str) -> Result<String, CubeError> {
let need_null_check = self.is_need_null_chek(false);
self.templates.in_where(
member_sql.to_string(),
self.filter_and_allocate_values(),
need_null_check,
)
}

fn not_in_where(&self, member_sql: &str) -> Result<String, CubeError> {
let need_null_check = self.is_need_null_chek(true);
self.templates.not_in_where(
member_sql.to_string(),
self.filter_and_allocate_values(),
need_null_check,
)
}

fn set_where(&self, member_sql: &str) -> Result<String, CubeError> {
self.templates.set_where(member_sql.to_string())
}

fn not_set_where(&self, member_sql: &str) -> Result<String, CubeError> {
self.templates.not_set_where(member_sql.to_string())
}

fn gt_where(&self, member_sql: &str) -> Result<String, CubeError> {
self.templates
.gt(member_sql.to_string(), self.first_param()?)
}

fn gte_where(&self, member_sql: &str) -> Result<String, CubeError> {
self.templates
.gte(member_sql.to_string(), self.first_param()?)
}

fn lt_where(&self, member_sql: &str) -> Result<String, CubeError> {
self.templates
.lt(member_sql.to_string(), self.first_param()?)
}

fn lte_where(&self, member_sql: &str) -> Result<String, CubeError> {
self.templates
.lte(member_sql.to_string(), self.first_param()?)
}

fn allocate_date_params(&self) -> Result<(String, String), CubeError> {
if self.values.len() >= 2 {
let from = if let Some(from_str) = &self.values[0] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,52 @@ pub enum FilterOperator {
Equal,
NotEqual,
InDateRange,
In,
NotIn,
Set,
NotSet,
Gt,
Gte,
Lt,
Lte,
}
/*
*
public inPlaceholders() {
return `(${join(', ', this.filterParams().map(p => this.allocateCastParam(p)))})`;
}
public inWhere(column) {
return `${column} IN ${this.inPlaceholders()}${this.orIsNullCheck(column, false)}`;
}
public notInWhere(column) {
return `${column} NOT IN ${this.inPlaceholders()}${this.orIsNullCheck(column, true)}`;
}
public setWhere(column) {
return `${column} IS NOT NULL`;
}
public notSetWhere(column) {
return `${column} IS NULL`;
}
public gtWhere(column) {
return `${column} > ${this.firstParameter()}`;
}
public gteWhere(column) {
return `${column} >= ${this.firstParameter()}`;
}
public ltWhere(column) {
return `${column} < ${this.firstParameter()}`;
}
public lteWhere(column) {
return `${column} <= ${this.firstParameter()}`;
}
*/
impl FromStr for FilterOperator {
type Err = CubeError;

Expand All @@ -14,6 +58,14 @@ impl FromStr for FilterOperator {
"equals" => Ok(Self::Equal),
"notequals" => Ok(Self::NotEqual),
"indaterange" => Ok(Self::InDateRange),
"in" => Ok(Self::In),
"notin" => Ok(Self::NotIn),
"set" => Ok(Self::Set),
"gt" => Ok(Self::Gt),
"gte" => Ok(Self::Gte),
"lt" => Ok(Self::Lt),
"lte" => Ok(Self::Lte),

_ => Err(CubeError::user(format!("Unknown filter operator {}", s))),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,46 @@ impl FilterTemplates {
)
}

pub fn gt(&self, column: String, param: String) -> Result<String, CubeError> {
self.render.render_template(
&"filters/gt",
context! {
column => column,
param => param
},
)
}

pub fn gte(&self, column: String, param: String) -> Result<String, CubeError> {
self.render.render_template(
&"filters/gte",
context! {
column => column,
param => param
},
)
}

pub fn lt(&self, column: String, param: String) -> Result<String, CubeError> {
self.render.render_template(
&"filters/lt",
context! {
column => column,
param => param
},
)
}

pub fn lte(&self, column: String, param: String) -> Result<String, CubeError> {
self.render.render_template(
&"filters/lte",
context! {
column => column,
param => param
},
)
}

fn additional_null_check(&self, need: bool, column: &String) -> Result<String, CubeError> {
if need {
self.or_is_null_check(column.clone())
Expand Down

0 comments on commit 73c8dcb

Please sign in to comment.