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 <optional>
27#include <unordered_set>
28
30
31namespace iceberg {
32
33class ICEBERG_EXPORT Binder : public ExpressionVisitor<std::shared_ptr<Expression>> {
34 public:
35 Binder(const Schema& schema, bool case_sensitive);
36
37 static Result<std::shared_ptr<Expression>> Bind(const Schema& schema,
38 const std::shared_ptr<Expression>& expr,
39 bool case_sensitive);
40
44 const std::shared_ptr<Expression>& child_result) override;
46 const std::shared_ptr<Expression>& left_result,
47 const std::shared_ptr<Expression>& right_result) override;
49 const std::shared_ptr<Expression>& left_result,
50 const std::shared_ptr<Expression>& right_result) override;
52 const std::shared_ptr<BoundPredicate>& pred) override;
54 const std::shared_ptr<UnboundPredicate>& pred) override;
56 const std::shared_ptr<BoundAggregate>& aggregate) override;
58 const std::shared_ptr<UnboundAggregate>& aggregate) override;
59
60 private:
61 const Schema& schema_;
62 const bool case_sensitive_;
63};
64
65class ICEBERG_EXPORT IsBoundVisitor : public ExpressionVisitor<std::optional<bool>> {
66 public:
67 static Result<bool> IsBound(const std::shared_ptr<Expression>& expr);
68
71 Result<std::optional<bool>> Not(const std::optional<bool>& child_result) override;
72 Result<std::optional<bool>> And(const std::optional<bool>& left_result,
73 const std::optional<bool>& right_result) override;
74 Result<std::optional<bool>> Or(const std::optional<bool>& left_result,
75 const std::optional<bool>& right_result) override;
77 const std::shared_ptr<BoundPredicate>& pred) override;
79 const std::shared_ptr<UnboundPredicate>& pred) override;
81 const std::shared_ptr<BoundAggregate>& aggregate) override;
83 const std::shared_ptr<UnboundAggregate>& aggregate) override;
84};
85
86using FieldIdsSetRef = std::reference_wrapper<std::unordered_set<int32_t>>;
87
89class ICEBERG_EXPORT ReferenceVisitor : public ExpressionVisitor<FieldIdsSetRef> {
90 public:
91 static Result<std::unordered_set<int32_t>> GetReferencedFieldIds(
92 const std::shared_ptr<Expression>& expr);
93
96 Result<FieldIdsSetRef> Not(const FieldIdsSetRef& child_result) override;
97 Result<FieldIdsSetRef> And(const FieldIdsSetRef& left_result,
98 const FieldIdsSetRef& right_result) override;
99 Result<FieldIdsSetRef> Or(const FieldIdsSetRef& left_result,
100 const FieldIdsSetRef& right_result) override;
101 Result<FieldIdsSetRef> Predicate(const std::shared_ptr<BoundPredicate>& pred) override;
103 const std::shared_ptr<UnboundPredicate>& pred) override;
105 const std::shared_ptr<BoundAggregate>& aggregate) override;
107 const std::shared_ptr<UnboundAggregate>& aggregate) override;
108
109 private:
110 std::unordered_set<int32_t> referenced_field_ids_;
111};
112
113} // namespace iceberg
An Expression that represents a logical AND operation between two expressions.
Definition expression.h:139
Definition binder.h:33
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:65
Result< std::optional< bool > > Aggregate(const std::shared_ptr< BoundAggregate > &aggregate) override
Visit a bound aggregate.
Result< std::optional< bool > > AlwaysFalse() override
Visit a False expression (always evaluates to false).
Result< std::optional< bool > > Aggregate(const std::shared_ptr< UnboundAggregate > &aggregate) override
Visit an unbound aggregate.
Result< std::optional< bool > > Predicate(const std::shared_ptr< BoundPredicate > &pred) override
Visit a bound predicate.
Result< std::optional< bool > > Predicate(const std::shared_ptr< UnboundPredicate > &pred) override
Visit an unbound predicate.
Result< std::optional< bool > > AlwaysTrue() override
Visit a True expression (always evaluates to true).
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:89
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
Definition expected.h:1199
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34