Skip to content

Commit e2df46f

Browse files
committed
refactor: use StructType instead of Schema for unbound term
1 parent da91626 commit e2df46f

23 files changed

+247
-202
lines changed

src/iceberg/expression/aggregate.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ bool MinAggregate::HasValue(const DataFile& file) const {
467467

468468
template <typename B>
469469
Result<std::shared_ptr<Expression>> UnboundAggregateImpl<B>::Bind(
470-
const Schema& schema, bool case_sensitive) const {
470+
const StructType& struct_, bool case_sensitive) const {
471471
ICEBERG_DCHECK(UnboundAggregateImpl<B>::IsSupportedOp(this->op()),
472472
"Unexpected aggregate operation");
473473

474474
std::shared_ptr<B> bound_term;
475475
if (this->term()) {
476-
ICEBERG_ASSIGN_OR_RAISE(bound_term, this->term()->Bind(schema, case_sensitive));
476+
ICEBERG_ASSIGN_OR_RAISE(bound_term, this->term()->Bind(struct_, case_sensitive));
477477
}
478478

479479
switch (this->op()) {

src/iceberg/expression/aggregate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class ICEBERG_EXPORT UnboundAggregateImpl : public UnboundAggregate,
8484
return BASE::term() ? BASE::term()->reference() : nullptr;
8585
}
8686

87-
Result<std::shared_ptr<Expression>> Bind(const Schema& schema,
87+
Result<std::shared_ptr<Expression>> Bind(const StructType& struct_,
8888
bool case_sensitive) const override;
8989

9090
private:

src/iceberg/expression/binder.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
namespace iceberg {
2323

24-
Binder::Binder(const Schema& schema, bool case_sensitive)
25-
: schema_(schema), case_sensitive_(case_sensitive) {}
24+
Binder::Binder(const StructType& struct_, bool case_sensitive)
25+
: struct_(struct_), case_sensitive_(case_sensitive) {}
2626

27-
Result<std::shared_ptr<Expression>> Binder::Bind(const Schema& schema,
27+
Result<std::shared_ptr<Expression>> Binder::Bind(const StructType& struct_,
2828
const std::shared_ptr<Expression>& expr,
2929
bool case_sensitive) {
30-
Binder binder(schema, case_sensitive);
30+
Binder binder(struct_, case_sensitive);
3131
return Visit<std::shared_ptr<Expression>, Binder>(expr, binder);
3232
}
3333

@@ -55,7 +55,7 @@ Result<std::shared_ptr<Expression>> Binder::Or(
5555
Result<std::shared_ptr<Expression>> Binder::Predicate(
5656
const std::shared_ptr<UnboundPredicate>& pred) {
5757
ICEBERG_DCHECK(pred != nullptr, "Predicate cannot be null");
58-
return pred->Bind(schema_, case_sensitive_);
58+
return pred->Bind(struct_, case_sensitive_);
5959
}
6060

6161
Result<std::shared_ptr<Expression>> Binder::Predicate(
@@ -73,7 +73,7 @@ Result<std::shared_ptr<Expression>> Binder::Aggregate(
7373
Result<std::shared_ptr<Expression>> Binder::Aggregate(
7474
const std::shared_ptr<UnboundAggregate>& aggregate) {
7575
ICEBERG_DCHECK(aggregate != nullptr, "Aggregate cannot be null");
76-
return aggregate->Bind(schema_, case_sensitive_);
76+
return aggregate->Bind(struct_, case_sensitive_);
7777
}
7878

7979
Result<bool> IsBoundVisitor::IsBound(const std::shared_ptr<Expression>& expr) {

src/iceberg/expression/binder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ namespace iceberg {
2828

2929
class ICEBERG_EXPORT Binder : public ExpressionVisitor<std::shared_ptr<Expression>> {
3030
public:
31-
Binder(const Schema& schema, bool case_sensitive);
31+
Binder(const StructType& struct_, bool case_sensitive);
3232

33-
static Result<std::shared_ptr<Expression>> Bind(const Schema& schema,
33+
static Result<std::shared_ptr<Expression>> Bind(const StructType& struct_,
3434
const std::shared_ptr<Expression>& expr,
3535
bool case_sensitive);
3636

@@ -54,7 +54,7 @@ class ICEBERG_EXPORT Binder : public ExpressionVisitor<std::shared_ptr<Expressio
5454
const std::shared_ptr<UnboundAggregate>& aggregate) override;
5555

5656
private:
57-
const Schema& schema_;
57+
const StructType& struct_;
5858
const bool case_sensitive_;
5959
};
6060

src/iceberg/expression/expression.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ class ICEBERG_EXPORT Unbound {
340340
public:
341341
/// \brief Bind this expression to a concrete schema.
342342
///
343-
/// \param schema The schema to bind against
343+
/// \param struct_ The struct type (or schema) to bind against
344344
/// \param case_sensitive Whether field name matching should be case sensitive
345345
/// \return A bound expression or an error if binding fails
346-
virtual Result<std::shared_ptr<B>> Bind(const Schema& schema,
346+
virtual Result<std::shared_ptr<B>> Bind(const StructType& struct_,
347347
bool case_sensitive) const = 0;
348348

349349
/// \brief Overloaded Bind method that uses case-sensitive matching by default.
350-
Result<std::shared_ptr<B>> Bind(const Schema& schema) const;
350+
Result<std::shared_ptr<B>> Bind(const StructType& struct_) const;
351351

352352
/// \brief Returns the underlying named reference for this unbound term.
353353
virtual std::shared_ptr<class NamedReference> reference() = 0;

src/iceberg/expression/manifest_evaluator.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,9 @@ Result<std::unique_ptr<ManifestEvaluator>> ManifestEvaluator::MakePartitionFilte
363363
std::shared_ptr<Expression> expr, const std::shared_ptr<PartitionSpec>& spec,
364364
const Schema& schema, bool case_sensitive) {
365365
ICEBERG_ASSIGN_OR_RAISE(auto partition_type, spec->PartitionType(schema));
366-
auto field_span = partition_type->fields();
367-
std::vector<SchemaField> fields(field_span.begin(), field_span.end());
368-
auto partition_schema = std::make_shared<Schema>(fields);
369366
ICEBERG_ASSIGN_OR_RAISE(auto rewrite_expr, RewriteNot::Visit(std::move(expr)));
370367
ICEBERG_ASSIGN_OR_RAISE(auto partition_expr,
371-
Binder::Bind(*partition_schema, rewrite_expr, case_sensitive));
368+
Binder::Bind(*partition_type, rewrite_expr, case_sensitive));
372369
return std::unique_ptr<ManifestEvaluator>(
373370
new ManifestEvaluator(std::move(partition_expr)));
374371
}

src/iceberg/expression/predicate.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ Result<std::shared_ptr<Expression>> UnboundPredicateImpl<B>::Negate() const {
182182

183183
template <typename B>
184184
Result<std::shared_ptr<Expression>> UnboundPredicateImpl<B>::Bind(
185-
const Schema& schema, bool case_sensitive) const {
186-
ICEBERG_ASSIGN_OR_RAISE(auto bound_term, BASE::term()->Bind(schema, case_sensitive));
185+
const StructType& struct_, bool case_sensitive) const {
186+
ICEBERG_ASSIGN_OR_RAISE(auto bound_term, BASE::term()->Bind(struct_, case_sensitive));
187187

188188
if (values_.empty()) {
189189
return BindUnaryOperation(std::move(bound_term));

src/iceberg/expression/predicate.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "iceberg/expression/literal.h"
2929
#include "iceberg/expression/term.h"
3030
#include "iceberg/iceberg_export.h"
31+
#include "iceberg/type.h"
3132

3233
namespace iceberg {
3334

@@ -68,7 +69,7 @@ class ICEBERG_EXPORT UnboundPredicate : public virtual Expression,
6869
std::shared_ptr<NamedReference> reference() override = 0;
6970

7071
/// \brief Bind this UnboundPredicate.
71-
Result<std::shared_ptr<Expression>> Bind(const Schema& schema,
72+
Result<std::shared_ptr<Expression>> Bind(const StructType& struct_,
7273
bool case_sensitive) const override = 0;
7374

7475
/// \brief Negate this UnboundPredicate.
@@ -125,7 +126,7 @@ class ICEBERG_EXPORT UnboundPredicateImpl : public UnboundPredicate,
125126

126127
std::string ToString() const override;
127128

128-
Result<std::shared_ptr<Expression>> Bind(const Schema& schema,
129+
Result<std::shared_ptr<Expression>> Bind(const StructType& struct_,
129130
bool case_sensitive) const override;
130131

131132
Result<std::shared_ptr<Expression>> Negate() const override;

src/iceberg/expression/projections.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "iceberg/expression/rewrite_not.h"
2828
#include "iceberg/partition_spec.h"
2929
#include "iceberg/result.h"
30+
#include "iceberg/schema.h"
3031
#include "iceberg/transform.h"
3132
#include "iceberg/util/macros.h"
3233

src/iceberg/expression/residual_evaluator.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "iceberg/schema.h"
2828
#include "iceberg/schema_internal.h"
2929
#include "iceberg/transform.h"
30+
#include "iceberg/type.h"
3031
#include "iceberg/util/macros.h"
3132

3233
namespace iceberg {
@@ -42,8 +43,7 @@ class ResidualVisitor : public BoundVisitor<std::shared_ptr<Expression>> {
4243
const StructLike& partition_data,
4344
bool case_sensitive) {
4445
ICEBERG_ASSIGN_OR_RAISE(auto partition_type, spec.PartitionType(schema));
45-
auto partition_schema = FromStructType(std::move(*partition_type), std::nullopt);
46-
return ResidualVisitor(spec, schema, std::move(partition_schema), partition_data,
46+
return ResidualVisitor(spec, schema, std::move(partition_type), partition_data,
4747
case_sensitive);
4848
}
4949

@@ -202,17 +202,17 @@ class ResidualVisitor : public BoundVisitor<std::shared_ptr<Expression>> {
202202

203203
private:
204204
ResidualVisitor(const PartitionSpec& spec, const Schema& schema,
205-
std::unique_ptr<Schema> partition_schema,
205+
std::unique_ptr<StructType> partition_type,
206206
const StructLike& partition_data, bool case_sensitive)
207207
: spec_(spec),
208208
schema_(schema),
209-
partition_schema_(std::move(partition_schema)),
209+
partition_type_(std::move(partition_type)),
210210
partition_data_(partition_data),
211211
case_sensitive_(case_sensitive) {}
212212

213213
const PartitionSpec& spec_;
214214
const Schema& schema_;
215-
std::unique_ptr<Schema> partition_schema_;
215+
std::unique_ptr<StructType> partition_type_;
216216
const StructLike& partition_data_;
217217
bool case_sensitive_;
218218
};
@@ -243,9 +243,8 @@ Result<std::shared_ptr<Expression>> ResidualVisitor::Predicate(
243243
std::shared_ptr<Expression> strict_result = nullptr;
244244

245245
if (strict_projection != nullptr) {
246-
ICEBERG_ASSIGN_OR_RAISE(
247-
auto bound_strict,
248-
strict_projection->Bind(*partition_schema_, case_sensitive_));
246+
ICEBERG_ASSIGN_OR_RAISE(auto bound_strict,
247+
strict_projection->Bind(*partition_type_, case_sensitive_));
249248
if (bound_strict->is_bound_predicate()) {
250249
ICEBERG_ASSIGN_OR_RAISE(
251250
strict_result, BoundVisitor::Predicate(
@@ -270,7 +269,7 @@ Result<std::shared_ptr<Expression>> ResidualVisitor::Predicate(
270269
if (inclusive_projection != nullptr) {
271270
ICEBERG_ASSIGN_OR_RAISE(
272271
auto bound_inclusive,
273-
inclusive_projection->Bind(*partition_schema_, case_sensitive_));
272+
inclusive_projection->Bind(*partition_type_, case_sensitive_));
274273

275274
if (bound_inclusive->is_bound_predicate()) {
276275
ICEBERG_ASSIGN_OR_RAISE(

0 commit comments

Comments
 (0)