-
Notifications
You must be signed in to change notification settings - Fork 70
feat: scaffolding work for expression #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,10 @@ | |
| #include "iceberg/expression/expression.h" | ||
|
|
||
| #include <format> | ||
| #include <utility> | ||
|
|
||
| #include "iceberg/util/formatter_internal.h" | ||
| #include "iceberg/util/macros.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
|
|
@@ -29,15 +33,15 @@ const std::shared_ptr<True>& True::Instance() { | |
| return instance; | ||
| } | ||
|
|
||
| std::shared_ptr<Expression> True::Negate() const { return False::Instance(); } | ||
| Result<std::shared_ptr<Expression>> True::Negate() const { return False::Instance(); } | ||
|
|
||
| // False implementation | ||
| const std::shared_ptr<False>& False::Instance() { | ||
| static const std::shared_ptr<False> instance = std::shared_ptr<False>(new False()); | ||
| return instance; | ||
| } | ||
|
|
||
| std::shared_ptr<Expression> False::Negate() const { return True::Instance(); } | ||
| Result<std::shared_ptr<Expression>> False::Negate() const { return True::Instance(); } | ||
|
|
||
| // And implementation | ||
| And::And(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right) | ||
|
|
@@ -47,11 +51,11 @@ std::string And::ToString() const { | |
| return std::format("({} and {})", left_->ToString(), right_->ToString()); | ||
| } | ||
|
|
||
| std::shared_ptr<Expression> And::Negate() const { | ||
| Result<std::shared_ptr<Expression>> And::Negate() const { | ||
| // De Morgan's law: not(A and B) = (not A) or (not B) | ||
| auto left_negated = left_->Negate(); | ||
| auto right_negated = right_->Negate(); | ||
| return std::make_shared<Or>(left_negated, right_negated); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto left_negated, left_->Negate()); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto right_negated, right_->Negate()); | ||
| return std::make_shared<Or>(std::move(left_negated), std::move(right_negated)); | ||
| } | ||
|
|
||
| bool And::Equals(const Expression& expr) const { | ||
|
|
@@ -71,11 +75,11 @@ std::string Or::ToString() const { | |
| return std::format("({} or {})", left_->ToString(), right_->ToString()); | ||
| } | ||
|
|
||
| std::shared_ptr<Expression> Or::Negate() const { | ||
| Result<std::shared_ptr<Expression>> Or::Negate() const { | ||
| // De Morgan's law: not(A or B) = (not A) and (not B) | ||
| auto left_negated = left_->Negate(); | ||
| auto right_negated = right_->Negate(); | ||
| return std::make_shared<And>(left_negated, right_negated); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto left_negated, left_->Negate()); | ||
| ICEBERG_ASSIGN_OR_RAISE(auto right_negated, right_->Negate()); | ||
| return std::make_shared<And>(std::move(left_negated), std::move(right_negated)); | ||
| } | ||
|
|
||
| bool Or::Equals(const Expression& expr) const { | ||
|
|
@@ -87,4 +91,100 @@ bool Or::Equals(const Expression& expr) const { | |
| return false; | ||
| } | ||
|
|
||
| std::string_view ToString(Expression::Operation op) { | ||
| switch (op) { | ||
| case Expression::Operation::kAnd: | ||
| return "AND"; | ||
| case Expression::Operation::kOr: | ||
| return "OR"; | ||
| case Expression::Operation::kTrue: | ||
| return "TRUE"; | ||
| case Expression::Operation::kFalse: | ||
| return "FALSE"; | ||
| case Expression::Operation::kIsNull: | ||
| return "IS_NULL"; | ||
| case Expression::Operation::kNotNull: | ||
| return "NOT_NULL"; | ||
| case Expression::Operation::kIsNan: | ||
| return "IS_NAN"; | ||
| case Expression::Operation::kNotNan: | ||
| return "NOT_NAN"; | ||
| case Expression::Operation::kLt: | ||
| return "LT"; | ||
| case Expression::Operation::kLtEq: | ||
| return "LT_EQ"; | ||
| case Expression::Operation::kGt: | ||
| return "GT"; | ||
| case Expression::Operation::kGtEq: | ||
| return "GT_EQ"; | ||
| case Expression::Operation::kEq: | ||
| return "EQ"; | ||
| case Expression::Operation::kNotEq: | ||
| return "NOT_EQ"; | ||
| case Expression::Operation::kIn: | ||
| return "IN"; | ||
| case Expression::Operation::kNotIn: | ||
| return "NOT_IN"; | ||
| case Expression::Operation::kStartsWith: | ||
| return "STARTS_WITH"; | ||
| case Expression::Operation::kNotStartsWith: | ||
| return "NOT_STARTS_WITH"; | ||
| case Expression::Operation::kCount: | ||
| return "COUNT"; | ||
| case Expression::Operation::kNot: | ||
| return "NOT"; | ||
| case Expression::Operation::kCountStar: | ||
| return "COUNT_STAR"; | ||
| case Expression::Operation::kMax: | ||
| return "MAX"; | ||
| case Expression::Operation::kMin: | ||
| return "MIN"; | ||
wgtmac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| std::unreachable(); | ||
| } | ||
|
|
||
| Result<Expression::Operation> Negate(Expression::Operation op) { | ||
| switch (op) { | ||
| case Expression::Operation::kIsNull: | ||
| return Expression::Operation::kNotNull; | ||
| case Expression::Operation::kNotNull: | ||
| return Expression::Operation::kIsNull; | ||
| case Expression::Operation::kIsNan: | ||
| return Expression::Operation::kNotNan; | ||
| case Expression::Operation::kNotNan: | ||
| return Expression::Operation::kIsNan; | ||
| case Expression::Operation::kLt: | ||
| return Expression::Operation::kGtEq; | ||
| case Expression::Operation::kLtEq: | ||
| return Expression::Operation::kGt; | ||
| case Expression::Operation::kGt: | ||
| return Expression::Operation::kLtEq; | ||
| case Expression::Operation::kGtEq: | ||
| return Expression::Operation::kLt; | ||
| case Expression::Operation::kEq: | ||
| return Expression::Operation::kNotEq; | ||
| case Expression::Operation::kNotEq: | ||
| return Expression::Operation::kEq; | ||
| case Expression::Operation::kIn: | ||
| return Expression::Operation::kNotIn; | ||
| case Expression::Operation::kNotIn: | ||
| return Expression::Operation::kIn; | ||
| case Expression::Operation::kStartsWith: | ||
| return Expression::Operation::kNotStartsWith; | ||
| case Expression::Operation::kNotStartsWith: | ||
| return Expression::Operation::kStartsWith; | ||
| case Expression::Operation::kTrue: | ||
| case Expression::Operation::kFalse: | ||
| case Expression::Operation::kNot: | ||
|
Comment on lines
176
to
184
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't there be negations for these?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm following the Java impl: https://github.com/apache/iceberg/blob/main/api/src/main/java/org/apache/iceberg/expressions/Expression.java#L64-L97 |
||
| case Expression::Operation::kCountStar: | ||
| case Expression::Operation::kMax: | ||
| case Expression::Operation::kMin: | ||
| case Expression::Operation::kAnd: | ||
| case Expression::Operation::kOr: | ||
|
||
| case Expression::Operation::kCount: | ||
| return InvalidArgument("No negation for operation: {}", op); | ||
| } | ||
| std::unreachable(); | ||
| } | ||
|
|
||
| } // namespace iceberg | ||
Uh oh!
There was an error while loading. Please reload this page.