Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2796 from chenxi8611/master
Addition of QUALIFY clause
- Loading branch information
Showing
22 changed files
with
17,351 additions
and
16,862 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/include/duckdb/planner/expression_binder/qualify_binder.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//===----------------------------------------------------------------------===// | ||
// DuckDB | ||
// | ||
// duckdb/planner/expression_binder/qualify_binder.hpp | ||
// | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#pragma once | ||
|
||
#include "duckdb/planner/expression_binder/select_binder.hpp" | ||
#include "duckdb/planner/expression_binder/column_alias_binder.hpp" | ||
|
||
namespace duckdb { | ||
|
||
//! The QUALIFY binder is responsible for binding an expression within the QUALIFY clause of a SQL statement | ||
class QualifyBinder : public SelectBinder { | ||
public: | ||
QualifyBinder(Binder &binder, ClientContext &context, BoundSelectNode &node, BoundGroupInformation &info, | ||
unordered_map<string, idx_t> &alias_map); | ||
|
||
protected: | ||
BindResult BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, | ||
bool root_expression = false) override; | ||
|
||
private: | ||
BindResult BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression); | ||
|
||
ColumnAliasBinder column_alias_binder; | ||
}; | ||
|
||
} // namespace duckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "duckdb/planner/expression_binder/qualify_binder.hpp" | ||
|
||
#include "duckdb/parser/expression/columnref_expression.hpp" | ||
#include "duckdb/planner/binder.hpp" | ||
#include "duckdb/planner/expression_binder/aggregate_binder.hpp" | ||
#include "duckdb/common/string_util.hpp" | ||
#include "duckdb/planner/query_node/bound_select_node.hpp" | ||
|
||
namespace duckdb { | ||
|
||
QualifyBinder::QualifyBinder(Binder &binder, ClientContext &context, BoundSelectNode &node, BoundGroupInformation &info, | ||
unordered_map<string, idx_t> &alias_map) | ||
: SelectBinder(binder, context, node, info), column_alias_binder(node, alias_map) { | ||
target_type = LogicalType(LogicalTypeId::BOOLEAN); | ||
} | ||
|
||
BindResult QualifyBinder::BindColumnRef(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression) { | ||
auto &expr = (ColumnRefExpression &)**expr_ptr; | ||
auto result = duckdb::SelectBinder::BindExpression(expr_ptr, depth); | ||
if (!result.HasError()) { | ||
return result; | ||
} | ||
|
||
auto alias_result = column_alias_binder.BindAlias(*this, expr, depth, root_expression); | ||
if (!alias_result.HasError()) { | ||
return alias_result; | ||
} | ||
|
||
return BindResult(StringUtil::Format("Referenced column %s not found in FROM clause and can't find in alias map.", | ||
expr.ToString())); | ||
} | ||
|
||
BindResult QualifyBinder::BindExpression(unique_ptr<ParsedExpression> *expr_ptr, idx_t depth, bool root_expression) { | ||
auto &expr = **expr_ptr; | ||
// check if the expression binds to one of the groups | ||
auto group_index = TryBindGroup(expr, depth); | ||
if (group_index != DConstants::INVALID_INDEX) { | ||
return BindGroup(expr, depth, group_index); | ||
} | ||
switch (expr.expression_class) { | ||
case ExpressionClass::WINDOW: | ||
return BindWindow((WindowExpression &)expr, depth); | ||
case ExpressionClass::COLUMN_REF: | ||
return BindColumnRef(expr_ptr, depth, root_expression); | ||
default: | ||
return duckdb::SelectBinder::BindExpression(expr_ptr, depth); | ||
} | ||
} | ||
|
||
} // namespace duckdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
namespace duckdb { | ||
|
||
const uint64_t VERSION_NUMBER = 29; | ||
const uint64_t VERSION_NUMBER = 30; | ||
|
||
} // namespace duckdb |
Oops, something went wrong.