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
40 Result<std::shared_ptr<Expression>> AlwaysTrue() override;
41 Result<std::shared_ptr<Expression>> AlwaysFalse() override;
42 Result<std::shared_ptr<Expression>> Not(
43 const std::shared_ptr<Expression>& child_result) override;
44 Result<std::shared_ptr<Expression>> And(
45 const std::shared_ptr<Expression>& left_result,
46 const std::shared_ptr<Expression>& right_result) override;
47 Result<std::shared_ptr<Expression>> Or(
48 const std::shared_ptr<Expression>& left_result,
49 const std::shared_ptr<Expression>& right_result) override;
50 Result<std::shared_ptr<Expression>> Predicate(
51 const std::shared_ptr<BoundPredicate>& pred) override;
52 Result<std::shared_ptr<Expression>> Predicate(
53 const std::shared_ptr<UnboundPredicate>& pred) override;
54 Result<std::shared_ptr<Expression>> Aggregate(
55 const std::shared_ptr<BoundAggregate>& aggregate) override;
56 Result<std::shared_ptr<Expression>> Aggregate(
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
68 Result<bool> AlwaysTrue() override;
69 Result<bool> AlwaysFalse() override;
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
87 Result<FieldIdsSetRef> AlwaysTrue() override;
88 Result<FieldIdsSetRef> AlwaysFalse() override;
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;
95 Result<FieldIdsSetRef> Predicate(
96 const std::shared_ptr<UnboundPredicate>& pred) override;
97 Result<FieldIdsSetRef> Aggregate(
98 const std::shared_ptr<BoundAggregate>& aggregate) override;
99 Result<FieldIdsSetRef> Aggregate(
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
Base aggregate holding an operation and a term.
Definition aggregate.h:39
An Expression that represents a logical AND operation between two expressions.
Definition expression.h:139
Definition binder.h:32
Base visitor for traversing expression trees.
Definition expression_visitor.h:49
Definition binder.h:64
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
A predicate is a boolean expression that tests a term against some criteria.
Definition predicate.h:38
Visitor to collect referenced field IDs from an expression.
Definition binder.h:82
A schema for a Table.
Definition schema.h:49