Skip to content

WIP growth for postgres #111

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions tesseract-core/src/query_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,50 @@ impl DrilldownSql {
cols
}

pub fn col_alias_string2(&self) -> String {
let cols = self.col_alias_vec2();
join(cols, ", ")
}

fn col_alias_vec2(&self) -> Vec<String> {
let mut cols: Vec<_> = self.level_columns.iter()
.map(|l| {
if let Some(ref name_col) = l.name_column {
format!("{}.{} as {}_{}, {} as {}_{}",
self.table.name,
l.key_column,
l.key_column,
self.alias_postfix,
name_col,
name_col,
self.alias_postfix,
)
} else {
format!("{}.{} as {}_{}",
self.table.name,
l.key_column,
l.key_column,
self.alias_postfix,
)
}
}).collect();

if self.property_columns.len() != 0 {
cols.push(
join(&self.property_columns, ", ")
);
}

cols
}

pub fn col_alias_only_string(&self) -> String {
let cols = self.col_alias_only_vec();
join(cols, ", ")
}

pub fn col_alias_only_vec(&self) -> Vec<String> {
let mut cols = vec![];
let mut cols = vec![];

// can't just map the cols, because some levels
// produce two and some produce one
Expand Down Expand Up @@ -370,4 +407,3 @@ pub fn dim_subquery(drill: Option<&DrilldownSql>, cut: Option<&CutSql>) -> DimSu
dim_cols: None,
}
}

1 change: 1 addition & 0 deletions tesseract-postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tokio = "0.1"
bb8 = "0.3"
bb8-postgres = "0.3"
futures-state-stream = "0.2"
itertools = "0.8.0"

[dependencies.tesseract-core]
path = "../tesseract-core"
23 changes: 22 additions & 1 deletion tesseract-postgres/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use failure::{Error, format_err};
use tesseract_core::{Backend, DataFrame};
use tesseract_core::{Backend, DataFrame, QueryIr};
use futures::{Future, Stream};
use tokio_postgres::NoTls;
extern crate futures;
Expand All @@ -16,6 +16,10 @@ use futures::{
};

mod df;
mod sql;

use self::sql::postgres_sql;

use self::df::{rows_to_df};

#[derive(Clone)]
Expand Down Expand Up @@ -76,6 +80,23 @@ impl Backend for Postgres {
fn box_clone(&self) -> Box<dyn Backend + Send + Sync> {
Box::new((*self).clone())
}

fn generate_sql(&self, query_ir: QueryIr) -> String {
postgres_sql(
&query_ir.table,
&query_ir.cuts,
&query_ir.drills,
&query_ir.meas,
&query_ir.filters,
&query_ir.top,
&query_ir.top_where,
&query_ir.sort,
&query_ir.limit,
&query_ir.rca,
&query_ir.growth,
)
}

}


Expand Down
51 changes: 51 additions & 0 deletions tesseract-postgres/src/sql.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
mod aggregator;
mod growth;
mod options;
mod primary_agg;

use tesseract_core::query_ir::{
TableSql,
CutSql,
DrilldownSql,
MeasureSql,
TopSql,
TopWhereSql,
SortSql,
LimitSql,
RcaSql,
GrowthSql,
FilterSql,
dim_subquery,
};
use self::options::wrap_options;
use self::primary_agg::primary_agg;
use itertools::join;

/// Error checking is done before this point. This string formatter
/// accepts any input
pub fn postgres_sql(
table: &TableSql,
cuts: &[CutSql],
drills: &[DrilldownSql],
meas: &[MeasureSql],
filters: &[FilterSql],
// TODO put Filters and Calculations into own structs
top: &Option<TopSql>,
top_where: &Option<TopWhereSql>,
sort: &Option<SortSql>,
limit: &Option<LimitSql>,
rca: &Option<RcaSql>,
growth: &Option<GrowthSql>,
) -> String
{
let mut final_sql = primary_agg(table, cuts, drills, meas);

if let Some(growth) = growth {
let (sql, drill_cols) = growth::calculate(final_sql, drills, meas.len(), growth);
final_sql = sql;
}

final_sql = wrap_options(final_sql, drills, top, top_where, sort, limit, filters);

final_sql
}
Loading