Skip to content

Commit f7d97ca

Browse files
committed
use concepts and remove ArrowArray
1 parent 5a49c08 commit f7d97ca

File tree

6 files changed

+37
-42
lines changed

6 files changed

+37
-42
lines changed

src/iceberg/expression/expressions.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ std::shared_ptr<UnboundPredicate<BoundReference>> Expressions::Predicate(
307307
std::move(values));
308308
}
309309

310+
std::shared_ptr<UnboundPredicate<BoundReference>> Expressions::Predicate(
311+
Expression::Operation op, std::string name, std::initializer_list<Literal> values) {
312+
return Predicate(op, name, std::vector<Literal>(values));
313+
}
314+
310315
std::shared_ptr<UnboundPredicate<BoundReference>> Expressions::Predicate(
311316
Expression::Operation op, std::string name) {
312317
return std::make_shared<UnboundPredicate<BoundReference>>(op, Ref(std::move(name)));
@@ -319,6 +324,13 @@ std::shared_ptr<UnboundPredicate<B>> Expressions::Predicate(
319324
return std::make_shared<UnboundPredicate<B>>(op, std::move(expr), std::move(values));
320325
}
321326

327+
template <typename B>
328+
std::shared_ptr<UnboundPredicate<B>> Expressions::Predicate(
329+
Expression::Operation op, std::shared_ptr<UnboundTerm<B>> expr,
330+
std::initializer_list<Literal> values) {
331+
return Predicate<B>(op, std::move(expr), std::vector<Literal>(values));
332+
}
333+
322334
template <typename B>
323335
std::shared_ptr<UnboundPredicate<B>> Expressions::Predicate(
324336
Expression::Operation op, std::shared_ptr<UnboundTerm<B>> expr) {

src/iceberg/expression/expressions.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ class ICEBERG_EXPORT Expressions {
228228
static std::shared_ptr<UnboundPredicate<BoundReference>> Predicate(
229229
Expression::Operation op, std::string name, std::vector<Literal> values);
230230

231+
/// \brief Create a predicate with operation and multiple values.
232+
static std::shared_ptr<UnboundPredicate<BoundReference>> Predicate(
233+
Expression::Operation op, std::string name, std::initializer_list<Literal> values);
234+
231235
/// \brief Create a unary predicate (no values).
232236
static std::shared_ptr<UnboundPredicate<BoundReference>> Predicate(
233237
Expression::Operation op, std::string name);
@@ -238,6 +242,12 @@ class ICEBERG_EXPORT Expressions {
238242
Expression::Operation op, std::shared_ptr<UnboundTerm<B>> expr,
239243
std::vector<Literal> values);
240244

245+
/// \brief Create a predicate with operation and multiple values.
246+
template <typename B>
247+
static std::shared_ptr<UnboundPredicate<B>> Predicate(
248+
Expression::Operation op, std::shared_ptr<UnboundTerm<B>> expr,
249+
std::initializer_list<Literal> values);
250+
241251
/// \brief Create a unary predicate for unbound term.
242252
template <typename B>
243253
static std::shared_ptr<UnboundPredicate<B>> Predicate(

src/iceberg/expression/predicate.cc

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
namespace iceberg {
3434

3535
// Predicate template implementations
36-
template <typename TermType>
37-
Predicate<TermType>::Predicate(Expression::Operation op, std::shared_ptr<TermType> term)
36+
template <TermType T>
37+
Predicate<T>::Predicate(Expression::Operation op, std::shared_ptr<T> term)
3838
: operation_(op), term_(std::move(term)) {}
3939

40-
template <typename TermType>
41-
Predicate<TermType>::~Predicate() = default;
40+
template <TermType T>
41+
Predicate<T>::~Predicate() = default;
4242

4343
// UnboundPredicate template implementations
4444
template <typename B>
@@ -289,18 +289,6 @@ Result<Literal::Value> BoundPredicate::Evaluate(const StructLike& data) const {
289289
return Literal::Value{test_result};
290290
}
291291

292-
Result<std::vector<Literal::Value>> BoundPredicate::Evaluate(
293-
const ArrowArray& data) const {
294-
ICEBERG_ASSIGN_OR_RAISE(auto eval_result, term_->Evaluate(data));
295-
std::vector<Literal::Value> result;
296-
result.reserve(eval_result.size());
297-
for (const auto& value : eval_result) {
298-
ICEBERG_ASSIGN_OR_RAISE(auto test_result, Test(value));
299-
result.emplace_back(test_result);
300-
}
301-
return result;
302-
}
303-
304292
// BoundUnaryPredicate implementation
305293
BoundUnaryPredicate::BoundUnaryPredicate(Expression::Operation op,
306294
std::shared_ptr<BoundTerm> term)

src/iceberg/expression/predicate.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,38 @@
2222
/// \file iceberg/expression/predicate.h
2323
/// Predicate interface for boolean expressions that test terms.
2424

25+
#include <concepts>
26+
2527
#include "iceberg/expression/expression.h"
2628
#include "iceberg/expression/term.h"
2729

2830
namespace iceberg {
2931

32+
template <typename T>
33+
concept TermType = std::derived_from<T, Term>;
34+
3035
/// \brief A predicate is a boolean expression that tests a term against some criteria.
3136
///
3237
/// \tparam TermType The type of the term being tested
33-
template <typename TermType>
38+
template <TermType T>
3439
class ICEBERG_EXPORT Predicate : public Expression {
3540
public:
3641
/// \brief Create a predicate with an operation and term.
3742
///
3843
/// \param op The operation this predicate performs
3944
/// \param term The term this predicate tests
40-
Predicate(Expression::Operation op, std::shared_ptr<TermType> term);
45+
Predicate(Expression::Operation op, std::shared_ptr<T> term);
4146

4247
~Predicate() override;
4348

4449
Expression::Operation op() const override { return operation_; }
4550

4651
/// \brief Returns the term this predicate tests.
47-
const std::shared_ptr<TermType>& term() const { return term_; }
52+
const std::shared_ptr<T>& term() const { return term_; }
4853

4954
protected:
5055
Expression::Operation operation_;
51-
std::shared_ptr<TermType> term_;
56+
std::shared_ptr<T> term_;
5257
};
5358

5459
/// \brief Unbound predicates contain unbound terms and must be bound to a concrete schema
@@ -108,8 +113,6 @@ class ICEBERG_EXPORT BoundPredicate : public Predicate<BoundTerm>, public Bound
108113

109114
Result<Literal::Value> Evaluate(const StructLike& data) const override;
110115

111-
Result<std::vector<Literal::Value>> Evaluate(const ArrowArray& data) const override;
112-
113116
/// \brief Test a value against this predicate.
114117
///
115118
/// \param value The value to test
@@ -122,7 +125,7 @@ class ICEBERG_EXPORT BoundPredicate : public Predicate<BoundTerm>, public Bound
122125
// A literal predicate (compares against a literal).
123126
kLiteral,
124127
// A set predicate (tests membership in a set).
125-
kIn,
128+
kSet,
126129
};
127130

128131
/// \brief Returns the kind of this bound predicate.
@@ -195,7 +198,7 @@ class ICEBERG_EXPORT BoundSetPredicate : public BoundPredicate {
195198

196199
Result<bool> Test(const Literal::Value& value) const override;
197200

198-
Kind kind() const override { return Kind::kIn; }
201+
Kind kind() const override { return Kind::kSet; }
199202

200203
std::string ToString() const override;
201204

src/iceberg/expression/term.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ Result<Literal::Value> BoundReference::Evaluate(const StructLike& data) const {
7979
return NotImplemented("BoundReference::Evaluate(StructLike) not implemented");
8080
}
8181

82-
Result<std::vector<Literal::Value>> BoundReference::Evaluate(
83-
const ArrowArray& data) const {
84-
return NotImplemented("BoundReference::Evaluate(ArrowArray) not implemented");
85-
}
86-
8782
bool BoundReference::Equals(const BoundTerm& other) const {
8883
if (other.kind() != Term::Kind::kReference) {
8984
return false;
@@ -132,11 +127,6 @@ Result<Literal::Value> BoundTransform::Evaluate(const StructLike& data) const {
132127
throw IcebergError("BoundTransform::Evaluate(StructLike) not implemented");
133128
}
134129

135-
Result<std::vector<Literal::Value>> BoundTransform::Evaluate(
136-
const ArrowArray& data) const {
137-
throw IcebergError("BoundTransform::Evaluate(ArrowArray) not implemented");
138-
}
139-
140130
bool BoundTransform::MayProduceNull() const {
141131
// transforms must produce null for null input values
142132
// transforms may produce null for non-null inputs when not order-preserving

src/iceberg/expression/term.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <string>
2727
#include <string_view>
2828

29-
#include "iceberg/arrow_c_data.h"
3029
#include "iceberg/expression/literal.h"
3130
#include "iceberg/type_fwd.h"
3231
#include "iceberg/util/formattable.h"
@@ -82,9 +81,6 @@ class ICEBERG_EXPORT Bound {
8281
/// \brief Evaluate this expression against a row-based data.
8382
virtual Result<Literal::Value> Evaluate(const StructLike& data) const = 0;
8483

85-
/// \brief Evaluate this expression against an Arrow array.
86-
virtual Result<std::vector<Literal::Value>> Evaluate(const ArrowArray& data) const = 0;
87-
8884
/// \brief Returns the underlying bound reference for this term.
8985
virtual std::shared_ptr<class BoundReference> reference() = 0;
9086
};
@@ -182,8 +178,6 @@ class ICEBERG_EXPORT BoundReference
182178

183179
Result<Literal::Value> Evaluate(const StructLike& data) const override;
184180

185-
Result<std::vector<Literal::Value>> Evaluate(const ArrowArray& data) const override;
186-
187181
std::shared_ptr<BoundReference> reference() override { return shared_from_this(); }
188182

189183
std::shared_ptr<Type> type() const override { return field_.type(); }
@@ -244,8 +238,6 @@ class ICEBERG_EXPORT BoundTransform : public BoundTerm {
244238

245239
Result<Literal::Value> Evaluate(const StructLike& data) const override;
246240

247-
Result<std::vector<Literal::Value>> Evaluate(const ArrowArray& data) const override;
248-
249241
std::shared_ptr<BoundReference> reference() override { return ref_; }
250242

251243
std::shared_ptr<Type> type() const override;

0 commit comments

Comments
 (0)