1#include "duckdb/planner/expression.hpp"
2
3#include "duckdb/common/exception.hpp"
4#include "duckdb/common/types/hash.hpp"
5#include "duckdb/planner/expression_iterator.hpp"
6
7using namespace duckdb;
8using namespace std;
9
10Expression::Expression(ExpressionType type, ExpressionClass expression_class, TypeId return_type)
11 : BaseExpression(type, expression_class), return_type(return_type) {
12}
13
14bool Expression::IsAggregate() const {
15 bool is_aggregate = false;
16 ExpressionIterator::EnumerateChildren(*this, [&](const Expression &child) { is_aggregate |= child.IsAggregate(); });
17 return is_aggregate;
18}
19
20bool Expression::IsWindow() const {
21 bool is_window = false;
22 ExpressionIterator::EnumerateChildren(*this, [&](const Expression &child) { is_window |= child.IsWindow(); });
23 return is_window;
24}
25
26bool Expression::IsScalar() const {
27 bool is_scalar = true;
28 ExpressionIterator::EnumerateChildren(*this, [&](const Expression &child) {
29 if (!child.IsScalar()) {
30 is_scalar = false;
31 }
32 });
33 return is_scalar;
34}
35
36bool Expression::IsFoldable() const {
37 bool is_foldable = true;
38 ExpressionIterator::EnumerateChildren(*this, [&](const Expression &child) {
39 if (!child.IsFoldable()) {
40 is_foldable = false;
41 }
42 });
43 return is_foldable;
44}
45
46bool Expression::HasParameter() const {
47 bool has_parameter = false;
48 ExpressionIterator::EnumerateChildren(*this,
49 [&](const Expression &child) { has_parameter |= child.HasParameter(); });
50 return has_parameter;
51}
52
53bool Expression::HasSubquery() const {
54 bool has_subquery = false;
55 ExpressionIterator::EnumerateChildren(*this, [&](const Expression &child) { has_subquery |= child.HasSubquery(); });
56 return has_subquery;
57}
58
59hash_t Expression::Hash() const {
60 hash_t hash = duckdb::Hash<uint32_t>((uint32_t)type);
61 hash = CombineHash(hash, duckdb::Hash<uint32_t>((uint32_t)return_type));
62 ExpressionIterator::EnumerateChildren(*this,
63 [&](const Expression &child) { hash = CombineHash(child.Hash(), hash); });
64 return hash;
65}
66