Skip to content

Commit

Permalink
support sql udf with unnamed parameters
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Xu <xzhseh@gmail.com>
  • Loading branch information
xzhseh committed Mar 2, 2024
1 parent 0e4a846 commit 8b1bbd8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/binder/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ impl Binder {
/// Bind an expression.
pub fn bind_expr(&mut self, expr: Expr) -> Result {
let id = match expr {
Expr::Value(v) => Ok(self.egraph.add(Node::Constant(v.into()))),
Expr::Value(v) => {
// This is okay since only sql udf relies on parameter-like (i.e., `$1`)
// values at present
// TODO: consider formally `bind_parameter` in the future (e.g., lambda function support, etc.)
if let Value::Placeholder(key) = v {
self.udf_context
.get_expr(&key)
.map_or_else(|| Err(BindError::InvalidSQL), |&e| Ok(e))
} else {
Ok(self.egraph.add(Node::Constant(v.into())))
}
},
Expr::Identifier(ident) => self.bind_ident([ident]),
Expr::CompoundIdentifier(idents) => self.bind_ident(idents),
Expr::BinaryOp { left, op, right } => self.bind_binary_op(*left, op, *right),
Expand Down
2 changes: 1 addition & 1 deletion src/binder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl UdfContext {
return Err(BindError::InvalidExpression("invalid syntax".to_string()));
};
if catalog.arg_names[i].is_empty() {
todo!("anonymous parameters not yet supported");
ret.insert(format!("${}", i + 1), e.clone());
} else {
// The index mapping here is accurate
// So that we could directly use the index
Expand Down

0 comments on commit 8b1bbd8

Please sign in to comment.