Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed May 2, 2024
1 parent 31e98cb commit 25ee11b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
6 changes: 1 addition & 5 deletions nexus/analyzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,11 +922,7 @@ fn parse_db_options(db_type: DbType, with_options: &[SqlOption]) -> anyhow::Resu
.context("no port specified")?
.parse::<u32>()
.context("unable to parse port as valid int")?,
user: opts
.get("user")
.cloned()
.unwrap_or_default()
.to_string(),
user: opts.get("user").cloned().unwrap_or_default().to_string(),
password: opts
.get("password")
.cloned()
Expand Down
30 changes: 18 additions & 12 deletions nexus/peer-mysql/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ fn json_to_expr(val: JsonValue) -> Expr {
JsonValue::String(x) => Expr::Value(Value::SingleQuotedString(x)),
JsonValue::Array(x) => Expr::Array(Array {
elem: x.into_iter().map(json_to_expr).collect::<Vec<_>>(),
named: false
named: false,
}),
JsonValue::Object(x) => Expr::Cast {
data_type: DataType::JSON,
expr: Box::new(Expr::Value(Value::SingleQuotedString(JsonValue::Object(x).to_string()))),
expr: Box::new(Expr::Value(Value::SingleQuotedString(
JsonValue::Object(x).to_string(),
))),
format: None,
},
}
}

pub fn rewrite_query(peername: &str, query: &mut Query) {
visit_relations_mut(query, |table| {
if table.0.len() > 1 {
// if peer name is first part of table name, remove first part
if peername.eq_ignore_ascii_case(&table.0[0].value) {
table.0.remove(0);
} else if table.0[0].value == "public" {
table.0.remove(0);
}
// if peer name is first part of table name, remove first part
// remove `public.` to facilitate mysql global function push down
if table.0.len() > 1
&& (peername.eq_ignore_ascii_case(&table.0[0].value) || table.0[0].value == "public")
{
table.0.remove(0);
}
ControlFlow::<()>::Continue(())
});
Expand All @@ -57,16 +58,21 @@ pub fn rewrite_query(peername: &str, query: &mut Query) {
named: true,
};
*node = FunctionArgExpr::Expr(Expr::Array(rewritten_array));
} else if let Expr::Cast { data_type: DataType::JSONB, expr, .. } = arg_expr {
} else if let Expr::Cast {
data_type: DataType::JSONB,
expr,
..
} = arg_expr
{
*node = match **expr {
Expr::Value(Value::SingleQuotedString(ref s)) => {
if let Ok(val) = serde_json::from_str::<JsonValue>(s) {
FunctionArgExpr::Expr(json_to_expr(val))
} else {
FunctionArgExpr::Expr((**expr).clone())
}
},
_ => FunctionArgExpr::Expr((**expr).clone())
}
_ => FunctionArgExpr::Expr((**expr).clone()),
};
}
}
Expand Down

0 comments on commit 25ee11b

Please sign in to comment.