1 | #include "duckdb/planner/expression_binder/where_binder.hpp" |
2 | #include "duckdb/planner/expression_binder/column_alias_binder.hpp" |
3 | #include "duckdb/parser/expression/columnref_expression.hpp" |
4 | |
5 | namespace duckdb { |
6 | |
7 | WhereBinder::WhereBinder(Binder &binder, ClientContext &context, optional_ptr<ColumnAliasBinder> column_alias_binder) |
8 | : ExpressionBinder(binder, context), column_alias_binder(column_alias_binder) { |
9 | target_type = LogicalType(LogicalTypeId::BOOLEAN); |
10 | } |
11 | |
12 | BindResult WhereBinder::BindColumnRef(unique_ptr<ParsedExpression> &expr_ptr, idx_t depth, bool root_expression) { |
13 | auto &expr = expr_ptr->Cast<ColumnRefExpression>(); |
14 | auto result = ExpressionBinder::BindExpression(expr_ptr, depth); |
15 | if (!result.HasError() || !column_alias_binder) { |
16 | return result; |
17 | } |
18 | |
19 | BindResult alias_result = column_alias_binder->BindAlias(enclosing_binder&: *this, expr, depth, root_expression); |
20 | // This code path cannot be exercised at thispoint. #1547 might change that. |
21 | if (!alias_result.HasError()) { |
22 | return alias_result; |
23 | } |
24 | |
25 | return result; |
26 | } |
27 | |
28 | BindResult WhereBinder::BindExpression(unique_ptr<ParsedExpression> &expr_ptr, idx_t depth, bool root_expression) { |
29 | auto &expr = *expr_ptr; |
30 | switch (expr.GetExpressionClass()) { |
31 | case ExpressionClass::DEFAULT: |
32 | return BindResult("WHERE clause cannot contain DEFAULT clause" ); |
33 | case ExpressionClass::WINDOW: |
34 | return BindResult("WHERE clause cannot contain window functions!" ); |
35 | case ExpressionClass::COLUMN_REF: |
36 | return BindColumnRef(expr_ptr, depth, root_expression); |
37 | default: |
38 | return ExpressionBinder::BindExpression(expr_ptr, depth); |
39 | } |
40 | } |
41 | |
42 | string WhereBinder::UnsupportedAggregateMessage() { |
43 | return "WHERE clause cannot contain aggregates!" ; |
44 | } |
45 | |
46 | } // namespace duckdb |
47 | |