1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/planner/operator/logical_distinct.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/planner/logical_operator.hpp"
12#include "duckdb/planner/bound_result_modifier.hpp"
13
14namespace duckdb {
15
16//! LogicalDistinct filters duplicate entries from its child operator
17class LogicalDistinct : public LogicalOperator {
18public:
19 static constexpr const LogicalOperatorType TYPE = LogicalOperatorType::LOGICAL_DISTINCT;
20
21public:
22 explicit LogicalDistinct(DistinctType distinct_type)
23 : LogicalOperator(LogicalOperatorType::LOGICAL_DISTINCT), distinct_type(distinct_type) {
24 }
25 explicit LogicalDistinct(vector<unique_ptr<Expression>> targets, DistinctType distinct_type)
26 : LogicalOperator(LogicalOperatorType::LOGICAL_DISTINCT), distinct_type(distinct_type),
27 distinct_targets(std::move(targets)) {
28 }
29
30 //! Whether or not this is a DISTINCT or DISTINCT ON
31 DistinctType distinct_type;
32 //! The set of distinct targets
33 vector<unique_ptr<Expression>> distinct_targets;
34 //! The order by modifier (optional, only for distinct on)
35 unique_ptr<BoundOrderModifier> order_by;
36
37public:
38 string ParamsToString() const override;
39
40 vector<ColumnBinding> GetColumnBindings() override {
41 return children[0]->GetColumnBindings();
42 }
43 void Serialize(FieldWriter &writer) const override;
44 static unique_ptr<LogicalOperator> Deserialize(LogicalDeserializationState &state, FieldReader &reader);
45
46protected:
47 void ResolveTypes() override {
48 types = children[0]->types;
49 }
50};
51} // namespace duckdb
52