Skip to content

Commit a22dc7f

Browse files
committed
fix conflict
1 parent 919b10a commit a22dc7f

File tree

9 files changed

+59
-70
lines changed

9 files changed

+59
-70
lines changed

src/iceberg/expression/expression.cc

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ Result<std::unique_ptr<And>> And::Make(std::shared_ptr<Expression> left,
5555

5656
And::And(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right)
5757
: left_(std::move(left)), right_(std::move(right)) {
58-
ICEBERG_DCHECK(left_ != nullptr, "And left operand cannot be null");
59-
ICEBERG_DCHECK(right_ != nullptr, "And right operand cannot be null");
58+
ICEBERG_DCHECK(left_ && right_, "And cannot have null children");
6059
}
6160

6261
std::string And::ToString() const {
@@ -82,19 +81,15 @@ bool And::Equals(const Expression& expr) const {
8281
// Or implementation
8382
Result<std::unique_ptr<Or>> Or::Make(std::shared_ptr<Expression> left,
8483
std::shared_ptr<Expression> right) {
85-
if (!left) {
86-
return InvalidArgument("Or expression left operand cannot be null");
87-
}
88-
if (!right) {
89-
return InvalidArgument("Or expression right operand cannot be null");
84+
if (!left || !right) [[unlikely]] {
85+
return InvalidExpression("Or cannot have null children");
9086
}
9187
return std::unique_ptr<Or>(new Or(std::move(left), std::move(right)));
9288
}
9389

9490
Or::Or(std::shared_ptr<Expression> left, std::shared_ptr<Expression> right)
9591
: left_(std::move(left)), right_(std::move(right)) {
96-
ICEBERG_DCHECK(left_ != nullptr, "Or left operand cannot be null");
97-
ICEBERG_DCHECK(right_ != nullptr, "Or right operand cannot be null");
92+
ICEBERG_DCHECK(left_ && right_, "Or cannot have null children");
9893
}
9994

10095
std::string Or::ToString() const {
@@ -119,14 +114,14 @@ bool Or::Equals(const Expression& expr) const {
119114

120115
// Not implementation
121116
Result<std::unique_ptr<Not>> Not::Make(std::shared_ptr<Expression> child) {
122-
if (!child) {
117+
if (!child) [[unlikely]] {
123118
return InvalidExpression("Not expression cannot have null child");
124119
}
125120
return std::unique_ptr<Not>(new Not(std::move(child)));
126121
}
127122

128123
Not::Not(std::shared_ptr<Expression> child) : child_(std::move(child)) {
129-
ICEBERG_DCHECK(child_ != nullptr, "Not child expression cannot be null");
124+
ICEBERG_DCHECK(child_ != nullptr, "Not expression cannot have null child");
130125
}
131126

132127
std::string Not::ToString() const { return std::format("not({})", child_->ToString()); }
@@ -233,7 +228,7 @@ Result<Expression::Operation> Negate(Expression::Operation op) {
233228
case Expression::Operation::kMax:
234229
case Expression::Operation::kMin:
235230
case Expression::Operation::kCount:
236-
return InvalidArgument("No negation for operation: {}", op);
231+
return InvalidExpression("No negation for operation: {}", op);
237232
}
238233
std::unreachable();
239234
}

src/iceberg/expression/expression.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ class ICEBERG_EXPORT And : public Expression {
134134
///
135135
/// \param left The left operand of the AND expression
136136
/// \param right The right operand of the AND expression
137-
/// \return A Result containing a unique pointer to And, or an error if either parameter
138-
/// is nullptr
139137
static Result<std::unique_ptr<And>> Make(std::shared_ptr<Expression> left,
140138
std::shared_ptr<Expression> right);
141139

@@ -174,8 +172,6 @@ class ICEBERG_EXPORT Or : public Expression {
174172
///
175173
/// \param left The left operand of the OR expression
176174
/// \param right The right operand of the OR expression
177-
/// \return A Result containing a unique pointer to Or, or an error if either parameter
178-
/// is nullptr
179175
static Result<std::unique_ptr<Or>> Make(std::shared_ptr<Expression> left,
180176
std::shared_ptr<Expression> right);
181177

src/iceberg/expression/expressions.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ std::shared_ptr<Expression> Expressions::Not(std::shared_ptr<Expression> child)
4242
return not_expr.child();
4343
}
4444

45-
auto result = ::iceberg::Not::Make(std::move(child));
46-
ICEBERG_ASSIGN_OR_THROW(auto not_expr, std::move(result));
47-
return {std::move(not_expr)};
45+
ICEBERG_ASSIGN_OR_THROW(auto not_expr, iceberg::Not::Make(std::move(child)));
46+
return not_expr;
4847
}
4948

5049
// Transform functions
@@ -54,46 +53,46 @@ std::shared_ptr<UnboundTransform> Expressions::Bucket(std::string name,
5453
ICEBERG_ASSIGN_OR_THROW(
5554
auto transform,
5655
UnboundTransform::Make(Ref(std::move(name)), Transform::Bucket(num_buckets)));
57-
return {std::move(transform)};
56+
return transform;
5857
}
5958

6059
std::shared_ptr<UnboundTransform> Expressions::Year(std::string name) {
6160
ICEBERG_ASSIGN_OR_THROW(
6261
auto transform, UnboundTransform::Make(Ref(std::move(name)), Transform::Year()));
63-
return {std::move(transform)};
62+
return transform;
6463
}
6564

6665
std::shared_ptr<UnboundTransform> Expressions::Month(std::string name) {
6766
ICEBERG_ASSIGN_OR_THROW(
6867
auto transform, UnboundTransform::Make(Ref(std::move(name)), Transform::Month()));
69-
return {std::move(transform)};
68+
return transform;
7069
}
7170

7271
std::shared_ptr<UnboundTransform> Expressions::Day(std::string name) {
7372
ICEBERG_ASSIGN_OR_THROW(auto transform,
7473
UnboundTransform::Make(Ref(std::move(name)), Transform::Day()));
75-
return {std::move(transform)};
74+
return transform;
7675
}
7776

7877
std::shared_ptr<UnboundTransform> Expressions::Hour(std::string name) {
7978
ICEBERG_ASSIGN_OR_THROW(
8079
auto transform, UnboundTransform::Make(Ref(std::move(name)), Transform::Hour()));
81-
return {std::move(transform)};
80+
return transform;
8281
}
8382

8483
std::shared_ptr<UnboundTransform> Expressions::Truncate(std::string name, int32_t width) {
8584
ICEBERG_ASSIGN_OR_THROW(
8685
auto transform,
8786
UnboundTransform::Make(Ref(std::move(name)), Transform::Truncate(width)));
88-
return {std::move(transform)};
87+
return transform;
8988
}
9089

9190
std::shared_ptr<UnboundTransform> Expressions::Transform(
9291
std::string name, std::shared_ptr<::iceberg::Transform> transform) {
9392
ICEBERG_ASSIGN_OR_THROW(
9493
auto unbound_transform,
9594
UnboundTransform::Make(Ref(std::move(name)), std::move(transform)));
96-
return {std::move(unbound_transform)};
95+
return unbound_transform;
9796
}
9897

9998
// Template implementations for unary predicates
@@ -346,7 +345,7 @@ std::shared_ptr<False> Expressions::AlwaysFalse() { return False::Instance(); }
346345

347346
std::shared_ptr<NamedReference> Expressions::Ref(std::string name) {
348347
ICEBERG_ASSIGN_OR_THROW(auto ref, NamedReference::Make(std::move(name)));
349-
return {std::move(ref)};
348+
return ref;
350349
}
351350

352351
Literal Expressions::Lit(Literal::Value value, std::shared_ptr<PrimitiveType> type) {

src/iceberg/expression/expressions.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ class ICEBERG_EXPORT Expressions {
6464
return left;
6565
}
6666

67-
auto result = ::iceberg::And::Make(std::move(left), std::move(right));
68-
ICEBERG_ASSIGN_OR_THROW(auto and_expr, std::move(result));
69-
return {std::move(and_expr)};
67+
ICEBERG_ASSIGN_OR_THROW(auto and_expr,
68+
iceberg::And::Make(std::move(left), std::move(right)));
69+
return and_expr;
7070
} else {
7171
return And(And(std::move(left), std::move(right)), std::forward<Args>(args)...);
7272
}
@@ -92,9 +92,9 @@ class ICEBERG_EXPORT Expressions {
9292
return left;
9393
}
9494

95-
auto result = ::iceberg::Or::Make(std::move(left), std::move(right));
96-
ICEBERG_ASSIGN_OR_THROW(auto or_expr, std::move(result));
97-
return {std::move(or_expr)};
95+
ICEBERG_ASSIGN_OR_THROW(auto or_expr,
96+
iceberg::Or::Make(std::move(left), std::move(right)));
97+
return or_expr;
9898
} else {
9999
return Or(Or(std::move(left), std::move(right)), std::forward<Args>(args)...);
100100
}

src/iceberg/expression/term.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ Result<std::shared_ptr<B>> Unbound<B>::Bind(const Schema& schema) const {
4444
// NamedReference implementation
4545
Result<std::unique_ptr<NamedReference>> NamedReference::Make(std::string field_name) {
4646
if (field_name.empty()) [[unlikely]] {
47-
return InvalidExpression("NamedReference field name cannot be empty");
47+
return InvalidExpression("NamedReference cannot have empty field name");
4848
}
4949
return std::unique_ptr<NamedReference>(new NamedReference(std::move(field_name)));
5050
}
5151

5252
NamedReference::NamedReference(std::string field_name)
5353
: field_name_(std::move(field_name)) {
54-
ICEBERG_DCHECK(!field_name_.empty(), "NamedReference field name cannot be empty");
54+
ICEBERG_DCHECK(!field_name_.empty(), "NamedReference cannot have empty field name");
5555
}
5656

5757
NamedReference::~NamedReference() = default;
@@ -73,14 +73,16 @@ std::string NamedReference::ToString() const {
7373

7474
// BoundReference implementation
7575
Result<std::unique_ptr<BoundReference>> BoundReference::Make(SchemaField field) {
76-
if (!field.type()) [[unlikely]] {
77-
return InvalidExpression("BoundReference field type cannot be null");
76+
if (auto status = field.Validate(); !status.has_value()) [[unlikely]] {
77+
return InvalidExpression("Cannot create BoundReference with invalid field: {}",
78+
status.error().message);
7879
}
7980
return std::unique_ptr<BoundReference>(new BoundReference(std::move(field)));
8081
}
8182

8283
BoundReference::BoundReference(SchemaField field) : field_(std::move(field)) {
83-
ICEBERG_DCHECK(field_.type() != nullptr, "BoundReference field type cannot be null");
84+
ICEBERG_DCHECK(field_.Validate().has_value(),
85+
"Cannot create BoundReference with invalid field");
8486
}
8587

8688
BoundReference::~BoundReference() = default;
@@ -108,7 +110,8 @@ bool BoundReference::Equals(const BoundTerm& other) const {
108110
Result<std::unique_ptr<UnboundTransform>> UnboundTransform::Make(
109111
std::shared_ptr<NamedReference> ref, std::shared_ptr<Transform> transform) {
110112
if (!ref || !transform) [[unlikely]] {
111-
return InvalidExpression("UnboundTransform cannot have null children");
113+
return InvalidExpression(
114+
"Cannot create UnboundTransform with null reference or transform");
112115
}
113116
return std::unique_ptr<UnboundTransform>(
114117
new UnboundTransform(std::move(ref), std::move(transform)));
@@ -117,8 +120,8 @@ Result<std::unique_ptr<UnboundTransform>> UnboundTransform::Make(
117120
UnboundTransform::UnboundTransform(std::shared_ptr<NamedReference> ref,
118121
std::shared_ptr<Transform> transform)
119122
: ref_(std::move(ref)), transform_(std::move(transform)) {
120-
ICEBERG_DCHECK(ref_ != nullptr, "UnboundTransform reference cannot be null");
121-
ICEBERG_DCHECK(transform_ != nullptr, "UnboundTransform transform cannot be null");
123+
ICEBERG_DCHECK(!ref || !transform,
124+
"Cannot create UnboundTransform with null reference or transform");
122125
}
123126

124127
UnboundTransform::~UnboundTransform() = default;
@@ -140,7 +143,8 @@ Result<std::unique_ptr<BoundTransform>> BoundTransform::Make(
140143
std::shared_ptr<BoundReference> ref, std::shared_ptr<Transform> transform,
141144
std::shared_ptr<TransformFunction> transform_func) {
142145
if (!ref || !transform || !transform_func) [[unlikely]] {
143-
return InvalidExpression("BoundTransform cannot have null children");
146+
return InvalidExpression(
147+
"Cannot create BoundTransform with null reference or transform");
144148
}
145149
return std::unique_ptr<BoundTransform>(new BoundTransform(
146150
std::move(ref), std::move(transform), std::move(transform_func)));
@@ -152,10 +156,8 @@ BoundTransform::BoundTransform(std::shared_ptr<BoundReference> ref,
152156
: ref_(std::move(ref)),
153157
transform_(std::move(transform)),
154158
transform_func_(std::move(transform_func)) {
155-
ICEBERG_DCHECK(ref_ != nullptr, "BoundTransform reference cannot be null");
156-
ICEBERG_DCHECK(transform_ != nullptr, "BoundTransform transform cannot be null");
157-
ICEBERG_DCHECK(transform_func_ != nullptr,
158-
"BoundTransform transform function cannot be null");
159+
ICEBERG_DCHECK(ref_ && transform_ && transform_func_,
160+
"Cannot create BoundTransform with null reference or transform");
159161
}
160162

161163
BoundTransform::~BoundTransform() = default;

src/iceberg/expression/term.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232

3333
namespace iceberg {
3434

35-
// TODO(gangwu): add a struct-like interface to wrap a row of data from ArrowArray or
36-
// structs like ManifestFile and ManifestEntry to facilitate generailization of the
37-
// evaluation of expressions on top of different data structures.
38-
class StructLike;
39-
4035
/// \brief A term is an expression node that produces a typed value when evaluated.
4136
class ICEBERG_EXPORT Term : public util::Formattable {
4237
public:
@@ -138,8 +133,6 @@ class ICEBERG_EXPORT NamedReference
138133
/// \brief Create a named reference to a field.
139134
///
140135
/// \param field_name The name of the field to reference
141-
/// \return A Result containing a unique pointer to NamedReference, or an error if
142-
/// field_name is empty
143136
static Result<std::unique_ptr<NamedReference>> Make(std::string field_name);
144137

145138
~NamedReference() override;
@@ -170,7 +163,6 @@ class ICEBERG_EXPORT BoundReference
170163
/// \brief Create a bound reference.
171164
///
172165
/// \param field The schema field
173-
/// \return A unique pointer to BoundReference (field cannot be null in practice)
174166
static Result<std::unique_ptr<BoundReference>> Make(SchemaField field);
175167

176168
~BoundReference() override;
@@ -206,8 +198,6 @@ class ICEBERG_EXPORT UnboundTransform : public UnboundTerm<class BoundTransform>
206198
///
207199
/// \param ref The term to apply the transformation to
208200
/// \param transform The transformation function to apply
209-
/// \return A Result containing a unique pointer to UnboundTransform, or an error if
210-
/// parameters are null
211201
static Result<std::unique_ptr<UnboundTransform>> Make(
212202
std::shared_ptr<NamedReference> ref, std::shared_ptr<Transform> transform);
213203

@@ -240,8 +230,6 @@ class ICEBERG_EXPORT BoundTransform : public BoundTerm {
240230
/// \param ref The bound term to apply the transformation to
241231
/// \param transform The transform to apply
242232
/// \param transform_func The bound transform function to apply
243-
/// \return A Result containing a unique pointer to BoundTransform, or an error if
244-
/// parameters are null
245233
static Result<std::unique_ptr<BoundTransform>> Make(
246234
std::shared_ptr<BoundReference> ref, std::shared_ptr<Transform> transform,
247235
std::shared_ptr<TransformFunction> transform_func);

src/iceberg/schema_field.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ bool SchemaField::optional() const { return optional_; }
5454

5555
std::string_view SchemaField::doc() const { return doc_; }
5656

57+
Status SchemaField::Validate() const {
58+
if (name_.empty()) [[unlikely]] {
59+
return InvalidSchema("SchemaField cannot have empty name");
60+
}
61+
if (type_ == nullptr) [[unlikely]] {
62+
return InvalidSchema("SchemaField cannot have null type");
63+
}
64+
return {};
65+
}
66+
5767
std::string SchemaField::ToString() const {
5868
std::string result = std::format("{} ({}): {} ({}){}", name_, field_id_, *type_,
5969
optional_ ? "optional" : "required",

src/iceberg/schema_field.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <string_view>
3030

3131
#include "iceberg/iceberg_export.h"
32+
#include "iceberg/result.h"
3233
#include "iceberg/type_fwd.h"
3334
#include "iceberg/util/formattable.h"
3435

@@ -72,6 +73,8 @@ class ICEBERG_EXPORT SchemaField : public iceberg::util::Formattable {
7273

7374
[[nodiscard]] std::string ToString() const override;
7475

76+
Status Validate() const;
77+
7578
friend bool operator==(const SchemaField& lhs, const SchemaField& rhs) {
7679
return lhs.Equals(rhs);
7780
}

src/iceberg/util/macros.h

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,18 @@
4242
ICEBERG_ASSIGN_OR_RAISE_IMPL(ICEBERG_ASSIGN_OR_RAISE_NAME(result_, __COUNTER__), lhs, \
4343
rexpr)
4444

45-
#define ICEBERG_ASSIGN_OR_THROW_IMPL(result_name, lhs, rexpr) \
46-
auto&& result_name = (rexpr); \
47-
if (!result_name) [[unlikely]] { \
48-
throw iceberg::ExpressionError(result_name.error().message); \
49-
} \
50-
lhs = std::move(result_name.value());
51-
52-
#define ICEBERG_ASSIGN_OR_THROW(lhs, rexpr) \
53-
ICEBERG_ASSIGN_OR_THROW_IMPL(ICEBERG_ASSIGN_OR_RAISE_NAME(result_, __COUNTER__), lhs, \
54-
rexpr)
55-
5645
#define ICEBERG_DCHECK(expr, message) assert((expr) && (message))
5746

47+
#define ERROR_TO_EXCEPTION(error) \
48+
if (error.kind == iceberg::ErrorKind::kInvalidExpression) { \
49+
throw iceberg::ExpressionError(error.message); \
50+
} else { \
51+
throw iceberg::IcebergError(error.message); \
52+
}
53+
5854
#define ICEBERG_THROW_NOT_OK(result) \
5955
if (auto&& result_name = result; !result_name) [[unlikely]] { \
60-
throw iceberg::IcebergError(result_name.error().message); \
56+
ERROR_TO_EXCEPTION(result_name.error()); \
6157
}
6258

6359
#define ICEBERG_ASSIGN_OR_THROW_IMPL(result_name, lhs, rexpr) \

0 commit comments

Comments
 (0)