Skip to content
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

Flatten case #285

Merged
merged 8 commits into from
Jul 10, 2024
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.9.22] - 2024-07-9
### Changed
- When translating relations to queries transform all nested CASE expressions into a single CASE

## [0.9.21] - 2024-06-27
### Changed
- Add integer domains to few boolean functions to reduce timing of fun.super_image
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Nicolas Grislain <[email protected]>"]
name = "qrlew"
version = "0.9.21"
version = "0.9.22"
edition = "2021"
description = "Sarus Qrlew Engine"
documentation = "https://docs.rs/qrlew"
Expand Down
44 changes: 18 additions & 26 deletions src/dialect_translation/bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,52 +28,44 @@ impl RelationToQueryTranslator for BigQueryTranslator {
materialized: None,
}
}
fn first(&self, expr: &expr::Expr) -> ast::Expr {
ast::Expr::from(expr)
fn first(&self, expr: ast::Expr) -> ast::Expr {
expr
}

fn mean(&self, expr: &expr::Expr) -> ast::Expr {
let arg = self.expr(expr);
function_builder("AVG", vec![arg], false)
fn mean(&self, expr: ast::Expr) -> ast::Expr {
function_builder("AVG", vec![expr], false)
}

fn var(&self, expr: &expr::Expr) -> ast::Expr {
let arg = self.expr(expr);
function_builder("VARIANCE", vec![arg], false)
fn var(&self, expr: ast::Expr) -> ast::Expr {
function_builder("VARIANCE", vec![expr], false)
}

fn std(&self, expr: &expr::Expr) -> ast::Expr {
let arg = self.expr(expr);
function_builder("STDDEV", vec![arg], false)
fn std(&self, expr: ast::Expr) -> ast::Expr {
function_builder("STDDEV", vec![expr], false)
}
/// Converting LOG to LOG10
fn log(&self, expr: &expr::Expr) -> ast::Expr {
let arg = self.expr(expr);
function_builder("LOG10", vec![arg], false)
fn log(&self, expr: ast::Expr) -> ast::Expr {
function_builder("LOG10", vec![expr], false)
}
fn cast_as_text(&self, expr: &expr::Expr) -> ast::Expr {
let ast_expr = self.expr(expr);
fn cast_as_text(&self, expr: ast::Expr) -> ast::Expr {
ast::Expr::Cast {
expr: Box::new(ast_expr),
expr: Box::new(expr),
data_type: ast::DataType::String(None),
format: None,
kind: ast::CastKind::Cast,
}
}
fn substr(&self, exprs: Vec<&expr::Expr>) -> ast::Expr {
fn substr(&self, exprs: Vec<ast::Expr>) -> ast::Expr {
assert!(exprs.len() == 2);
let ast_exprs: Vec<ast::Expr> = exprs.into_iter().map(|expr| self.expr(expr)).collect();
function_builder("SUBSTR", ast_exprs, false)
function_builder("SUBSTR", exprs, false)
}
fn substr_with_size(&self, exprs: Vec<&expr::Expr>) -> ast::Expr {
fn substr_with_size(&self, exprs: Vec<ast::Expr>) -> ast::Expr {
assert!(exprs.len() == 3);
let ast_exprs: Vec<ast::Expr> = exprs.into_iter().map(|expr| self.expr(expr)).collect();
function_builder("SUBSTR", ast_exprs, false)
function_builder("SUBSTR", exprs, false)
}
/// Converting MD5(X) to TO_HEX(MD5(X))
fn md5(&self, expr: &expr::Expr) -> ast::Expr {
let ast_expr = self.expr(expr);
let md5_function = function_builder("MD5", vec![ast_expr], false);
fn md5(&self, expr: ast::Expr) -> ast::Expr {
let md5_function = function_builder("MD5", vec![expr], false);
function_builder("TO_HEX", vec![md5_function], false)
}
fn random(&self) -> ast::Expr {
Expand Down
Loading
Loading