Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
Andi Cuko committed Sep 30, 2024
1 parent 33e81b5 commit 53e9c8b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/dialect_translation/hive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sqlparser::{ast, dialect::HiveDialect};
pub struct HiveTranslator;

// Using the same translations as in bigquery since it should be similar.
// HiveTranslator is not tested at the moment.
// HiveTranslator is not well tested at the moment.
impl RelationToQueryTranslator for HiveTranslator {
fn identifier(&self, value: &expr::Identifier) -> Vec<ast::Ident> {
value
Expand Down Expand Up @@ -109,6 +109,41 @@ impl RelationToQueryTranslator for HiveTranslator {
};
function_builder("UNIX_SECONDS", vec![cast], false)
}

fn set_operation(
&self,
with: Vec<ast::Cte>,
operator: ast::SetOperator,
quantifier: ast::SetQuantifier,
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::Query {
with: (!with.is_empty()).then_some(ast::With {
recursive: false,
cte_tables: with,
}),
body: Box::new(ast::SetExpr::SetOperation {
op: operator,
set_quantifier: translated_quantifier,
left: Box::new(ast::SetExpr::Select(Box::new(left))),
right: Box::new(ast::SetExpr::Select(Box::new(right))),
}),
order_by: vec![],
limit: None,
offset: None,
fetch: None,
locks: vec![],
limit_by: vec![],
for_clause: None,
}
}
}

impl QueryToRelationTranslator for HiveTranslator {
Expand Down
12 changes: 12 additions & 0 deletions src/dialect_translation/mssql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,18 @@ impl RelationToQueryTranslator for MsSqlTranslator {
options: None,
}
}

fn format_float_value(&self, value: f64) -> ast::Expr {
let max_precision = 37;
let formatted = if value.abs() < 1e-10 || value.abs() > 1e10 {
// If the value is too small or too large, switch to scientific notation
format!("{:.precision$e}", value, precision = max_precision)
} else {
// Otherwise, use the default float formatting with the specified precision
format!("{}", value)
};
ast::Expr::Value(ast::Value::Number(formatted, false))
}
}

impl QueryToRelationTranslator for MsSqlTranslator {
Expand Down

0 comments on commit 53e9c8b

Please sign in to comment.