1//===----------------------------------------------------------------------===//
2// DuckDB
3//
4// duckdb/parser/expression/conjunction_expression.hpp
5//
6//
7//===----------------------------------------------------------------------===//
8
9#pragma once
10
11#include "duckdb/parser/parsed_expression.hpp"
12#include "duckdb/common/vector.hpp"
13
14namespace duckdb {
15
16//! Represents a conjunction (AND/OR)
17class ConjunctionExpression : public ParsedExpression {
18public:
19 static constexpr const ExpressionClass TYPE = ExpressionClass::CONJUNCTION;
20
21public:
22 DUCKDB_API explicit ConjunctionExpression(ExpressionType type);
23 DUCKDB_API ConjunctionExpression(ExpressionType type, vector<unique_ptr<ParsedExpression>> children);
24 DUCKDB_API ConjunctionExpression(ExpressionType type, unique_ptr<ParsedExpression> left,
25 unique_ptr<ParsedExpression> right);
26
27 vector<unique_ptr<ParsedExpression>> children;
28
29public:
30 void AddExpression(unique_ptr<ParsedExpression> expr);
31
32 string ToString() const override;
33
34 static bool Equal(const ConjunctionExpression &a, const ConjunctionExpression &b);
35
36 unique_ptr<ParsedExpression> Copy() const override;
37
38 void Serialize(FieldWriter &writer) const override;
39 static unique_ptr<ParsedExpression> Deserialize(ExpressionType type, FieldReader &source);
40 void FormatSerialize(FormatSerializer &serializer) const override;
41 static unique_ptr<ParsedExpression> FormatDeserialize(ExpressionType type, FormatDeserializer &deserializer);
42
43public:
44 template <class T, class BASE>
45 static string ToString(const T &entry) {
46 string result = "(" + entry.children[0]->ToString();
47 for (idx_t i = 1; i < entry.children.size(); i++) {
48 result += " " + ExpressionTypeToOperator(entry.type) + " " + entry.children[i]->ToString();
49 }
50 return result + ")";
51 }
52};
53} // namespace duckdb
54