Skip to content

Commit ac1f05f

Browse files
mroz45zanmato1984
andauthored
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 <kamil.tokarek@secom.com.pl> Co-authored-by: kamilt <kamil.tokarek@secom.com.pl> Co-authored-by: Rossi Sun <zanmato1984@gmail.com> Signed-off-by: Rossi Sun <zanmato1984@gmail.com>
1 parent ab42634 commit ac1f05f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cpp/src/arrow/compute/expression.cc

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ void PrintTo(const Expression& expr, std::ostream* os) {
221221
bool Expression::Equals(const Expression& other) const {
222222
if (Identical(*this, other)) return true;
223223

224+
if (impl_ == nullptr || other.impl_ == nullptr) return false;
225+
224226
if (impl_->index() != other.impl_->index()) {
225227
return false;
226228
}

cpp/src/arrow/compute/expression_test.cc

+9
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,15 @@ TEST(Expression, Equality) {
338338
literal(std::numeric_limits<double>::signaling_NaN()));
339339
}
340340

341+
// Equality when underlying `impl_` is null.
342+
Expression expr1;
343+
Expression expr2(literal(1));
344+
EXPECT_NE(literal("a"), expr1);
345+
EXPECT_NE(expr1, literal("a"));
346+
347+
EXPECT_FALSE(expr1.Equals(expr2));
348+
EXPECT_FALSE(expr2.Equals(expr1));
349+
341350
EXPECT_EQ(field_ref("a"), field_ref("a"));
342351
EXPECT_NE(field_ref("a"), field_ref("b"));
343352
EXPECT_NE(field_ref("a"), literal(2));

0 commit comments

Comments
 (0)