Skip to content

Commit 366c586

Browse files
committed
IsBoundVisitor mixed bound/unbound predicate should error
1 parent 2bd493c commit 366c586

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

src/iceberg/expression/binder.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "iceberg/expression/binder.h"
2121

22+
#include "iceberg/util/macros.h"
23+
2224
namespace iceberg {
2325

2426
Binder::Binder(const Schema& schema, bool case_sensitive)
@@ -89,11 +91,13 @@ Result<bool> IsBoundVisitor::AlwaysFalse() { return true; }
8991
Result<bool> IsBoundVisitor::Not(bool child_result) { return child_result; }
9092

9193
Result<bool> IsBoundVisitor::And(bool left_result, bool right_result) {
92-
return left_result && right_result;
94+
ICEBERG_PRECHECK(left_result == right_result, "Found partially bound expression");
95+
return left_result;
9396
}
9497

9598
Result<bool> IsBoundVisitor::Or(bool left_result, bool right_result) {
96-
return left_result && right_result;
99+
ICEBERG_PRECHECK(left_result == right_result, "Found partially bound expression");
100+
return left_result;
97101
}
98102

99103
Result<bool> IsBoundVisitor::Predicate(const std::shared_ptr<BoundPredicate>& pred) {

src/iceberg/test/expression_visitor_test.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,14 @@ TEST_F(IsBoundVisitorTest, AndWithBoundChildren) {
332332
}
333333

334334
TEST_F(IsBoundVisitorTest, AndWithUnboundChild) {
335-
// AND with any unbound child should return false
335+
// AND with mixed bound/unbound children should error
336336
auto bound_pred = Expressions::Equal("name", Literal::String("Alice"));
337337
ICEBERG_UNWRAP_OR_FAIL(auto pred1, Bind(bound_pred));
338338
auto pred2 = Expressions::Equal("age", Literal::Int(25)); // unbound
339339
auto mixed_and = Expressions::And(pred1, pred2);
340340

341-
ICEBERG_UNWRAP_OR_FAIL(auto is_bound, IsBoundVisitor::IsBound(mixed_and));
342-
EXPECT_FALSE(is_bound);
341+
auto result = IsBoundVisitor::IsBound(mixed_and);
342+
EXPECT_THAT(result, HasErrorMessage("Found partially bound expression"));
343343
}
344344

345345
TEST_F(IsBoundVisitorTest, OrWithBoundChildren) {
@@ -354,14 +354,14 @@ TEST_F(IsBoundVisitorTest, OrWithBoundChildren) {
354354
}
355355

356356
TEST_F(IsBoundVisitorTest, OrWithUnboundChild) {
357-
// OR with any unbound child should return false
357+
// OR with mixed bound/unbound children should error
358358
auto pred1 = Expressions::IsNull("name"); // unbound
359359
auto bound_pred2 = Expressions::Equal("age", Literal::Int(25));
360360
ICEBERG_UNWRAP_OR_FAIL(auto pred2, Bind(bound_pred2));
361361
auto mixed_or = Expressions::Or(pred1, pred2);
362362

363-
ICEBERG_UNWRAP_OR_FAIL(auto is_bound, IsBoundVisitor::IsBound(mixed_or));
364-
EXPECT_FALSE(is_bound);
363+
auto result = IsBoundVisitor::IsBound(mixed_or);
364+
EXPECT_THAT(result, HasErrorMessage("Found partially bound expression"));
365365
}
366366

367367
TEST_F(IsBoundVisitorTest, NotWithBoundChild) {
@@ -395,15 +395,15 @@ TEST_F(IsBoundVisitorTest, ComplexExpression) {
395395
ICEBERG_UNWRAP_OR_FAIL(auto is_bound, IsBoundVisitor::IsBound(bound_complex));
396396
EXPECT_TRUE(is_bound);
397397

398-
// Complex expression: one unbound should return false
398+
// Complex expression: mixed bound/unbound children should error
399399
auto unbound_pred = Expressions::Equal("name", Literal::String("Alice"));
400400
ICEBERG_UNWRAP_OR_FAIL(auto bound_pred2, Bind(pred2));
401401
ICEBERG_UNWRAP_OR_FAIL(auto bound_pred3, Bind(pred3));
402402
auto mixed_and = Expressions::And(unbound_pred, bound_pred2);
403403
auto mixed_complex = Expressions::Or(mixed_and, bound_pred3);
404404

405-
ICEBERG_UNWRAP_OR_FAIL(auto is_bound_mixed, IsBoundVisitor::IsBound(mixed_complex));
406-
EXPECT_FALSE(is_bound_mixed);
405+
auto result_mixed = IsBoundVisitor::IsBound(mixed_complex);
406+
EXPECT_THAT(result_mixed, HasErrorMessage("Found partially bound expression"));
407407
}
408408

409409
class RewriteNotTest : public ExpressionVisitorTest {};

0 commit comments

Comments
 (0)