-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(tesseract): Logical plan #9497
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
+3,322
−1,185
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod cube_bridge; | ||
pub mod logical_plan; | ||
pub mod physical_plan_builder; | ||
pub mod plan; | ||
pub mod planner; |
48 changes: 48 additions & 0 deletions
48
rust/cubesqlplanner/cubesqlplanner/src/logical_plan/aggregate_multiplied_subquery.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use super::pretty_print::*; | ||
use super::*; | ||
use crate::planner::BaseCube; | ||
use std::rc::Rc; | ||
|
||
pub enum AggregateMultipliedSubquerySouce { | ||
Cube, | ||
MeasureSubquery(Rc<MeasureSubquery>), | ||
} | ||
|
||
pub struct AggregateMultipliedSubquery { | ||
pub schema: Rc<LogicalSchema>, | ||
pub dimension_subqueries: Vec<Rc<DimensionSubQuery>>, | ||
pub keys_subquery: Rc<KeysSubQuery>, | ||
pub pk_cube: Rc<BaseCube>, //FIXME may be duplication with information in keys_subquery | ||
pub source: Rc<AggregateMultipliedSubquerySouce>, | ||
} | ||
|
||
impl PrettyPrint for AggregateMultipliedSubquery { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
result.println("AggregateMultipliedSubquery: ", state); | ||
let state = state.new_level(); | ||
let details_state = state.new_level(); | ||
result.println("schema:", &state); | ||
self.schema.pretty_print(result, &details_state); | ||
if !self.dimension_subqueries.is_empty() { | ||
result.println("dimension_subqueries:", &state); | ||
for subquery in self.dimension_subqueries.iter() { | ||
subquery.pretty_print(result, &details_state); | ||
} | ||
} | ||
result.println("keys_subquery:", &state); | ||
self.keys_subquery.pretty_print(result, &details_state); | ||
result.println("source:", &state); | ||
match self.source.as_ref() { | ||
AggregateMultipliedSubquerySouce::Cube => { | ||
result.println(&format!("Cube: {}", self.pk_cube.name()), &details_state); | ||
} | ||
AggregateMultipliedSubquerySouce::MeasureSubquery(measure_subquery) => { | ||
result.println( | ||
&format!("MeasureSubquery: {}", measure_subquery.measures.len()), | ||
&details_state, | ||
); | ||
measure_subquery.pretty_print(result, &details_state); | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
rust/cubesqlplanner/cubesqlplanner/src/logical_plan/cube.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::planner::BaseCube; | ||
use std::rc::Rc; | ||
#[derive(Clone)] | ||
pub struct Cube { | ||
pub name: String, | ||
pub cube: Rc<BaseCube>, | ||
} | ||
|
||
impl Cube { | ||
pub fn new(cube: Rc<BaseCube>) -> Rc<Self> { | ||
Rc::new(Self { | ||
name: cube.name().clone(), | ||
cube, | ||
}) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
rust/cubesqlplanner/cubesqlplanner/src/logical_plan/dimension_subquery.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use super::pretty_print::*; | ||
use super::*; | ||
use crate::planner::sql_evaluator::MemberSymbol; | ||
use std::rc::Rc; | ||
|
||
pub struct DimensionSubQuery { | ||
pub query: Rc<Query>, | ||
pub primary_keys_dimensions: Vec<Rc<MemberSymbol>>, | ||
pub subquery_dimension: Rc<MemberSymbol>, | ||
pub measure_for_subquery_dimension: Rc<MemberSymbol>, | ||
} | ||
|
||
impl PrettyPrint for DimensionSubQuery { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
result.println("DimensionSubQuery: ", state); | ||
let state = state.new_level(); | ||
let details_state = state.new_level(); | ||
result.println(&format!("query: "), &state); | ||
self.query.pretty_print(result, &details_state); | ||
result.println( | ||
&format!( | ||
"-primary_keys_dimensions: {}", | ||
print_symbols(&self.primary_keys_dimensions) | ||
), | ||
&state, | ||
); | ||
result.println( | ||
&format!( | ||
"-subquery_dimension: {}", | ||
self.subquery_dimension.full_name() | ||
), | ||
&state, | ||
); | ||
result.println( | ||
&format!( | ||
"-measure_for_subquery_dimension: {}", | ||
self.measure_for_subquery_dimension.full_name() | ||
), | ||
&state, | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
rust/cubesqlplanner/cubesqlplanner/src/logical_plan/filter.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use super::pretty_print::*; | ||
use crate::plan::{Filter, FilterItem}; | ||
use itertools::Itertools; | ||
|
||
pub struct LogicalFilter { | ||
pub dimensions_filters: Vec<FilterItem>, | ||
pub time_dimensions_filters: Vec<FilterItem>, | ||
pub measures_filter: Vec<FilterItem>, | ||
pub segments: Vec<FilterItem>, | ||
} | ||
|
||
impl LogicalFilter { | ||
pub fn all_filters(&self) -> Option<Filter> { | ||
let items = self | ||
.time_dimensions_filters | ||
.iter() | ||
.chain(self.dimensions_filters.iter()) | ||
.chain(self.segments.iter()) | ||
.cloned() | ||
.collect_vec(); | ||
if items.is_empty() { | ||
None | ||
} else { | ||
Some(Filter { items }) | ||
} | ||
} | ||
} | ||
|
||
impl PrettyPrint for LogicalFilter { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
let details_state = state.new_level(); | ||
result.println("dimensions_filters:", &state); | ||
for filter in self.dimensions_filters.iter() { | ||
pretty_print_filter_item(result, &details_state, filter); | ||
} | ||
result.println("time_dimensions_filters:", &state); | ||
for filter in self.time_dimensions_filters.iter() { | ||
pretty_print_filter_item(result, &details_state, filter); | ||
} | ||
result.println("measures_filter:", &state); | ||
for filter in self.measures_filter.iter() { | ||
pretty_print_filter_item(result, &details_state, filter); | ||
} | ||
result.println("segments:", &state); | ||
for filter in self.segments.iter() { | ||
pretty_print_filter_item(result, &details_state, filter); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
rust/cubesqlplanner/cubesqlplanner/src/logical_plan/full_key_aggregate.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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use super::*; | ||
use crate::planner::sql_evaluator::MemberSymbol; | ||
use std::rc::Rc; | ||
|
||
pub struct MultiStageSubqueryRef { | ||
pub name: String, | ||
} | ||
|
||
impl PrettyPrint for MultiStageSubqueryRef { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
result.println(&format!("MultiStageSubqueryRef: {}", self.name), state); | ||
} | ||
} | ||
|
||
pub enum FullKeyAggregateSource { | ||
ResolveMultipliedMeasures(Rc<ResolveMultipliedMeasures>), | ||
MultiStageSubqueryRef(Rc<MultiStageSubqueryRef>), | ||
} | ||
|
||
impl PrettyPrint for FullKeyAggregateSource { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
match self { | ||
Self::ResolveMultipliedMeasures(resolve_multiplied_measures) => { | ||
resolve_multiplied_measures.pretty_print(result, state); | ||
} | ||
Self::MultiStageSubqueryRef(subquery_ref) => { | ||
subquery_ref.pretty_print(result, state); | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub struct FullKeyAggregate { | ||
pub join_dimensions: Vec<Rc<MemberSymbol>>, | ||
pub use_full_join_and_coalesce: bool, | ||
pub sources: Vec<FullKeyAggregateSource>, | ||
} | ||
|
||
impl PrettyPrint for FullKeyAggregate { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
result.println("FullKeyAggregate: ", state); | ||
let state = state.new_level(); | ||
let details_state = state.new_level(); | ||
result.println( | ||
&format!("join_dimensions: {}", print_symbols(&self.join_dimensions)), | ||
&state, | ||
); | ||
result.println( | ||
&format!( | ||
"use_full_join_and_coalesce: {}", | ||
self.use_full_join_and_coalesce | ||
), | ||
&state, | ||
); | ||
result.println("sources:", &state); | ||
for source in self.sources.iter() { | ||
source.pretty_print(result, &details_state); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
rust/cubesqlplanner/cubesqlplanner/src/logical_plan/full_key_aggregate_query.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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use super::*; | ||
use crate::planner::query_properties::OrderByItem; | ||
use std::rc::Rc; | ||
|
||
pub struct FullKeyAggregateQuery { | ||
pub multistage_members: Vec<Rc<LogicalMultiStageMember>>, | ||
pub schema: Rc<LogicalSchema>, | ||
pub filter: Rc<LogicalFilter>, | ||
pub offset: Option<usize>, | ||
pub limit: Option<usize>, | ||
pub ungrouped: bool, | ||
pub order_by: Vec<OrderByItem>, | ||
pub source: Rc<FullKeyAggregate>, | ||
} | ||
|
||
impl PrettyPrint for FullKeyAggregateQuery { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
result.println("FullKeyAggregateQuery: ", state); | ||
let state = state.new_level(); | ||
let details_state = state.new_level(); | ||
if !self.multistage_members.is_empty() { | ||
result.println("multistage_members:", &state); | ||
for member in self.multistage_members.iter() { | ||
member.pretty_print(result, &details_state); | ||
} | ||
} | ||
|
||
result.println("schema:", &state); | ||
self.schema.pretty_print(result, &details_state); | ||
result.println("filter:", &state); | ||
self.filter.pretty_print(result, &details_state); | ||
if let Some(offset) = &self.offset { | ||
result.println(&format!("offset:{}", offset), &state); | ||
} | ||
if let Some(limit) = &self.limit { | ||
result.println(&format!("limit:{}", limit), &state); | ||
} | ||
result.println(&format!("ungrouped:{}", self.ungrouped), &state); | ||
if !self.order_by.is_empty() { | ||
result.println("order_by:", &state); | ||
for order_by in self.order_by.iter() { | ||
result.println( | ||
&format!( | ||
"{} {}", | ||
order_by.name(), | ||
if order_by.desc() { "desc" } else { "asc" } | ||
), | ||
&details_state, | ||
); | ||
} | ||
} | ||
result.println("source:", &state); | ||
self.source.pretty_print(result, &details_state); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
rust/cubesqlplanner/cubesqlplanner/src/logical_plan/join.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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use super::pretty_print::*; | ||
use super::Cube; | ||
use super::SimpleQuery; | ||
use crate::planner::sql_evaluator::{MemberSymbol, SqlCall}; | ||
use std::rc::Rc; | ||
|
||
#[derive(Clone)] | ||
pub struct CubeJoinItem { | ||
pub cube: Rc<Cube>, | ||
pub on_sql: Rc<SqlCall>, | ||
} | ||
|
||
impl PrettyPrint for CubeJoinItem { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
result.println(&format!("CubeJoinItem for cube: {}", self.cube.name), state); | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct SubqueryDimensionJoinItem { | ||
pub subquery: Rc<SimpleQuery>, | ||
pub dimension: Rc<MemberSymbol>, | ||
pub primary_keys_dimensions: Vec<Rc<MemberSymbol>>, | ||
} | ||
|
||
impl PrettyPrint for SubqueryDimensionJoinItem { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
result.println( | ||
&format!( | ||
"SubqueryDimensionJoinItem for dimension `{}`: ", | ||
self.dimension.full_name() | ||
), | ||
state, | ||
); | ||
result.println("subquery:", state); | ||
result.println("primary_keys_dimensions:", state); | ||
let state = state.new_level(); | ||
for dim in self.primary_keys_dimensions.iter() { | ||
result.println(&format!("- {}", dim.full_name()), &state); | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub enum LogicalJoinItem { | ||
CubeJoinItem(CubeJoinItem), | ||
} | ||
|
||
impl PrettyPrint for LogicalJoinItem { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
match self { | ||
LogicalJoinItem::CubeJoinItem(item) => item.pretty_print(result, state), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct LogicalJoin { | ||
pub root: Rc<Cube>, | ||
pub joins: Vec<LogicalJoinItem>, | ||
} | ||
|
||
impl PrettyPrint for LogicalJoin { | ||
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) { | ||
result.println(&format!("Join: "), state); | ||
let state = state.new_level(); | ||
result.println(&format!("root: {}", self.root.name), &state); | ||
result.println(&format!("joins: "), &state); | ||
let state = state.new_level(); | ||
for join in self.joins.iter() { | ||
join.pretty_print(result, &state); | ||
} | ||
} | ||
} |
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.
Are any new variants expected or planned here?
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.
Yep, PreAggregationSource for example.
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.
Yep, pre aggregation for example