-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(tesseract): Fix rolling window with few time dimensions, filter_group in segments and member expressions #9673
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
12880ec
feat(tesseract): Catch up with features recently added to BaseQuery
waralexrom 866e024
rolling window with two td one custom and one regular
waralexrom 916b926
patched measures
waralexrom ed2c307
filter_group in segments
waralexrom f0ccd15
fix
waralexrom 44099a1
limit fix
waralexrom d787e45
member expressions fixes
waralexrom 14cc1e3
fix
waralexrom a206bff
addon
waralexrom c17bcbb
fix
waralexrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 20 additions & 2 deletions
22
rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/join_hints.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,25 @@ | ||
| use serde::{Deserialize, Serialize}; | ||
| use cubenativeutils::wrappers::inner_types::InnerTypes; | ||
| use cubenativeutils::wrappers::serializer::NativeDeserialize; | ||
| use cubenativeutils::wrappers::NativeObjectHandle; | ||
| use cubenativeutils::CubeError; | ||
| use serde::Serialize; | ||
|
|
||
| #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] | ||
| #[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize)] | ||
| pub enum JoinHintItem { | ||
| Single(String), | ||
| Vector(Vec<String>), | ||
| } | ||
|
|
||
| impl<IT: InnerTypes> NativeDeserialize<IT> for JoinHintItem { | ||
| fn from_native(native_object: NativeObjectHandle<IT>) -> Result<Self, CubeError> { | ||
| match Vec::<String>::from_native(native_object.clone()) { | ||
| Ok(value) => Ok(Self::Vector(value)), | ||
| Err(_) => match String::from_native(native_object) { | ||
| Ok(value) => Ok(Self::Single(value)), | ||
| Err(_) => Err(CubeError::user(format!( | ||
| "Join hint item expected to be string or vector of strings" | ||
| ))), | ||
| }, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 40 additions & 2 deletions
42
rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/member_expression.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,62 @@ | ||
| use super::member_sql::{MemberSql, NativeMemberSql}; | ||
| use super::struct_with_sql_member::{NativeStructWithSqlMember, StructWithSqlMember}; | ||
| use cubenativeutils::wrappers::serializer::{ | ||
| NativeDeserialize, NativeDeserializer, NativeSerialize, | ||
| }; | ||
| use cubenativeutils::wrappers::NativeArray; | ||
| use cubenativeutils::wrappers::{NativeContextHolder, NativeObjectHandle}; | ||
| use cubenativeutils::CubeError; | ||
| use serde::{Deserialize, Serialize}; | ||
| use std::any::Any; | ||
| use std::rc::Rc; | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone)] | ||
| pub struct ExpressionStructStatic { | ||
| #[serde(rename = "type")] | ||
| pub expression_type: String, | ||
| #[serde(rename = "sourceMeasure")] | ||
| pub source_measure: Option<String>, | ||
| #[serde(rename = "replaceAggregationType")] | ||
| pub replace_aggregation_type: Option<String>, | ||
| } | ||
|
|
||
| #[nativebridge::native_bridge(ExpressionStructStatic)] | ||
| pub trait ExpressionStruct { | ||
| #[nbridge(field, optional, vec)] | ||
| fn add_filters(&self) -> Result<Option<Vec<Rc<dyn StructWithSqlMember>>>, CubeError>; | ||
| } | ||
|
|
||
| pub enum MemberExpressionExpressionDef { | ||
| Sql(Rc<dyn MemberSql>), | ||
| Struct(Rc<dyn ExpressionStruct>), | ||
| } | ||
|
|
||
| impl<IT: InnerTypes> NativeDeserialize<IT> for MemberExpressionExpressionDef { | ||
| fn from_native(native_object: NativeObjectHandle<IT>) -> Result<Self, CubeError> { | ||
| match NativeMemberSql::from_native(native_object.clone()) { | ||
| Ok(sql) => Ok(Self::Sql(Rc::new(sql))), | ||
| Err(_) => match NativeExpressionStruct::from_native(native_object) { | ||
| Ok(expr) => Ok(Self::Struct(Rc::new(expr))), | ||
| Err(_) => Err(CubeError::user(format!( | ||
| "Member sql or expression struct expected for member expression expression field" | ||
| ))), | ||
| }, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone)] | ||
| pub struct MemberExpressionDefinitionStatic { | ||
| #[serde(rename = "expressionName")] | ||
| pub expression_name: Option<String>, | ||
| pub name: Option<String>, | ||
| #[serde(rename = "cubeName")] | ||
| pub cube_name: Option<String>, | ||
| pub definition: Option<String>, | ||
| } | ||
|
|
||
| #[nativebridge::native_bridge(MemberExpressionDefinitionStatic)] | ||
| #[nativebridge::native_bridge(MemberExpressionDefinitionStatic, without_imports)] | ||
| pub trait MemberExpressionDefinition { | ||
| #[nbridge(field)] | ||
| fn expression(&self) -> Result<Rc<dyn MemberSql>, CubeError>; | ||
| fn expression(&self) -> Result<MemberExpressionExpressionDef, CubeError>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,8 @@ | ||||||
| use super::query_tools::QueryTools; | ||||||
| use super::sql_evaluator::{MeasureTimeShift, MemberExpressionSymbol, MemberSymbol, SqlCall}; | ||||||
| use super::sql_evaluator::{MeasureTimeShifts, MemberExpressionSymbol, MemberSymbol}; | ||||||
| use super::{evaluate_with_context, BaseMember, BaseMemberHelper, VisitorContext}; | ||||||
| use crate::cube_bridge::measure_definition::{MeasureDefinition, RollingWindow}; | ||||||
| use crate::cube_bridge::measure_definition::RollingWindow; | ||||||
| use crate::planner::sql_evaluator::MemberExpressionExpression; | ||||||
| use crate::planner::sql_templates::PlanSqlTemplates; | ||||||
| use cubenativeutils::CubeError; | ||||||
| use std::fmt::{Debug, Formatter}; | ||||||
|
|
@@ -11,7 +12,6 @@ pub struct BaseMeasure { | |||||
| measure: String, | ||||||
| query_tools: Rc<QueryTools>, | ||||||
| member_evaluator: Rc<MemberSymbol>, | ||||||
| definition: Option<Rc<dyn MeasureDefinition>>, | ||||||
| #[allow(dead_code)] | ||||||
| member_expression_definition: Option<String>, | ||||||
| cube_name: String, | ||||||
|
|
@@ -84,7 +84,6 @@ impl BaseMeasure { | |||||
| measure: s.full_name(), | ||||||
| query_tools: query_tools.clone(), | ||||||
| member_evaluator: evaluation_node.clone(), | ||||||
| definition: Some(s.definition().clone()), | ||||||
| member_expression_definition: None, | ||||||
| cube_name: s.cube_name().clone(), | ||||||
| name: s.name().clone(), | ||||||
|
|
@@ -101,7 +100,6 @@ impl BaseMeasure { | |||||
| measure: full_name, | ||||||
| query_tools: query_tools.clone(), | ||||||
| member_evaluator: evaluation_node, | ||||||
| definition: None, | ||||||
| cube_name, | ||||||
| name, | ||||||
| member_expression_definition, | ||||||
|
|
@@ -127,7 +125,7 @@ impl BaseMeasure { | |||||
| } | ||||||
|
|
||||||
| pub fn try_new_from_expression( | ||||||
| expression: Rc<SqlCall>, | ||||||
| expression: MemberExpressionExpression, | ||||||
| cube_name: String, | ||||||
| name: String, | ||||||
| member_expression_definition: Option<String>, | ||||||
|
|
@@ -138,36 +136,28 @@ impl BaseMeasure { | |||||
| name.clone(), | ||||||
| expression, | ||||||
| member_expression_definition.clone(), | ||||||
| query_tools.base_tools().clone(), | ||||||
| )?; | ||||||
| let full_name = member_expression_symbol.full_name(); | ||||||
| let member_evaluator = Rc::new(MemberSymbol::MemberExpression(member_expression_symbol)); | ||||||
| let member_evaluator = MemberSymbol::new_member_expression(member_expression_symbol); | ||||||
| let default_alias = PlanSqlTemplates::alias_name(&name); | ||||||
| Ok(Rc::new(Self { | ||||||
| measure: full_name, | ||||||
| query_tools, | ||||||
| member_evaluator, | ||||||
| definition: None, | ||||||
| cube_name, | ||||||
| name, | ||||||
| member_expression_definition, | ||||||
| default_alias, | ||||||
| })) | ||||||
| } | ||||||
|
|
||||||
| pub fn can_used_as_addictive_in_multplied(&self) -> Result<bool, CubeError> { | ||||||
| let measure_type = self.measure_type(); | ||||||
| let res = if measure_type == "countDistinct" || measure_type == "countDistinctApprox" { | ||||||
| true | ||||||
| } else if measure_type == "count" { | ||||||
| if let Some(definition) = &self.definition { | ||||||
| !definition.has_sql()? | ||||||
| } else { | ||||||
| false | ||||||
| } | ||||||
| pub fn can_be_used_as_additive_in_multplied(&self) -> bool { | ||||||
| if let Ok(measure_symbol) = self.member_evaluator.as_measure() { | ||||||
| measure_symbol.can_used_as_addictive_in_multplied() | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to rename this too:
Suggested change
|
||||||
| } else { | ||||||
| false | ||||||
| }; | ||||||
| Ok(res) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn member_evaluator(&self) -> &Rc<MemberSymbol> { | ||||||
|
|
@@ -182,49 +172,35 @@ impl BaseMeasure { | |||||
| &self.cube_name | ||||||
| } | ||||||
|
|
||||||
| pub fn reduce_by(&self) -> Option<Vec<String>> { | ||||||
| self.definition | ||||||
| .as_ref() | ||||||
| .and_then(|d| d.static_data().reduce_by_references.clone()) | ||||||
| } | ||||||
|
|
||||||
| pub fn add_group_by(&self) -> Option<Vec<String>> { | ||||||
| self.definition | ||||||
| .as_ref() | ||||||
| .and_then(|d| d.static_data().add_group_by_references.clone()) | ||||||
| } | ||||||
|
|
||||||
| pub fn group_by(&self) -> Option<Vec<String>> { | ||||||
| self.definition | ||||||
| .as_ref() | ||||||
| .and_then(|d| d.static_data().group_by_references.clone()) | ||||||
| } | ||||||
|
|
||||||
| //FIXME dublicate with symbol | ||||||
| pub fn is_calculated(&self) -> bool { | ||||||
| match self.measure_type() { | ||||||
| "number" | "string" | "time" | "boolean" => true, | ||||||
| _ => false, | ||||||
| if let Ok(measure_symbol) = self.member_evaluator.as_measure() { | ||||||
| measure_symbol.is_calculated() | ||||||
| } else { | ||||||
| true | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn time_shifts(&self) -> Vec<MeasureTimeShift> { | ||||||
| pub fn time_shift(&self) -> Option<MeasureTimeShifts> { | ||||||
| match self.member_evaluator.as_ref() { | ||||||
| MemberSymbol::Measure(measure_symbol) => measure_symbol.time_shifts().clone(), | ||||||
| _ => vec![], | ||||||
| MemberSymbol::Measure(measure_symbol) => measure_symbol.time_shift().clone(), | ||||||
| _ => None, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn is_multi_stage(&self) -> bool { | ||||||
| self.definition | ||||||
| .as_ref() | ||||||
| .is_some_and(|d| d.static_data().multi_stage.unwrap_or(false)) | ||||||
| if let Ok(measure_symbol) = self.member_evaluator.as_measure() { | ||||||
| measure_symbol.is_multi_stage() | ||||||
| } else { | ||||||
| false | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn rolling_window(&self) -> Option<RollingWindow> { | ||||||
| self.definition | ||||||
| .as_ref() | ||||||
| .and_then(|d| d.static_data().rolling_window.clone()) | ||||||
| if let Ok(measure_symbol) = self.member_evaluator.as_measure() { | ||||||
| measure_symbol.rolling_window().clone() | ||||||
| } else { | ||||||
| None | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn is_rolling_window(&self) -> bool { | ||||||
|
|
@@ -239,11 +215,12 @@ impl BaseMeasure { | |||||
| self.is_rolling_window() || self.is_running_total() | ||||||
| } | ||||||
|
|
||||||
| //FIXME dublicate with symbol | ||||||
| pub fn measure_type(&self) -> &str { | ||||||
| self.definition | ||||||
| .as_ref() | ||||||
| .map_or("number", |d| &d.static_data().measure_type) | ||||||
| pub fn measure_type(&self) -> String { | ||||||
| if let Ok(measure_symbol) = self.member_evaluator.as_measure() { | ||||||
| measure_symbol.measure_type().clone() | ||||||
| } else { | ||||||
| "number".to_string() | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| pub fn is_multi_stage_ungroupped(&self) -> bool { | ||||||
|
|
||||||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this to the upper scope and mark test(s) as skipped instead of making it pass while it does nothing?