jumpwire-db-gateway
jumpwire-db-gateway copied to clipboard
SQL expr variants are lost when converting from Rust to Elixir
For example, the query select a from foo where a > any(b) gets parsed by sqlparser into:
[Query(Query { with: None, body: Select(Select { distinct: None, top: None, projection: [UnnamedExpr(Identifier(Ident { value: "a", quote_style: None }))], into: None, from: [TableWithJoins { relation: Table { name: ObjectName([Ident { value: "foo", quote_style: None }]), alias: None, args: None, with_hints: [] }, joins: [] }], lateral_views: [], selection: Some(BinaryOp { left: Identifier(Ident { value: "a", quote_style: None }), op: Gt, right: AnyOp(Identifier(Ident { value: "b", quote_style: None })) }), group_by: [], cluster_by: [], distribute_by: [], sort_by: [], having: None, named_window: [], qualify: None }), order_by: [], limit: None, offset: None, fetch: None, locks: [] })]
Note the AnyOp inside the selection's BinaryOp struct. Convering this with serde_rustler strips this variant:
[
%JumpWire.Proxy.SQL.Statement.Query{
locks: [],
fetch: nil,
offset: nil,
limit: nil,
order_by: [],
body: %JumpWire.Proxy.SQL.Statement.Select{
qualify: nil,
named_window: [],
having: nil,
sort_by: [],
distribute_by: [],
cluster_by: [],
group_by: [],
selection: %JumpWire.Proxy.SQL.Statement.BinaryOp{
right: %JumpWire.Proxy.SQL.Statement.Ident{
quote_style: nil,
value: "b"
},
op: :gt,
left: %JumpWire.Proxy.SQL.Statement.Ident{quote_style: nil, value: "a"}
},
lateral_views: [],
from: [
%JumpWire.Proxy.SQL.Statement.TableWithJoins{
joins: [],
relation: %JumpWire.Proxy.SQL.Statement.Table{
with_hints: [],
args: nil,
alias: nil,
name: [
%JumpWire.Proxy.SQL.Statement.Ident{
quote_style: nil,
value: "foo"
}
]
}
}
],
into: nil,
projection: [
%JumpWire.Proxy.SQL.Statement.Ident{quote_style: nil, value: "a"}
],
top: nil,
distinct: nil
},
with: nil
}
]
This is probably a bug with serde_rustler that needs to be fixed in our fork.