Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
andicuko committed Sep 30, 2024
1 parent 8118e88 commit a20e6a7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
10 changes: 7 additions & 3 deletions src/dialect_translation/bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,11 @@ impl RelationToQueryTranslator for BigQueryTranslator {
left: ast::Select,
right: ast::Select,
) -> ast::Query {

// UNION in big query must use a quantifier that can be either
// ALL or Distinct.
let translated_quantifier = match quantifier {
ast::SetQuantifier::All => ast::SetQuantifier::All,
_ => ast::SetQuantifier::Distinct
_ => ast::SetQuantifier::Distinct,
};
ast::Query {
with: (!with.is_empty()).then_some(ast::With {
Expand Down Expand Up @@ -158,7 +157,12 @@ mod tests {

use super::*;
use crate::{
builder::{Ready, With}, data_type::DataType, dialect_translation::RelationWithTranslator, expr::Expr, namer, relation::{schema::Schema, Relation},
builder::{Ready, With},
data_type::DataType,
dialect_translation::RelationWithTranslator,
expr::Expr,
namer,
relation::{schema::Schema, Relation},
};
use std::sync::Arc;

Expand Down
2 changes: 1 addition & 1 deletion src/dialect_translation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ pub trait QueryToRelationTranslator {
// checking the identifier
let _ = self.try_identifier(ident)?;
expr::Expr::try_from(expr.with(context))
},
}
_ => expr::Expr::try_from(expr.with(context)),
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/dialect_translation/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ impl QueryToRelationTranslator for MySqlTranslator {
"from_base64" => try_encode_decode(converted, EncodeDecodeFormat::Base64),
"hex" => try_encode(converted, EncodeDecodeFormat::Hex),
"to_base64" => try_encode(converted, EncodeDecodeFormat::Base64),
"rand" => Ok(expr::Expr::random(0)),
_ => {
let expr = ast::Expr::Function(func.clone());
expr::Expr::try_from(expr.with(context))
Expand Down Expand Up @@ -279,18 +278,14 @@ fn try_encode(exprs: Vec<expr::Expr>, format: EncodeDecodeFormat) -> Result<expr
#[cfg(test)]
#[cfg(feature = "mysql")]
mod tests {
use base64::display;
use itertools::Itertools as _;

use super::*;
use crate::{
builder::{Ready, With},
dialect_translation::{postgresql::PostgreSqlTranslator, RelationWithTranslator},
display::Dot,
io::{mysql, postgresql, Database as _},
namer,
relation::{schema::Schema, Relation},
sql::{self, parse, relation::QueryWithRelations},
relation::Relation,
sql::{self, relation::QueryWithRelations},
};

fn try_from_mssql_query(
Expand Down
26 changes: 12 additions & 14 deletions src/dialect_translation/postgresql.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{expr::{self, Identifier}, hierarchy::Hierarchy, WithoutContext as _};
use crate::{
expr::{self, Identifier},
hierarchy::Hierarchy,
WithoutContext as _,
};

use super::{function_builder, QueryToRelationTranslator, RelationToQueryTranslator};
use crate::sql::{Error, Result};
Expand Down Expand Up @@ -109,19 +113,13 @@ impl QueryToRelationTranslator for PostgreSqlTranslator {
let function_name: &str = &func.name.0.iter().next().unwrap().value.to_lowercase()[..];

match function_name {
"rand" |
"unhex" |
"from_hex" |
"choose" |
"newid" |
"dayname" |
"date_format" |
"quarter" |
"datetime_diff" |
"date" |
"from_unixtime" |
"unix_timestamp"
=> Err(Error::ParsingError(format!("`{}` is not a postgres function", function_name.to_uppercase()))),
"rand" | "unhex" | "from_hex" | "choose" | "newid" | "dayname" | "date_format"
| "quarter" | "datetime_diff" | "date" | "from_unixtime" | "unix_timestamp" => {
Err(Error::ParsingError(format!(
"`{}` is not a postgres function",
function_name.to_uppercase()
)))
}
_ => {
let expr = ast::Expr::Function(func.clone());
expr::Expr::try_from(expr.with(context))
Expand Down
1 change: 0 additions & 1 deletion src/relation/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ fn select_from_query(query: ast::Query) -> ast::Select {
}
}


impl<'a, T: RelationToQueryTranslator> Visitor<'a, ast::Query> for FromRelationVisitor<T> {
fn table(&self, table: &'a Table) -> ast::Query {
self.translator.query(
Expand Down

0 comments on commit a20e6a7

Please sign in to comment.