This is an automated email from the ASF dual-hosted git repository.
zanmato pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new ac1f05f28e GH-45700: [C++][Compute] Added nullptr check in Equals
method to handle null impl_ pointers (#45701)
ac1f05f28e is described below
commit ac1f05f28e18e85ee55cf7aaf3c8ae1ffe0e92d7
Author: mroz45 <[email protected]>
AuthorDate: Fri Mar 14 11:15:20 2025 +0100
GH-45700: [C++][Compute] Added nullptr check in Equals method to handle
null impl_ pointers (#45701)
### Rationale for this change
### What changes are included in this PR?
This PR adds a check to ensure that the Expression is not nullptr
### Are these changes tested?
Yes.
### Are there any user-facing changes?
No
* GitHub Issue: #45700
Lead-authored-by: mroz45 <[email protected]>
Co-authored-by: kamilt <[email protected]>
Co-authored-by: Rossi Sun <[email protected]>
Signed-off-by: Rossi Sun <[email protected]>
---
cpp/src/arrow/compute/expression.cc | 2 ++
cpp/src/arrow/compute/expression_test.cc | 9 +++++++++
2 files changed, 11 insertions(+)
diff --git a/cpp/src/arrow/compute/expression.cc
b/cpp/src/arrow/compute/expression.cc
index e970cd3175..e065416208 100644
--- a/cpp/src/arrow/compute/expression.cc
+++ b/cpp/src/arrow/compute/expression.cc
@@ -221,6 +221,8 @@ void PrintTo(const Expression& expr, std::ostream* os) {
bool Expression::Equals(const Expression& other) const {
if (Identical(*this, other)) return true;
+ if (impl_ == nullptr || other.impl_ == nullptr) return false;
+
if (impl_->index() != other.impl_->index()) {
return false;
}
diff --git a/cpp/src/arrow/compute/expression_test.cc
b/cpp/src/arrow/compute/expression_test.cc
index 0b7e8a9c23..dcc0f2e5c0 100644
--- a/cpp/src/arrow/compute/expression_test.cc
+++ b/cpp/src/arrow/compute/expression_test.cc
@@ -338,6 +338,15 @@ TEST(Expression, Equality) {
literal(std::numeric_limits<double>::signaling_NaN()));
}
+ // Equality when underlying `impl_` is null.
+ Expression expr1;
+ Expression expr2(literal(1));
+ EXPECT_NE(literal("a"), expr1);
+ EXPECT_NE(expr1, literal("a"));
+
+ EXPECT_FALSE(expr1.Equals(expr2));
+ EXPECT_FALSE(expr2.Equals(expr1));
+
EXPECT_EQ(field_ref("a"), field_ref("a"));
EXPECT_NE(field_ref("a"), field_ref("b"));
EXPECT_NE(field_ref("a"), literal(2));