iceberg-cpp
Loading...
Searching...
No Matches
binder.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <functional>
26#include <unordered_set>
27
29
30namespace iceberg {
31
32class ICEBERG_EXPORT Binder : public ExpressionVisitor<std::shared_ptr<Expression>> {
33 public:
34 Binder(const Schema& schema, bool case_sensitive);
35
36 static Result<std::shared_ptr<Expression>> Bind(const Schema& schema,
37 const std::shared_ptr<Expression>& expr,
38 bool case_sensitive);
39
43 const std::shared_ptr<Expression>& child_result) override;
45 const std::shared_ptr<Expression>& left_result,
46 const std::shared_ptr<Expression>& right_result) override;
48 const std::shared_ptr<Expression>& left_result,
49 const std::shared_ptr<Expression>& right_result) override;
51 const std::shared_ptr<BoundPredicate>& pred) override;
53 const std::shared_ptr<UnboundPredicate>& pred) override;
55 const std::shared_ptr<BoundAggregate>& aggregate) override;
57 const std::shared_ptr<UnboundAggregate>& aggregate) override;
58
59 private:
60 const Schema& schema_;
61 const bool case_sensitive_;
62};
63
64class ICEBERG_EXPORT IsBoundVisitor : public ExpressionVisitor<bool> {
65 public:
66 static Result<bool> IsBound(const std::shared_ptr<Expression>& expr);
67
70 Result<bool> Not(bool child_result) override;
71 Result<bool> And(bool left_result, bool right_result) override;
72 Result<bool> Or(bool left_result, bool right_result) override;
73 Result<bool> Predicate(const std::shared_ptr<BoundPredicate>& pred) override;
74 Result<bool> Predicate(const std::shared_ptr<UnboundPredicate>& pred) override;
75 Result<bool> Aggregate(const std::shared_ptr<BoundAggregate>& aggregate) override;
76 Result<bool> Aggregate(const std::shared_ptr<UnboundAggregate>& aggregate) override;
77};
78
79using FieldIdsSetRef = std::reference_wrapper<std::unordered_set<int32_t>>;
80
82class ICEBERG_EXPORT ReferenceVisitor : public ExpressionVisitor<FieldIdsSetRef> {
83 public:
84 static Result<std::unordered_set<int32_t>> GetReferencedFieldIds(
85 const std::shared_ptr<Expression>& expr);
86
89 Result<FieldIdsSetRef> Not(const FieldIdsSetRef& child_result) override;
90 Result<FieldIdsSetRef> And(const FieldIdsSetRef& left_result,
91 const FieldIdsSetRef& right_result) override;
92 Result<FieldIdsSetRef> Or(const FieldIdsSetRef& left_result,
93 const FieldIdsSetRef& right_result) override;
94 Result<FieldIdsSetRef> Predicate(const std::shared_ptr<BoundPredicate>& pred) override;
96 const std::shared_ptr<UnboundPredicate>& pred) override;
98 const std::shared_ptr<BoundAggregate>& aggregate) override;
100 const std::shared_ptr<UnboundAggregate>& aggregate) override;
101
102 private:
103 std::unordered_set<int32_t> referenced_field_ids_;
104};
105
106} // namespace iceberg
An Expression that represents a logical AND operation between two expressions.
Definition expression.h:139
Definition binder.h:32
Result< std::shared_ptr< Expression > > AlwaysFalse() override
Visit a False expression (always evaluates to false).
Result< std::shared_ptr< Expression > > Predicate(const std::shared_ptr< UnboundPredicate > &pred) override
Visit an unbound predicate.
Result< std::shared_ptr< Expression > > Aggregate(const std::shared_ptr< UnboundAggregate > &aggregate) override
Visit an unbound aggregate.
Result< std::shared_ptr< Expression > > Aggregate(const std::shared_ptr< BoundAggregate > &aggregate) override
Visit a bound aggregate.
Result< std::shared_ptr< Expression > > Predicate(const std::shared_ptr< BoundPredicate > &pred) override
Visit a bound predicate.
Result< std::shared_ptr< Expression > > AlwaysTrue() override
Visit a True expression (always evaluates to true).
Base visitor for traversing expression trees.
Definition expression_visitor.h:49
Definition binder.h:64
Result< bool > Aggregate(const std::shared_ptr< UnboundAggregate > &aggregate) override
Visit an unbound aggregate.
Result< bool > AlwaysFalse() override
Visit a False expression (always evaluates to false).
Result< bool > Predicate(const std::shared_ptr< BoundPredicate > &pred) override
Visit a bound predicate.
Result< bool > AlwaysTrue() override
Visit a True expression (always evaluates to true).
Result< bool > Aggregate(const std::shared_ptr< BoundAggregate > &aggregate) override
Visit a bound aggregate.
Result< bool > Predicate(const std::shared_ptr< UnboundPredicate > &pred) override
Visit an unbound predicate.
An Expression that represents logical NOT operation.
Definition expression.h:289
An Expression that represents a logical OR operation between two expressions.
Definition expression.h:215
Visitor to collect referenced field IDs from an expression.
Definition binder.h:82
Result< FieldIdsSetRef > AlwaysTrue() override
Visit a True expression (always evaluates to true).
Result< FieldIdsSetRef > Aggregate(const std::shared_ptr< UnboundAggregate > &aggregate) override
Visit an unbound aggregate.
Result< FieldIdsSetRef > Predicate(const std::shared_ptr< BoundPredicate > &pred) override
Visit a bound predicate.
Result< FieldIdsSetRef > Aggregate(const std::shared_ptr< BoundAggregate > &aggregate) override
Visit a bound aggregate.
Result< FieldIdsSetRef > AlwaysFalse() override
Visit a False expression (always evaluates to false).
Result< FieldIdsSetRef > Predicate(const std::shared_ptr< UnboundPredicate > &pred) override
Visit an unbound predicate.
A schema for a Table.
Definition schema.h:51
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88