-
Notifications
You must be signed in to change notification settings - Fork 66
feat: add expression visitors #311
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
Open
wgtmac
wants to merge
9
commits into
apache:main
Choose a base branch
from
wgtmac:expr_visitor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a743525
feat: add expression visitors
wgtmac c8a9a7f
Update src/iceberg/expression/expression_visitor.h
wgtmac 39c4f9c
Update src/iceberg/expression/expression_visitor.h
wgtmac 095d428
Update src/iceberg/expression/expression_visitor.h
wgtmac b615c68
Update src/iceberg/expression/expression_visitor.h
wgtmac 79efeee
Update src/iceberg/expression/expression.h
wgtmac f0bff76
Update src/iceberg/expression/expression.h
wgtmac 0d26f4a
Update src/iceberg/expression/expression.h
wgtmac 18fcee6
Update src/iceberg/expression/expression.cc
wgtmac 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,95 @@ | ||
| /* | ||
| * 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/binder.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| Binder::Binder(const Schema& schema, bool case_sensitive) | ||
| : schema_(schema), case_sensitive_(case_sensitive) {} | ||
|
|
||
| Result<std::shared_ptr<Expression>> Binder::Bind(const Schema& schema, | ||
| const std::shared_ptr<Expression>& expr, | ||
| bool case_sensitive) { | ||
| Binder binder(schema, case_sensitive); | ||
| return Visit<std::shared_ptr<Expression>, Binder>(expr, binder); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Binder::AlwaysTrue() { return True::Instance(); } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Binder::AlwaysFalse() { return False::Instance(); } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Binder::Not( | ||
| const std::shared_ptr<Expression>& child_result) { | ||
| return iceberg::Not::MakeFolded(child_result); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Binder::And( | ||
| const std::shared_ptr<Expression>& left_result, | ||
| const std::shared_ptr<Expression>& right_result) { | ||
| return iceberg::And::MakeFolded(left_result, right_result); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Binder::Or( | ||
| const std::shared_ptr<Expression>& left_result, | ||
| const std::shared_ptr<Expression>& right_result) { | ||
| return iceberg::Or::MakeFolded(left_result, right_result); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Binder::Predicate( | ||
| const std::shared_ptr<UnboundPredicate>& pred) { | ||
| ICEBERG_DCHECK(pred != nullptr, "Predicate cannot be null"); | ||
| return pred->Bind(schema_, case_sensitive_); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<Expression>> Binder::Predicate( | ||
| const std::shared_ptr<BoundPredicate>& pred) { | ||
| ICEBERG_DCHECK(pred != nullptr, "Predicate cannot be null"); | ||
| return InvalidExpression("Found already bound predicate: {}", pred->ToString()); | ||
| } | ||
|
|
||
| Result<bool> IsBoundVisitor::IsBound(const std::shared_ptr<Expression>& expr) { | ||
| ICEBERG_DCHECK(expr != nullptr, "Expression cannot be null"); | ||
| IsBoundVisitor visitor; | ||
| return Visit<bool, IsBoundVisitor>(expr, visitor); | ||
| } | ||
|
|
||
| Result<bool> IsBoundVisitor::AlwaysTrue() { return true; } | ||
|
|
||
| Result<bool> IsBoundVisitor::AlwaysFalse() { return true; } | ||
|
|
||
| Result<bool> IsBoundVisitor::Not(bool child_result) { return child_result; } | ||
|
|
||
| Result<bool> IsBoundVisitor::And(bool left_result, bool right_result) { | ||
| return left_result && right_result; | ||
| } | ||
|
|
||
| Result<bool> IsBoundVisitor::Or(bool left_result, bool right_result) { | ||
| return left_result && right_result; | ||
| } | ||
|
|
||
| Result<bool> IsBoundVisitor::Predicate(const std::shared_ptr<BoundPredicate>& pred) { | ||
| return true; | ||
| } | ||
|
|
||
| Result<bool> IsBoundVisitor::Predicate(const std::shared_ptr<UnboundPredicate>& pred) { | ||
| 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,72 @@ | ||
| /* | ||
| * 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/binder.h | ||
| /// Bind an expression to a schema. | ||
|
|
||
| #include "iceberg/expression/expression_visitor.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| class ICEBERG_EXPORT Binder : public ExpressionVisitor<std::shared_ptr<Expression>> { | ||
| public: | ||
| Binder(const Schema& schema, bool case_sensitive); | ||
|
|
||
| static Result<std::shared_ptr<Expression>> Bind(const Schema& schema, | ||
| const std::shared_ptr<Expression>& expr, | ||
| bool case_sensitive); | ||
|
|
||
| Result<std::shared_ptr<Expression>> AlwaysTrue() override; | ||
| Result<std::shared_ptr<Expression>> AlwaysFalse() override; | ||
| Result<std::shared_ptr<Expression>> Not( | ||
| const std::shared_ptr<Expression>& child_result) override; | ||
| Result<std::shared_ptr<Expression>> And( | ||
| const std::shared_ptr<Expression>& left_result, | ||
| const std::shared_ptr<Expression>& right_result) override; | ||
| Result<std::shared_ptr<Expression>> Or( | ||
| const std::shared_ptr<Expression>& left_result, | ||
| const std::shared_ptr<Expression>& right_result) override; | ||
| Result<std::shared_ptr<Expression>> Predicate( | ||
| const std::shared_ptr<BoundPredicate>& pred) override; | ||
| Result<std::shared_ptr<Expression>> Predicate( | ||
| const std::shared_ptr<UnboundPredicate>& pred) override; | ||
|
|
||
| private: | ||
| const Schema& schema_; | ||
| const bool case_sensitive_; | ||
| }; | ||
|
|
||
| class ICEBERG_EXPORT IsBoundVisitor : public ExpressionVisitor<bool> { | ||
| public: | ||
| static Result<bool> IsBound(const std::shared_ptr<Expression>& expr); | ||
|
|
||
| Result<bool> AlwaysTrue() override; | ||
| Result<bool> AlwaysFalse() override; | ||
| Result<bool> Not(bool child_result) override; | ||
| Result<bool> And(bool left_result, bool right_result) override; | ||
| Result<bool> Or(bool left_result, bool right_result) override; | ||
| Result<bool> Predicate(const std::shared_ptr<BoundPredicate>& pred) override; | ||
| Result<bool> Predicate(const std::shared_ptr<UnboundPredicate>& pred) override; | ||
| }; | ||
|
|
||
| // TODO(gangwu): add the Java parity `ReferenceVisitor` | ||
|
|
||
| } // 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
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.
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.