Skip to content

Commit 2eeefec

Browse files
committed
fix: review comments
1 parent 7730c88 commit 2eeefec

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/iceberg/expression/binder.cc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,22 @@ Result<bool> IsBoundVisitor::IsBound(const std::shared_ptr<Expression>& expr) {
8585
return Visit<bool, IsBoundVisitor>(expr, visitor);
8686
}
8787

88-
Result<bool> IsBoundVisitor::AlwaysTrue() { return true; }
88+
Result<bool> IsBoundVisitor::AlwaysTrue() {
89+
return InvalidExpression("IsBoundVisitor does not support AlwaysTrue expression");
90+
}
8991

90-
Result<bool> IsBoundVisitor::AlwaysFalse() { return true; }
92+
Result<bool> IsBoundVisitor::AlwaysFalse() {
93+
return InvalidExpression("IsBoundVisitor does not support AlwaysFalse expression");
94+
}
9195

9296
Result<bool> IsBoundVisitor::Not(bool child_result) { return child_result; }
9397

9498
Result<bool> IsBoundVisitor::And(bool left_result, bool right_result) {
95-
ICEBERG_PRECHECK(left_result == right_result, "Found partially bound expression");
96-
return left_result;
99+
return left_result && right_result;
97100
}
98101

99102
Result<bool> IsBoundVisitor::Or(bool left_result, bool right_result) {
100-
ICEBERG_PRECHECK(left_result == right_result, "Found partially bound expression");
101-
return left_result;
103+
return left_result && right_result;
102104
}
103105

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

src/iceberg/test/expression_visitor_test.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ TEST_F(BinderTest, ErrorNestedUnboundField) {
296296
class IsBoundVisitorTest : public ExpressionVisitorTest {};
297297

298298
TEST_F(IsBoundVisitorTest, Constants) {
299-
// True and False are always considered bound
299+
// True and False should error out
300300
auto true_expr = Expressions::AlwaysTrue();
301-
ICEBERG_UNWRAP_OR_FAIL(auto is_bound_true, IsBoundVisitor::IsBound(true_expr));
302-
EXPECT_TRUE(is_bound_true);
301+
auto result_true = IsBoundVisitor::IsBound(true_expr);
302+
EXPECT_THAT(result_true, IsError(ErrorKind::kInvalidExpression));
303303

304304
auto false_expr = Expressions::AlwaysFalse();
305-
ICEBERG_UNWRAP_OR_FAIL(auto is_bound_false, IsBoundVisitor::IsBound(false_expr));
306-
EXPECT_TRUE(is_bound_false);
305+
auto result_false = IsBoundVisitor::IsBound(false_expr);
306+
EXPECT_THAT(result_false, IsError(ErrorKind::kInvalidExpression));
307307
}
308308

309309
TEST_F(IsBoundVisitorTest, UnboundPredicate) {
@@ -333,14 +333,14 @@ TEST_F(IsBoundVisitorTest, AndWithBoundChildren) {
333333
}
334334

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

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

346346
TEST_F(IsBoundVisitorTest, OrWithBoundChildren) {
@@ -355,14 +355,14 @@ TEST_F(IsBoundVisitorTest, OrWithBoundChildren) {
355355
}
356356

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

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

368368
TEST_F(IsBoundVisitorTest, NotWithBoundChild) {
@@ -396,15 +396,15 @@ TEST_F(IsBoundVisitorTest, ComplexExpression) {
396396
ICEBERG_UNWRAP_OR_FAIL(auto is_bound, IsBoundVisitor::IsBound(bound_complex));
397397
EXPECT_TRUE(is_bound);
398398

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

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

410410
class RewriteNotTest : public ExpressionVisitorTest {};

0 commit comments

Comments
 (0)