Skip to content

Commit afd3935

Browse files
committed
feat: expression interface init commit, apply review suggestions.
1 parent d3f6624 commit afd3935

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

src/iceberg/expression.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@ namespace iceberg {
2525

2626
// True implementation
2727
const std::shared_ptr<True>& True::Instance() {
28-
static const std::shared_ptr<True> instance = std::shared_ptr<True>(new True());
28+
static const std::shared_ptr<True> instance{new True()};
2929
return instance;
3030
}
3131

32-
Result<ExpressionPtr> True::Negate() const { return False::Instance(); }
32+
Result<std::shared_ptr<Expression>> True::Negate() const { return False::Instance(); }
3333

3434
// False implementation
3535
const std::shared_ptr<False>& False::Instance() {
3636
static const std::shared_ptr<False> instance = std::shared_ptr<False>(new False());
3737
return instance;
3838
}
3939

40-
Result<ExpressionPtr> False::Negate() const { return True::Instance(); }
40+
Result<std::shared_ptr<Expression>> False::Negate() const { return True::Instance(); }
4141

4242
// And implementation
43-
And::And(ExpressionPtr left, ExpressionPtr right)
43+
And::And(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right)
4444
: left_(std::move(left)), right_(std::move(right)) {}
4545

4646
std::string And::ToString() const {
4747
return std::format("({} and {})", left_->ToString(), right_->ToString());
4848
}
4949

50-
Result<ExpressionPtr> And::Negate() const {
50+
Result<std::shared_ptr<Expression>> And::Negate() const {
5151
// TODO(yingcai-cy): Implement Or expression
5252
return unexpected(
5353
Error(ErrorKind::kInvalidExpression, "And negation not yet implemented"));

src/iceberg/expression.h

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131

3232
namespace iceberg {
3333

34-
/// \brief Type alias for shared pointer to Expression
35-
class Expression;
36-
using ExpressionPtr = std::shared_ptr<Expression>;
37-
3834
/// \brief Represents a boolean expression tree.
3935
class ICEBERG_EXPORT Expression {
4036
public:
@@ -71,7 +67,7 @@ class ICEBERG_EXPORT Expression {
7167
virtual Operation op() const = 0;
7268

7369
/// \brief Returns the negation of this expression, equivalent to not(this).
74-
virtual Result<ExpressionPtr> Negate() const {
70+
virtual Result<std::shared_ptr<Expression>> Negate() const {
7571
return unexpected(
7672
Error(ErrorKind::kInvalidExpression, "Expression cannot be negated"));
7773
}
@@ -99,7 +95,7 @@ class ICEBERG_EXPORT True : public Expression {
9995

10096
std::string ToString() const override { return "true"; }
10197

102-
Result<ExpressionPtr> Negate() const override;
98+
Result<std::shared_ptr<Expression>> Negate() const override;
10399

104100
bool Equals(const Expression& other) const override {
105101
return other.op() == Operation::kTrue;
@@ -119,7 +115,7 @@ class ICEBERG_EXPORT False : public Expression {
119115

120116
std::string ToString() const override { return "false"; }
121117

122-
Result<ExpressionPtr> Negate() const override;
118+
Result<std::shared_ptr<Expression>> Negate() const override;
123119

124120
bool Equals(const Expression& other) const override {
125121
return other.op() == Operation::kFalse;
@@ -137,31 +133,31 @@ class ICEBERG_EXPORT And : public Expression {
137133
public:
138134
/// \brief Constructs an And expression from two sub-expressions.
139135
///
140-
/// @param left The left operand of the AND expression
141-
/// @param right The right operand of the AND expression
142-
And(ExpressionPtr left, ExpressionPtr right);
136+
/// \param left The left operand of the AND expression
137+
/// \param right The right operand of the AND expression
138+
And(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right);
143139

144140
/// \brief Returns the left operand of the AND expression.
145141
///
146-
/// @return The left operand of the AND expression
147-
const ExpressionPtr& left() const { return left_; }
142+
/// \return The left operand of the AND expression
143+
const std::shared_ptr<Expression>& left() const { return left_; }
148144

149145
/// \brief Returns the right operand of the AND expression.
150146
///
151-
/// @return The right operand of the AND expression
152-
const ExpressionPtr& right() const { return right_; }
147+
/// \return The right operand of the AND expression
148+
const std::shared_ptr<Expression>& right() const { return right_; }
153149

154150
Operation op() const override { return Operation::kAnd; }
155151

156152
std::string ToString() const override;
157153

158-
Result<ExpressionPtr> Negate() const override;
154+
Result<std::shared_ptr<Expression>> Negate() const override;
159155

160156
bool Equals(const Expression& other) const override;
161157

162158
private:
163-
ExpressionPtr left_;
164-
ExpressionPtr right_;
159+
std::shared_ptr<Expression> left_;
160+
std::shared_ptr<Expression> right_;
165161
};
166162

167163
} // namespace iceberg

test/expression_test.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@
2525

2626
namespace iceberg {
2727

28-
TEST(TrueFalseTest, Basi) {
28+
TEST(TrueFalseTest, Basic) {
2929
// Test negation of False returns True
30-
const std::shared_ptr<False> false_instance = False::Instance();
30+
auto false_instance = False::Instance();
3131
auto negated = false_instance->Negate();
3232

3333
EXPECT_TRUE(negated.has_value());
3434

3535
// Check that negated expression is True
36-
std::shared_ptr<Expression> true_expr = negated.value();
36+
auto true_expr = negated.value();
3737
EXPECT_EQ(true_expr->op(), Expression::Operation::kTrue);
3838

3939
EXPECT_EQ(true_expr->ToString(), "true");
4040

4141
// Test negation of True returns false
42-
const std::shared_ptr<True> true_instance = True::Instance();
42+
auto true_instance = True::Instance();
4343
negated = true_instance->Negate();
4444

4545
EXPECT_TRUE(negated.has_value());
4646

47-
// Check that negated expression is True
48-
std::shared_ptr<Expression> false_expr = negated.value();
47+
// Check that negated expression is False
48+
auto false_expr = negated.value();
4949
EXPECT_EQ(false_expr->op(), Expression::Operation::kFalse);
5050

5151
EXPECT_EQ(false_expr->ToString(), "false");

0 commit comments

Comments
 (0)