| 1 | #include "duckdb/planner/expression_binder/table_function_binder.hpp" |
| 2 | #include "duckdb/parser/expression/columnref_expression.hpp" |
| 3 | #include "duckdb/planner/expression/bound_constant_expression.hpp" |
| 4 | #include "duckdb/planner/table_binding.hpp" |
| 5 | |
| 6 | namespace duckdb { |
| 7 | |
| 8 | TableFunctionBinder::TableFunctionBinder(Binder &binder, ClientContext &context) : ExpressionBinder(binder, context) { |
| 9 | } |
| 10 | |
| 11 | BindResult TableFunctionBinder::BindColumnReference(ColumnRefExpression &expr, idx_t depth, bool root_expression) { |
| 12 | |
| 13 | // if this is a lambda parameters, then we temporarily add a BoundLambdaRef, |
| 14 | // which we capture and remove later |
| 15 | if (lambda_bindings) { |
| 16 | auto &colref = expr.Cast<ColumnRefExpression>(); |
| 17 | for (idx_t i = 0; i < lambda_bindings->size(); i++) { |
| 18 | if (colref.GetColumnName() == (*lambda_bindings)[i].dummy_name) { |
| 19 | return (*lambda_bindings)[i].Bind(colref, lambda_index: i, depth); |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | auto value_function = ExpressionBinder::GetSQLValueFunction(column_name: expr.GetColumnName()); |
| 24 | if (value_function) { |
| 25 | return BindExpression(expr&: value_function, depth, root_expression); |
| 26 | } |
| 27 | |
| 28 | auto result_name = StringUtil::Join(input: expr.column_names, separator: "." ); |
| 29 | return BindResult(make_uniq<BoundConstantExpression>(args: Value(result_name))); |
| 30 | } |
| 31 | |
| 32 | BindResult TableFunctionBinder::BindExpression(unique_ptr<ParsedExpression> &expr_ptr, idx_t depth, |
| 33 | bool root_expression) { |
| 34 | auto &expr = *expr_ptr; |
| 35 | switch (expr.GetExpressionClass()) { |
| 36 | case ExpressionClass::COLUMN_REF: |
| 37 | return BindColumnReference(expr&: expr.Cast<ColumnRefExpression>(), depth, root_expression); |
| 38 | case ExpressionClass::SUBQUERY: |
| 39 | throw BinderException("Table function cannot contain subqueries" ); |
| 40 | case ExpressionClass::DEFAULT: |
| 41 | return BindResult("Table function cannot contain DEFAULT clause" ); |
| 42 | case ExpressionClass::WINDOW: |
| 43 | return BindResult("Table function cannot contain window functions!" ); |
| 44 | default: |
| 45 | return ExpressionBinder::BindExpression(expr_ptr, depth); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | string TableFunctionBinder::UnsupportedAggregateMessage() { |
| 50 | return "Table function cannot contain aggregates!" ; |
| 51 | } |
| 52 | |
| 53 | } // namespace duckdb |
| 54 | |