-
Notifications
You must be signed in to change notification settings - Fork 70
feat:add init expression interface. #58
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
68298ed
feat:add init expression interface.
yingcai-cy d191747
Merge remote-tracking branch 'origin/main' into expr
yingcai-cy bcb7506
feat: expression interface apply review suggestions.
yingcai-cy 48be4c9
feat:expressin apply review comments.
yingcai-cy d3f6624
Merge branch 'main' into expr
yingcai-cy afd3935
feat: expression interface init commit, apply review suggestions.
yingcai-cy b3f4a43
Fix cmake file format.
yingcai-cy 672d938
Merge remote-tracking branch 'origin/main' into expr
yingcai-cy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include "iceberg/expression.h" | ||
|
|
||
| #include <unordered_map> | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| expected<Expression::Operation, Error> Expression::FromString( | ||
| const std::string& operation_type) { | ||
| std::string lowercase_op = operation_type; | ||
| std::transform(lowercase_op.begin(), lowercase_op.end(), lowercase_op.begin(), | ||
| [](unsigned char c) { return std::tolower(c); }); | ||
|
|
||
| static const std::unordered_map<std::string, Operation> op_map = { | ||
| {"true", Operation::kTrue}, | ||
| {"false", Operation::kFalse}, | ||
| {"is_null", Operation::kIsNull}, | ||
| {"not_null", Operation::kNotNull}, | ||
| {"is_nan", Operation::kIsNan}, | ||
| {"not_nan", Operation::kNotNan}, | ||
| {"lt", Operation::kLt}, | ||
| {"lt_eq", Operation::kLtEq}, | ||
| {"gt", Operation::kGt}, | ||
| {"gt_eq", Operation::kGtEq}, | ||
| {"eq", Operation::kEq}, | ||
| {"not_eq", Operation::kNotEq}, | ||
| {"in", Operation::kIn}, | ||
| {"not_in", Operation::kNotIn}, | ||
| {"not", Operation::kNot}, | ||
| {"and", Operation::kAnd}, | ||
| {"or", Operation::kOr}, | ||
| {"starts_with", Operation::kStartsWith}, | ||
| {"not_starts_with", Operation::kNotStartsWith}, | ||
| {"count", Operation::kCount}, | ||
| {"count_star", Operation::kCountStar}, | ||
| {"max", Operation::kMax}, | ||
| {"min", Operation::kMin}}; | ||
|
|
||
| auto it = op_map.find(lowercase_op); | ||
| if (it == op_map.end()) { | ||
| return unexpected<Error>( | ||
| {ErrorKind::kInvalidOperatorType, "Unknown operation type: " + operation_type}); | ||
| } | ||
| return it->second; | ||
| } | ||
|
|
||
| expected<Expression::Operation, Error> Expression::Negate(Operation op) { | ||
| switch (op) { | ||
| case Operation::kTrue: | ||
| return Operation::kFalse; | ||
| case Operation::kFalse: | ||
| return Operation::kTrue; | ||
| case Operation::kIsNull: | ||
| return Operation::kNotNull; | ||
| case Operation::kNotNull: | ||
| return Operation::kIsNull; | ||
| case Operation::kIsNan: | ||
| return Operation::kNotNan; | ||
| case Operation::kNotNan: | ||
| return Operation::kIsNan; | ||
| case Operation::kLt: | ||
| return Operation::kGtEq; | ||
| case Operation::kLtEq: | ||
| return Operation::kGt; | ||
| case Operation::kGt: | ||
| return Operation::kLtEq; | ||
| case Operation::kGtEq: | ||
| return Operation::kLt; | ||
| case Operation::kEq: | ||
| return Operation::kNotEq; | ||
| case Operation::kNotEq: | ||
| return Operation::kEq; | ||
| case Operation::kIn: | ||
| return Operation::kNotIn; | ||
| case Operation::kNotIn: | ||
| return Operation::kIn; | ||
| case Operation::kStartsWith: | ||
| return Operation::kNotStartsWith; | ||
| case Operation::kNotStartsWith: | ||
| return Operation::kStartsWith; | ||
| default: | ||
| return unexpected<Error>( | ||
| {ErrorKind::kInvalidOperatorType, "No negation defined for operation"}); | ||
| } | ||
| } | ||
|
|
||
| expected<Expression::Operation, Error> Expression::FlipLR(Operation op) { | ||
| switch (op) { | ||
| case Operation::kLt: | ||
| return Operation::kGt; | ||
| case Operation::kLtEq: | ||
| return Operation::kGtEq; | ||
| case Operation::kGt: | ||
| return Operation::kLt; | ||
| case Operation::kGtEq: | ||
| return Operation::kLtEq; | ||
| case Operation::kEq: | ||
| return Operation::kEq; | ||
| case Operation::kNotEq: | ||
| return Operation::kNotEq; | ||
| case Operation::kAnd: | ||
| return Operation::kAnd; | ||
| case Operation::kOr: | ||
| return Operation::kOr; | ||
| default: | ||
| return unexpected<Error>( | ||
| {ErrorKind::kInvalidOperatorType, "No left-right flip for operation"}); | ||
| } | ||
| } | ||
|
|
||
| } // namespace iceberg | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| /// \file iceberg/expression.h | ||
| /// Boolean expression tree for Iceberg table operations. | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "iceberg/error.h" | ||
| #include "iceberg/expected.h" | ||
| #include "iceberg/iceberg_export.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief Represents a boolean expression tree. | ||
| class ICEBERG_EXPORT Expression { | ||
yingcai-cy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public: | ||
| /// Operation types for expressions | ||
| enum class Operation { | ||
yingcai-cy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| kTrue, | ||
| kFalse, | ||
| kIsNull, | ||
| kNotNull, | ||
| kIsNan, | ||
| kNotNan, | ||
| kLt, | ||
| kLtEq, | ||
| kGt, | ||
| kGtEq, | ||
| kEq, | ||
| kNotEq, | ||
| kIn, | ||
| kNotIn, | ||
| kNot, | ||
| kAnd, | ||
| kOr, | ||
| kStartsWith, | ||
| kNotStartsWith, | ||
| kCount, | ||
| kCountStar, | ||
| kMax, | ||
| kMin | ||
Fokko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| virtual ~Expression() = default; | ||
|
|
||
| /// \brief Returns the operation for an expression node. | ||
| [[nodiscard]] virtual Operation Op() const = 0; | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// \brief Returns the negation of this expression, equivalent to not(this). | ||
| [[nodiscard]] virtual expected<std::shared_ptr<Expression>, Error> Negate() const { | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return unexpected<Error>( | ||
| {ErrorKind::kInvalidExpression, "This expression cannot be negated"}); | ||
| } | ||
|
|
||
| /// \brief Returns whether this expression will accept the same values as another. | ||
| /// | ||
| /// If this returns true, the expressions are guaranteed to return the same evaluation | ||
| /// for the same input. However, if this returns false the expressions may return the | ||
| /// same evaluation for the same input. That is, expressions may be equivalent even if | ||
| /// this returns false. | ||
| /// | ||
| /// For best results, rewrite not and bind expressions before calling this method. | ||
| /// | ||
| /// \param other another expression | ||
| /// \return true if the expressions are equivalent | ||
| [[nodiscard]] virtual bool IsEquivalentTo(const Expression& other) const { | ||
| // only bound predicates can be equivalent | ||
| return false; | ||
| } | ||
|
|
||
| /// \brief Convert operation string to enum | ||
| static expected<Operation, Error> FromString(const std::string& operation_type); | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// \brief Returns the operation used when this is negated. | ||
| static expected<Operation, Error> Negate(Operation op); | ||
|
|
||
| /// \brief Returns the equivalent operation when the left and right operands are | ||
| /// exchanged. | ||
| static expected<Operation, Error> FlipLR(Operation op); | ||
| }; | ||
|
|
||
| } // namespace iceberg | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.