From 81371a9471e97cc94cd99201ab0a90008c59d23e Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Sat, 2 Mar 2024 14:47:57 -0500 Subject: [PATCH] support sql udf with unnamed parameters --- src/binder/expr.rs | 13 ++++++++++++- src/binder/mod.rs | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/binder/expr.rs b/src/binder/expr.rs index 9c40e9e0..f22af288 100644 --- a/src/binder/expr.rs +++ b/src/binder/expr.rs @@ -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), diff --git a/src/binder/mod.rs b/src/binder/mod.rs index 644e08c9..f2ed4bcd 100644 --- a/src/binder/mod.rs +++ b/src/binder/mod.rs @@ -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