Coverage Report

Created: 2025-12-16 09:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/duckdb/src/planner/expression/bound_parameter_expression.cpp
Line
Count
Source
1
#include "duckdb/planner/expression/bound_parameter_expression.hpp"
2
#include "duckdb/common/types/hash.hpp"
3
#include "duckdb/common/to_string.hpp"
4
#include "duckdb/planner/expression_iterator.hpp"
5
6
namespace duckdb {
7
8
BoundParameterExpression::BoundParameterExpression(const string &identifier)
9
41.3k
    : Expression(ExpressionType::VALUE_PARAMETER, ExpressionClass::BOUND_PARAMETER,
10
41.3k
                 LogicalType(LogicalTypeId::UNKNOWN)),
11
41.3k
      identifier(identifier) {
12
41.3k
}
13
14
BoundParameterExpression::BoundParameterExpression(bound_parameter_map_t &global_parameter_set, string identifier,
15
                                                   LogicalType return_type,
16
                                                   shared_ptr<BoundParameterData> parameter_data)
17
11.2k
    : Expression(ExpressionType::VALUE_PARAMETER, ExpressionClass::BOUND_PARAMETER, std::move(return_type)),
18
11.2k
      identifier(std::move(identifier)) {
19
  // check if we have already deserialized a parameter with this number
20
11.2k
  auto entry = global_parameter_set.find(this->identifier);
21
11.2k
  if (entry == global_parameter_set.end()) {
22
    // we have not - store the entry we deserialized from this parameter expression
23
11.1k
    global_parameter_set[this->identifier] = parameter_data;
24
11.1k
  } else {
25
    // we have! use the previously deserialized entry
26
119
    parameter_data = entry->second;
27
119
  }
28
11.2k
  this->parameter_data = std::move(parameter_data);
29
11.2k
}
30
31
0
void BoundParameterExpression::Invalidate(Expression &expr) {
32
0
  if (expr.GetExpressionType() != ExpressionType::VALUE_PARAMETER) {
33
0
    throw InternalException("BoundParameterExpression::Invalidate requires a parameter as input");
34
0
  }
35
0
  auto &bound_parameter = expr.Cast<BoundParameterExpression>();
36
0
  bound_parameter.return_type = LogicalTypeId::SQLNULL;
37
0
  bound_parameter.parameter_data->return_type = LogicalTypeId::INVALID;
38
0
}
39
40
0
void BoundParameterExpression::InvalidateRecursive(Expression &expr) {
41
0
  if (expr.GetExpressionType() == ExpressionType::VALUE_PARAMETER) {
42
0
    Invalidate(expr);
43
0
    return;
44
0
  }
45
0
  ExpressionIterator::EnumerateChildren(expr, [&](Expression &child) { InvalidateRecursive(child); });
46
0
}
47
48
0
bool BoundParameterExpression::IsScalar() const {
49
0
  return true;
50
0
}
51
9
bool BoundParameterExpression::HasParameter() const {
52
9
  return true;
53
9
}
54
19.0k
bool BoundParameterExpression::IsFoldable() const {
55
19.0k
  return false;
56
19.0k
}
57
58
3.15k
string BoundParameterExpression::ToString() const {
59
3.15k
  return "$" + identifier;
60
3.15k
}
61
62
7
bool BoundParameterExpression::Equals(const BaseExpression &other_p) const {
63
7
  if (!Expression::Equals(other_p)) {
64
0
    return false;
65
0
  }
66
7
  auto &other = other_p.Cast<BoundParameterExpression>();
67
7
  return StringUtil::CIEquals(identifier, other.identifier);
68
7
}
69
70
6.75k
hash_t BoundParameterExpression::Hash() const {
71
6.75k
  hash_t result = Expression::Hash();
72
6.75k
  result = CombineHash(duckdb::Hash(identifier.c_str(), identifier.size()), result);
73
6.75k
  return result;
74
6.75k
}
75
76
88
unique_ptr<Expression> BoundParameterExpression::Copy() const {
77
88
  auto result = make_uniq<BoundParameterExpression>(identifier);
78
88
  result->parameter_data = parameter_data;
79
88
  result->return_type = return_type;
80
88
  result->CopyProperties(*this);
81
88
  return std::move(result);
82
88
}
83
84
} // namespace duckdb