-
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 3 commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * 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 | ||
| /// Expression interface for Iceberg table operations. | ||
|
|
||
| #include "iceberg/expected.h" | ||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/result.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief Represents a boolean expression tree. | ||
| class ICEBERG_EXPORT Expression { | ||
| 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. | ||
| virtual Operation Op() const = 0; | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// \brief Returns the negation of this expression, equivalent to not(this). | ||
| virtual Result<std::shared_ptr<Expression>> Negate() const { | ||
yingcai-cy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return unexpected( | ||
| Error(ErrorKind::kInvalidExpression, "Expression cannot be negated")); | ||
| } | ||
|
|
||
| /// \brief Returns whether this expression will accept the same values as another. | ||
| /// \param other another expression | ||
| /// \return true if the expressions are equivalent | ||
| virtual bool IsEquivalentTo(const Expression& other) const { | ||
| // only bound predicates can be equivalent | ||
| return false; | ||
| } | ||
|
|
||
| virtual std::string ToString() const { return "Expression"; } | ||
| }; | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * 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 "and.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| And::And(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right) | ||
| : left_(std::move(left)), right_(std::move(right)) {} | ||
|
|
||
| bool And::IsEquivalentTo(const Expression& expr) const { | ||
| if (expr.Op() == Operation::kAnd) { | ||
| const auto& other = static_cast<const And&>(expr); | ||
| return (left_->IsEquivalentTo(*other.left()) && | ||
| right_->IsEquivalentTo(*other.right())) || | ||
| (left_->IsEquivalentTo(*other.right()) && | ||
| right_->IsEquivalentTo(*other.left())); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| #include <format> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "iceberg/expression.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief An Expression that represents a logical AND operation between two expressions. | ||
| /// | ||
| /// This expression evaluates to true if and only if both of its child expressions | ||
| /// evaluate to true. | ||
| class ICEBERG_EXPORT And : public Expression { | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public: | ||
| /// \brief Constructs an And expression from two sub-expressions. | ||
| /// | ||
| /// @param left The left operand of the AND expression | ||
| /// @param right The right operand of the AND expression | ||
| And(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right); | ||
|
|
||
| /// \brief Returns the left operand of the AND expression. | ||
| /// | ||
| /// @return The left operand of the AND expression | ||
| const std::shared_ptr<Expression>& left() const { return left_; } | ||
|
|
||
| /// \brief Returns the right operand of the AND expression. | ||
| /// | ||
| /// @return The right operand of the AND expression | ||
| const std::shared_ptr<Expression>& right() const { return right_; } | ||
|
|
||
| Operation Op() const override { return Operation::kAnd; } | ||
|
|
||
| std::string ToString() const override { | ||
| return std::format("({} and {})", left_->ToString(), right_->ToString()); | ||
| } | ||
|
|
||
| // implement Negate later | ||
| // expected<std::shared_ptr<Expression>, Error> Negate() const override; | ||
|
|
||
| bool IsEquivalentTo(const Expression& other) const override; | ||
|
|
||
| private: | ||
| std::shared_ptr<Expression> left_; | ||
| std::shared_ptr<Expression> right_; | ||
| }; | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * 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 "false.h" | ||
|
|
||
| #include "true.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| expected<std::shared_ptr<Expression>, Error> False::Negate() const { | ||
| return True::shared_instance(); | ||
| } | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "iceberg/expression.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief An expression that is always false. | ||
| class ICEBERG_EXPORT False : public Expression { | ||
| public: | ||
| static const False& instance() { | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static False instance; | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return instance; | ||
| } | ||
|
|
||
| static const std::shared_ptr<Expression>& shared_instance() { | ||
yingcai-cy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static std::shared_ptr<Expression> instance = std::shared_ptr<Expression>( | ||
| const_cast<False*>(&False::instance()), [](Expression*) {}); | ||
| return instance; | ||
| } | ||
|
|
||
| Operation Op() const override { return Operation::kFalse; } | ||
|
|
||
| std::string ToString() const override { return "false"; } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Negate() const override; | ||
|
|
||
| bool IsEquivalentTo(const Expression& other) const override { | ||
| return other.Op() == Operation::kFalse; | ||
| } | ||
|
|
||
| private: | ||
| constexpr False() = default; | ||
| }; | ||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * 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 "true.h" | ||
|
|
||
| #include "false.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| Result<std::shared_ptr<Expression>> True::Negate() const { | ||
| return False::shared_instance(); | ||
| } | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "iceberg/expression.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief An Expression that is always true. | ||
| /// | ||
| /// Represents a boolean predicate that always evaluates to true. | ||
| class ICEBERG_EXPORT True : public Expression { | ||
| public: | ||
| static const True& instance() { | ||
| static True instance; | ||
| return instance; | ||
| } | ||
|
|
||
| static const std::shared_ptr<Expression>& shared_instance() { | ||
| static std::shared_ptr<Expression> instance = std::shared_ptr<Expression>( | ||
| const_cast<True*>(&True::instance()), [](Expression*) {}); | ||
| return instance; | ||
| } | ||
|
|
||
| Operation Op() const override { return Operation::kTrue; } | ||
|
|
||
| std::string ToString() const override { return "true"; } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Negate() const override; | ||
|
|
||
| bool IsEquivalentTo(const Expression& other) const override { | ||
| return other.Op() == Operation::kTrue; | ||
| } | ||
|
|
||
| private: | ||
| constexpr True() = default; | ||
| }; | ||
|
|
||
| } // 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.