This is an automated email from the ASF dual-hosted git repository.
zhjwpku pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new ce5b37a7 refactor(expression): make Bound::reference() const (#1161)
ce5b37a7 is described below
commit ce5b37a7ba7e91ed984a474d859aba75b08adb8f
Author: Junwang Zhao <[email protected]>
AuthorDate: Tue Nov 24 00:01:13 2026 +0800
refactor(expression): make Bound::reference() const (#1161)
Return a read-only field reference so callers can inspect a const bound
expression. Update the four overrides and exercise the accessor through a const
Bound reference.
---
src/iceberg/expression/aggregate.h | 2 +-
src/iceberg/expression/expression.h | 2 +-
src/iceberg/expression/json_serde.cc | 4 ++--
src/iceberg/expression/predicate.h | 4 +++-
src/iceberg/expression/term.h | 6 ++++--
src/iceberg/test/predicate_test.cc | 2 ++
6 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/src/iceberg/expression/aggregate.h
b/src/iceberg/expression/aggregate.h
index bbb01a4a..9ba0ddbd 100644
--- a/src/iceberg/expression/aggregate.h
+++ b/src/iceberg/expression/aggregate.h
@@ -121,7 +121,7 @@ class ICEBERG_EXPORT BoundAggregate : public
Aggregate<BoundTerm>, public Bound
virtual Literal GetResult() const = 0;
};
- std::shared_ptr<BoundReference> reference() override {
+ std::shared_ptr<const BoundReference> reference() const override {
ICEBERG_DCHECK(term() != nullptr || op() ==
Expression::Operation::kCountStar,
"Bound aggregate term should not be null except for
COUNT(*)");
return term() ? term()->reference() : nullptr;
diff --git a/src/iceberg/expression/expression.h
b/src/iceberg/expression/expression.h
index 63dc7ef2..9ccb4f39 100644
--- a/src/iceberg/expression/expression.h
+++ b/src/iceberg/expression/expression.h
@@ -365,7 +365,7 @@ class ICEBERG_EXPORT Bound {
virtual Result<Literal> Evaluate(const StructLike& data) const = 0;
/// \brief Returns the underlying bound reference for this term.
- virtual std::shared_ptr<class BoundReference> reference() = 0;
+ virtual std::shared_ptr<const class BoundReference> reference() const = 0;
};
} // namespace iceberg
diff --git a/src/iceberg/expression/json_serde.cc
b/src/iceberg/expression/json_serde.cc
index 59f3fdcc..c679d2c6 100644
--- a/src/iceberg/expression/json_serde.cc
+++ b/src/iceberg/expression/json_serde.cc
@@ -222,8 +222,8 @@ nlohmann::json ToJson(const UnboundTransform& transform) {
nlohmann::json ToJson(const BoundReference& ref) { return ref.name(); }
nlohmann::json ToJson(const BoundTransform& transform) {
- auto& mut = const_cast<BoundTransform&>(transform);
- return MakeTransformJson(transform.transform()->ToString(),
mut.reference()->name());
+ return MakeTransformJson(transform.transform()->ToString(),
+ transform.reference()->name());
}
Result<std::unique_ptr<NamedReference>> NamedReferenceFromJson(
diff --git a/src/iceberg/expression/predicate.h
b/src/iceberg/expression/predicate.h
index c7afbca6..e2d39081 100644
--- a/src/iceberg/expression/predicate.h
+++ b/src/iceberg/expression/predicate.h
@@ -169,7 +169,9 @@ class ICEBERG_EXPORT BoundPredicate : public
Predicate<BoundTerm>, public Bound
using Predicate<BoundTerm>::term;
- std::shared_ptr<BoundReference> reference() override { return
term_->reference(); }
+ std::shared_ptr<const BoundReference> reference() const override {
+ return term_->reference();
+ }
Result<Literal> Evaluate(const StructLike& data) const override;
diff --git a/src/iceberg/expression/term.h b/src/iceberg/expression/term.h
index 4d5f0979..97119533 100644
--- a/src/iceberg/expression/term.h
+++ b/src/iceberg/expression/term.h
@@ -149,7 +149,9 @@ class ICEBERG_EXPORT BoundReference
Result<Literal> Evaluate(const StructLike& data) const override;
- std::shared_ptr<BoundReference> reference() override { return
shared_from_this(); }
+ std::shared_ptr<const BoundReference> reference() const override {
+ return shared_from_this();
+ }
std::shared_ptr<Type> type() const override { return field_.type(); }
@@ -219,7 +221,7 @@ class ICEBERG_EXPORT BoundTransform : public BoundTerm {
Result<Literal> Evaluate(const StructLike& data) const override;
- std::shared_ptr<BoundReference> reference() override { return ref_; }
+ std::shared_ptr<const BoundReference> reference() const override { return
ref_; }
std::shared_ptr<Type> type() const override;
diff --git a/src/iceberg/test/predicate_test.cc
b/src/iceberg/test/predicate_test.cc
index 9332842b..3a93b013 100644
--- a/src/iceberg/test/predicate_test.cc
+++ b/src/iceberg/test/predicate_test.cc
@@ -231,6 +231,8 @@ TEST_F(PredicateTest, NamedReferenceBind) {
ASSERT_THAT(bound_result, IsOk());
auto bound_ref = bound_result.value();
+ const Bound& bound = *bound_ref;
+ EXPECT_EQ(bound.reference(), bound_ref);
EXPECT_EQ(bound_ref->name(), "id");
EXPECT_EQ(bound_ref->field().field_id(), 1);
EXPECT_EQ(bound_ref->type()->type_id(), TypeId::kLong);