Skip to content

Commit 3c67aac

Browse files
committed
feat(tesseract): Logical plan
1 parent 4697600 commit 3c67aac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3227
-51
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
pub mod cube_bridge;
2+
pub mod logical_plan;
3+
pub mod physical_plan_builder;
24
pub mod plan;
35
pub mod planner;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use super::pretty_print::*;
2+
use super::LogicalFilter;
3+
use super::LogicalJoin;
4+
use super::*;
5+
use crate::plan::{Expr, Filter, FilterItem, MemberExpression};
6+
use crate::planner::sql_evaluator::MemberSymbol;
7+
use crate::planner::query_properties::OrderByItem;
8+
use std::rc::Rc;
9+
10+
pub enum AggregateMultipliedSubquerySouce {
11+
Cube(Rc<Cube>)
12+
}
13+
14+
impl PrettyPrint for AggregateMultipliedSubquerySouce {
15+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
16+
match self {
17+
AggregateMultipliedSubquerySouce::Cube(cube) => {
18+
result.println(&format!("Cube: {}", cube.cube.name()), state);
19+
}
20+
}
21+
}
22+
}
23+
24+
25+
26+
pub struct AggregateMultipliedSubquery {
27+
pub schema: Rc<LogicalSchema>,
28+
pub dimension_subqueries: Vec<Rc<DimensionSubQuery>>,
29+
pub keys_subquery: Rc<KeysSubQuery>,
30+
pub source: Rc<AggregateMultipliedSubquerySouce>,
31+
32+
}
33+
34+
impl PrettyPrint for AggregateMultipliedSubquery {
35+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
36+
result.println("AggregateMultipliedSubquery: ", state);
37+
let state = state.new_level();
38+
let details_state = state.new_level();
39+
result.println("schema:", &state);
40+
self.schema.pretty_print(result, &details_state);
41+
if !self.dimension_subqueries.is_empty() {
42+
result.println("dimension_subqueries:", &state);
43+
for subquery in self.dimension_subqueries.iter() {
44+
subquery.pretty_print(result, &details_state);
45+
}
46+
}
47+
result.println("keys_subquery:", &state);
48+
self.keys_subquery.pretty_print(result, &details_state);
49+
result.println("source:", &state);
50+
self.source.pretty_print(result, &details_state);
51+
52+
}
53+
}
54+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use crate::planner::BaseCube;
2+
use std::rc::Rc;
3+
#[derive(Clone)]
4+
pub struct Cube {
5+
pub name: String,
6+
pub cube: Rc<BaseCube>,
7+
}
8+
9+
impl Cube {
10+
pub fn new(cube: Rc<BaseCube>) -> Rc<Self> {
11+
Rc::new(Self {
12+
name: cube.name().clone(),
13+
cube,
14+
})
15+
}
16+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use super::pretty_print::*;
2+
use super::*;
3+
use super::LogicalSchema;
4+
use crate::plan::{Expr, Filter, FilterItem, MemberExpression};
5+
use crate::planner::sql_evaluator::MemberSymbol;
6+
use std::rc::Rc;
7+
8+
pub struct DimensionSubQuery {
9+
pub query: Rc<Query>,
10+
pub primary_keys_dimensions: Vec<Rc<MemberSymbol>>,
11+
pub subquery_dimension: Rc<MemberSymbol>,
12+
pub measure_for_subquery_dimension: Rc<MemberSymbol>,
13+
}
14+
15+
impl PrettyPrint for DimensionSubQuery {
16+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
17+
result.println("DimensionSubQuery: ", state);
18+
let state = state.new_level();
19+
let details_state = state.new_level();
20+
result.println(&format!("query: "), &state);
21+
self.query.pretty_print(result, &details_state);
22+
result.println(
23+
&format!("-primary_keys_dimensions: {}", print_symbols(&self.primary_keys_dimensions)),
24+
&state,
25+
);
26+
result.println(&format!("-subquery_dimension: {}", self.subquery_dimension.full_name()), &state);
27+
result.println(&format!("-measure_for_subquery_dimension: {}", self.measure_for_subquery_dimension.full_name()), &state);
28+
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use super::pretty_print::*;
2+
use crate::plan::{Expr, Filter, FilterItem, MemberExpression};
3+
use crate::planner::sql_evaluator::MemberSymbol;
4+
use std::rc::Rc;
5+
use itertools::Itertools;
6+
7+
pub struct LogicalFilter {
8+
pub dimensions_filters: Vec<FilterItem>,
9+
pub time_dimensions_filters: Vec<FilterItem>,
10+
pub measures_filter: Vec<FilterItem>,
11+
pub segments: Vec<FilterItem>,
12+
}
13+
14+
impl LogicalFilter {
15+
pub fn all_filters(&self) -> Option<Filter> {
16+
let items = self
17+
.time_dimensions_filters
18+
.iter()
19+
.chain(self.dimensions_filters.iter())
20+
.chain(self.segments.iter())
21+
.cloned()
22+
.collect_vec();
23+
if items.is_empty() {
24+
None
25+
} else {
26+
Some(Filter { items })
27+
}
28+
}
29+
}
30+
31+
impl PrettyPrint for LogicalFilter {
32+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
33+
let details_state = state.new_level();
34+
result.println("dimensions_filters:", &state);
35+
for filter in self.dimensions_filters.iter() {
36+
pretty_print_filter_item(result, &details_state, filter);
37+
}
38+
result.println("time_dimensions_filters:", &state);
39+
for filter in self.time_dimensions_filters.iter() {
40+
pretty_print_filter_item(result, &details_state, filter);
41+
}
42+
result.println("measures_filter:", &state);
43+
for filter in self.measures_filter.iter() {
44+
pretty_print_filter_item(result, &details_state, filter);
45+
}
46+
result.println("segments:", &state);
47+
for filter in self.segments.iter() {
48+
pretty_print_filter_item(result, &details_state, filter);
49+
}
50+
}
51+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use super::*;
2+
use crate::plan::{Expr, Filter, FilterItem, MemberExpression};
3+
use crate::planner::sql_evaluator::MemberSymbol;
4+
use crate::planner::query_properties::OrderByItem;
5+
use std::rc::Rc;
6+
7+
pub struct MultiStageSubqueryRef {
8+
pub name: String
9+
}
10+
11+
impl PrettyPrint for MultiStageSubqueryRef {
12+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
13+
result.println(&format!("MultiStageSubqueryRef: {}", self.name), state);
14+
}
15+
}
16+
17+
18+
pub enum FullKeyAggregateSource {
19+
ResolveMultipliedMeasures(Rc<ResolveMultipliedMeasures>),
20+
MultiStageSubqueryRef(Rc<MultiStageSubqueryRef>)
21+
}
22+
23+
impl PrettyPrint for FullKeyAggregateSource {
24+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
25+
match self {
26+
Self::ResolveMultipliedMeasures(resolve_multiplied_measures) => {
27+
resolve_multiplied_measures.pretty_print(result, state);
28+
}
29+
Self::MultiStageSubqueryRef(subquery_ref) => {
30+
subquery_ref.pretty_print(result, state);
31+
}
32+
}
33+
}
34+
}
35+
36+
pub struct FullKeyAggregate {
37+
pub join_dimensions: Vec<Rc<MemberSymbol>>,
38+
pub sources: Vec<FullKeyAggregateSource>
39+
}
40+
41+
impl PrettyPrint for FullKeyAggregate {
42+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
43+
result.println("FullKeyAggregate: ", state);
44+
let state = state.new_level();
45+
let details_state = state.new_level();
46+
result.println(
47+
&format!("join_dimensions: {}", print_symbols(&self.join_dimensions)),
48+
&state,
49+
);
50+
result.println("sources:", &state);
51+
for source in self.sources.iter() {
52+
source.pretty_print(result, &details_state);
53+
}
54+
}
55+
}
56+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use super::*;
2+
use std::rc::Rc;
3+
use crate::planner::query_properties::OrderByItem;
4+
5+
pub struct FullKeyAggregateQuery {
6+
pub multistage_members: Vec<Rc<LogicalMultiStageMember>>,
7+
pub schema: Rc<LogicalSchema>,
8+
pub filter: Rc<LogicalFilter>,
9+
pub offset: Option<usize>,
10+
pub limit: Option<usize>,
11+
pub ungrouped: bool,
12+
pub order_by: Vec<OrderByItem>,
13+
pub source: Rc<FullKeyAggregate>,
14+
}
15+
16+
impl PrettyPrint for FullKeyAggregateQuery {
17+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
18+
result.println("FullKeyAggregateQuery: ", state);
19+
let state = state.new_level();
20+
let details_state = state.new_level();
21+
if !self.multistage_members.is_empty() {
22+
result.println("multistage_members:", &state);
23+
for member in self.multistage_members.iter() {
24+
member.pretty_print(result, &details_state);
25+
}
26+
}
27+
28+
result.println("schema:", &state);
29+
self.schema.pretty_print(result, &details_state);
30+
result.println("filter:", &state);
31+
self.filter.pretty_print(result, &details_state);
32+
if let Some(offset) = &self.offset {
33+
result.println(&format!("offset:{}", offset), &state);
34+
}
35+
if let Some(limit) = &self.limit {
36+
result.println(&format!("limit:{}", limit), &state);
37+
}
38+
result.println(&format!("ungrouped:{}", self.ungrouped), &state);
39+
if !self.order_by.is_empty() {
40+
result.println("order_by:", &state);
41+
for order_by in self.order_by.iter() {
42+
result.println(&format!("{} {}", order_by.name(), if order_by.desc() { "desc" } else { "asc" }), &details_state);
43+
}
44+
}
45+
result.println("source:", &state);
46+
self.source.pretty_print(result, &details_state);
47+
}
48+
}
49+
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use super::pretty_print::*;
2+
use super::Cube;
3+
use super::SimpleQuery;
4+
use crate::planner::sql_evaluator::{MemberSymbol, SqlCall};
5+
use std::rc::Rc;
6+
7+
#[derive(Clone)]
8+
pub struct CubeJoinItem {
9+
pub cube: Rc<Cube>,
10+
pub on_sql: Rc<SqlCall>,
11+
}
12+
13+
impl PrettyPrint for CubeJoinItem {
14+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
15+
result.println(&format!("CubeJoinItem for cube: {}", self.cube.name), state);
16+
}
17+
}
18+
19+
#[derive(Clone)]
20+
pub struct SubqueryDimensionJoinItem {
21+
pub subquery: Rc<SimpleQuery>,
22+
pub dimension: Rc<MemberSymbol>,
23+
pub primary_keys_dimensions: Vec<Rc<MemberSymbol>>,
24+
}
25+
26+
impl PrettyPrint for SubqueryDimensionJoinItem {
27+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
28+
result.println(
29+
&format!(
30+
"SubqueryDimensionJoinItem for dimension `{}`: ",
31+
self.dimension.full_name()
32+
),
33+
state,
34+
);
35+
result.println("subquery:", state);
36+
result.println("primary_keys_dimensions:", state);
37+
let state = state.new_level();
38+
for dim in self.primary_keys_dimensions.iter() {
39+
result.println(&format!("- {}", dim.full_name()), &state);
40+
}
41+
}
42+
}
43+
44+
#[derive(Clone)]
45+
pub enum LogicalJoinItem {
46+
CubeJoinItem(CubeJoinItem),
47+
}
48+
49+
impl PrettyPrint for LogicalJoinItem {
50+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
51+
match self {
52+
LogicalJoinItem::CubeJoinItem(item) => item.pretty_print(result, state),
53+
}
54+
}
55+
}
56+
57+
#[derive(Clone)]
58+
pub struct LogicalJoin {
59+
pub root: Rc<Cube>,
60+
pub joins: Vec<LogicalJoinItem>,
61+
}
62+
63+
impl PrettyPrint for LogicalJoin {
64+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
65+
result.println(&format!("Join: "), state);
66+
let state = state.new_level();
67+
result.println(&format!("root: {}", self.root.name), &state);
68+
result.println(&format!("joins: "), &state);
69+
let state = state.new_level();
70+
for join in self.joins.iter() {
71+
join.pretty_print(result, &state);
72+
}
73+
}
74+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use super::*;
2+
use crate::planner::sql_evaluator::MemberSymbol;
3+
use std::rc::Rc;
4+
5+
#[derive(Clone)]
6+
pub struct KeysSubQuery {
7+
pub key_cube_name: String,
8+
pub time_dimensions: Vec<Rc<MemberSymbol>>,
9+
pub dimensions: Vec<Rc<MemberSymbol>>,
10+
pub dimension_subqueries: Vec<Rc<DimensionSubQuery>>,
11+
pub primary_keys_dimensions: Vec<Rc<MemberSymbol>>,
12+
pub filter: Rc<LogicalFilter>,
13+
pub source: Rc<LogicalJoin>,
14+
}
15+
16+
impl PrettyPrint for KeysSubQuery {
17+
fn pretty_print(&self, result: &mut PrettyPrintResult, state: &PrettyPrintState) {
18+
result.println("KeysSubQuery: ", state);
19+
let state = state.new_level();
20+
let details_state = state.new_level();
21+
result.println(&format!("-key_cube_name: {}", self.key_cube_name), &state);
22+
result.println(
23+
&format!("-time_dimensions: {}", print_symbols(&self.time_dimensions)),
24+
&state,
25+
);
26+
result.println(
27+
&format!("-dimensions: {}", print_symbols(&self.dimensions)),
28+
&state,
29+
);
30+
/* if !self.dimension_subqueries.is_empty() {
31+
result.println("dimension_subqueries:", &state);
32+
for subquery in self.dimension_subqueries.iter() {
33+
subquery.pretty_print(result, &details_state);
34+
}
35+
} */
36+
result.println(
37+
&format!("-primary_keys_dimensions: {}", print_symbols(&self.primary_keys_dimensions)),
38+
&state,
39+
);
40+
result.println("filters:", &state);
41+
self.filter.pretty_print(result, &details_state);
42+
result.println("source:", &state);
43+
self.source.pretty_print(result, &details_state);
44+
}
45+
}

0 commit comments

Comments
 (0)