Skip to content

Commit 9f21cb4

Browse files
committed
fix: Use Result/Status as the return value type
1 parent 5a46de2 commit 9f21cb4

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

src/iceberg/transform.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Transform::Transform(TransformType transform_type, int32_t param)
107107

108108
TransformType Transform::transform_type() const { return transform_type_; }
109109

110-
expected<std::unique_ptr<TransformFunction>, Error> Transform::Bind(
110+
Result<std::unique_ptr<TransformFunction>> Transform::Bind(
111111
const std::shared_ptr<Type>& source_type) const {
112112
auto type_str = TransformTypeToString(transform_type_);
113113

src/iceberg/transform.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class ICEBERG_EXPORT Transform : public util::Formattable {
125125
/// parameter.
126126
/// \param source_type The source column type to bind to.
127127
/// \return A TransformFunction instance wrapped in `expected`, or an error on failure.
128-
expected<std::unique_ptr<TransformFunction>, Error> Bind(
128+
Result<std::unique_ptr<TransformFunction>> Bind(
129129
const std::shared_ptr<Type>& source_type) const;
130130

131131
/// \brief Returns a string representation of this transform (e.g., "bucket[16]").
@@ -177,13 +177,13 @@ class ICEBERG_EXPORT TransformFunction {
177177
virtual ~TransformFunction() = default;
178178
TransformFunction(TransformType transform_type, std::shared_ptr<Type> source_type);
179179
/// \brief Transform an input array to a new array
180-
virtual expected<ArrowArray, Error> Transform(const ArrowArray& data) = 0;
180+
virtual Result<ArrowArray> Transform(const ArrowArray& data) = 0;
181181
/// \brief Get the transform type
182182
TransformType transform_type() const;
183183
/// \brief Get the source type of transform function
184184
const std::shared_ptr<Type>& source_type() const;
185185
/// \brief Get the result type of transform function
186-
virtual expected<std::shared_ptr<Type>, Error> ResultType() const = 0;
186+
virtual Result<std::shared_ptr<Type>> ResultType() const = 0;
187187

188188
friend bool operator==(const TransformFunction& lhs, const TransformFunction& rhs) {
189189
return lhs.Equals(rhs);

src/iceberg/transform_function.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ namespace iceberg {
2828
IdentityTransform::IdentityTransform(std::shared_ptr<Type> const& source_type)
2929
: TransformFunction(TransformType::kIdentity, source_type) {}
3030

31-
expected<ArrowArray, Error> IdentityTransform::Transform(const ArrowArray& input) {
31+
Result<ArrowArray> IdentityTransform::Transform(const ArrowArray& input) {
3232
return unexpected<Error>(
3333
{.kind = ErrorKind::kNotImplemented, .message = "IdentityTransform::Transform"});
3434
}
3535

36-
expected<std::shared_ptr<Type>, Error> IdentityTransform::ResultType() const {
36+
Result<std::shared_ptr<Type>> IdentityTransform::ResultType() const {
3737
auto src_type = source_type();
3838
if (!src_type || !src_type->is_primitive()) {
3939
return unexpected(Error{
@@ -48,12 +48,12 @@ BucketTransform::BucketTransform(std::shared_ptr<Type> const& source_type,
4848
int32_t num_buckets)
4949
: TransformFunction(TransformType::kBucket, source_type), num_buckets_(num_buckets) {}
5050

51-
expected<ArrowArray, Error> BucketTransform::Transform(const ArrowArray& input) {
51+
Result<ArrowArray> BucketTransform::Transform(const ArrowArray& input) {
5252
return unexpected<Error>(
5353
{.kind = ErrorKind::kNotImplemented, .message = "BucketTransform::Transform"});
5454
}
5555

56-
expected<std::shared_ptr<Type>, Error> BucketTransform::ResultType() const {
56+
Result<std::shared_ptr<Type>> BucketTransform::ResultType() const {
5757
return unexpected<Error>(
5858
{.kind = ErrorKind::kNotImplemented, .message = "BucketTransform::result_type"});
5959
}
@@ -62,77 +62,77 @@ TruncateTransform::TruncateTransform(std::shared_ptr<Type> const& source_type,
6262
int32_t width)
6363
: TransformFunction(TransformType::kTruncate, source_type), width_(width) {}
6464

65-
expected<ArrowArray, Error> TruncateTransform::Transform(const ArrowArray& input) {
65+
Result<ArrowArray> TruncateTransform::Transform(const ArrowArray& input) {
6666
return unexpected<Error>(
6767
{.kind = ErrorKind::kNotImplemented, .message = "TruncateTransform::Transform"});
6868
}
6969

70-
expected<std::shared_ptr<Type>, Error> TruncateTransform::ResultType() const {
70+
Result<std::shared_ptr<Type>> TruncateTransform::ResultType() const {
7171
return unexpected<Error>(
7272
{.kind = ErrorKind::kNotImplemented, .message = "TruncateTransform::result_type"});
7373
}
7474

7575
YearTransform::YearTransform(std::shared_ptr<Type> const& source_type)
7676
: TransformFunction(TransformType::kTruncate, source_type) {}
7777

78-
expected<ArrowArray, Error> YearTransform::Transform(const ArrowArray& input) {
78+
Result<ArrowArray> YearTransform::Transform(const ArrowArray& input) {
7979
return unexpected<Error>(
8080
{.kind = ErrorKind::kNotImplemented, .message = "YearTransform::Transform"});
8181
}
8282

83-
expected<std::shared_ptr<Type>, Error> YearTransform::ResultType() const {
83+
Result<std::shared_ptr<Type>> YearTransform::ResultType() const {
8484
return unexpected<Error>(
8585
{.kind = ErrorKind::kNotImplemented, .message = "YearTransform::result_type"});
8686
}
8787

8888
MonthTransform::MonthTransform(std::shared_ptr<Type> const& source_type)
8989
: TransformFunction(TransformType::kMonth, source_type) {}
9090

91-
expected<ArrowArray, Error> MonthTransform::Transform(const ArrowArray& input) {
91+
Result<ArrowArray> MonthTransform::Transform(const ArrowArray& input) {
9292
return unexpected<Error>(
9393
{.kind = ErrorKind::kNotImplemented, .message = "MonthTransform::Transform"});
9494
}
9595

96-
expected<std::shared_ptr<Type>, Error> MonthTransform::ResultType() const {
96+
Result<std::shared_ptr<Type>> MonthTransform::ResultType() const {
9797
return unexpected<Error>(
9898
{.kind = ErrorKind::kNotImplemented, .message = "MonthTransform::result_type"});
9999
}
100100

101101
DayTransform::DayTransform(std::shared_ptr<Type> const& source_type)
102102
: TransformFunction(TransformType::kDay, source_type) {}
103103

104-
expected<ArrowArray, Error> DayTransform::Transform(const ArrowArray& input) {
104+
Result<ArrowArray> DayTransform::Transform(const ArrowArray& input) {
105105
return unexpected<Error>(
106106
{.kind = ErrorKind::kNotImplemented, .message = "DayTransform::Transform"});
107107
}
108108

109-
expected<std::shared_ptr<Type>, Error> DayTransform::ResultType() const {
109+
Result<std::shared_ptr<Type>> DayTransform::ResultType() const {
110110
return unexpected<Error>(
111111
{.kind = ErrorKind::kNotImplemented, .message = "DayTransform::result_type"});
112112
}
113113

114114
HourTransform::HourTransform(std::shared_ptr<Type> const& source_type)
115115
: TransformFunction(TransformType::kHour, source_type) {}
116116

117-
expected<ArrowArray, Error> HourTransform::Transform(const ArrowArray& input) {
117+
Result<ArrowArray> HourTransform::Transform(const ArrowArray& input) {
118118
return unexpected<Error>(
119119
{.kind = ErrorKind::kNotImplemented, .message = "HourTransform::Transform"});
120120
}
121121

122-
expected<std::shared_ptr<Type>, Error> HourTransform::ResultType() const {
122+
Result<std::shared_ptr<Type>> HourTransform::ResultType() const {
123123
return unexpected<Error>(
124124
{.kind = ErrorKind::kNotImplemented, .message = "HourTransform::result_type"});
125125
}
126126

127127
VoidTransform::VoidTransform(std::shared_ptr<Type> const& source_type)
128128
: TransformFunction(TransformType::kVoid, source_type) {}
129129

130-
expected<ArrowArray, Error> VoidTransform::Transform(const ArrowArray& input) {
130+
Result<ArrowArray> VoidTransform::Transform(const ArrowArray& input) {
131131
return unexpected<Error>(
132132
{.kind = ErrorKind::kNotImplemented, .message = "VoidTransform::Transform"});
133133
}
134134

135-
expected<std::shared_ptr<Type>, Error> VoidTransform::ResultType() const {
135+
Result<std::shared_ptr<Type>> VoidTransform::ResultType() const {
136136
return unexpected<Error>(
137137
{.kind = ErrorKind::kNotImplemented, .message = "VoidTransform::result_type"});
138138
}

src/iceberg/transform_function.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ class IdentityTransform : public TransformFunction {
3131
explicit IdentityTransform(std::shared_ptr<Type> const& source_type);
3232

3333
/// \brief Returns the input array without modification.
34-
expected<ArrowArray, Error> Transform(const ArrowArray& input) override;
34+
Result<ArrowArray> Transform(const ArrowArray& input) override;
3535

3636
/// \brief Returns the same type as the source type if it is valid.
37-
expected<std::shared_ptr<Type>, Error> ResultType() const override;
37+
Result<std::shared_ptr<Type>> ResultType() const override;
3838
};
3939

4040
/// \brief Bucket transform that hashes input values into N buckets.
@@ -45,10 +45,10 @@ class BucketTransform : public TransformFunction {
4545
BucketTransform(std::shared_ptr<Type> const& source_type, int32_t num_buckets);
4646

4747
/// \brief Applies the bucket hash function to the input array.
48-
expected<ArrowArray, Error> Transform(const ArrowArray& input) override;
48+
Result<ArrowArray> Transform(const ArrowArray& input) override;
4949

5050
/// \brief Returns INT32 as the output type.
51-
expected<std::shared_ptr<Type>, Error> ResultType() const override;
51+
Result<std::shared_ptr<Type>> ResultType() const override;
5252

5353
private:
5454
int32_t num_buckets_;
@@ -62,10 +62,10 @@ class TruncateTransform : public TransformFunction {
6262
TruncateTransform(std::shared_ptr<Type> const& source_type, int32_t width);
6363

6464
/// \brief Truncates values in the input array to the specified width.
65-
expected<ArrowArray, Error> Transform(const ArrowArray& input) override;
65+
Result<ArrowArray> Transform(const ArrowArray& input) override;
6666

6767
/// \brief Returns the same type as source_type.
68-
expected<std::shared_ptr<Type>, Error> ResultType() const override;
68+
Result<std::shared_ptr<Type>> ResultType() const override;
6969

7070
private:
7171
int32_t width_;
@@ -78,10 +78,10 @@ class YearTransform : public TransformFunction {
7878
explicit YearTransform(std::shared_ptr<Type> const& source_type);
7979

8080
/// \brief Extracts the year from each timestamp in the input array.
81-
expected<ArrowArray, Error> Transform(const ArrowArray& input) override;
81+
Result<ArrowArray> Transform(const ArrowArray& input) override;
8282

8383
/// \brief Returns INT32 as the output type.
84-
expected<std::shared_ptr<Type>, Error> ResultType() const override;
84+
Result<std::shared_ptr<Type>> ResultType() const override;
8585
};
8686

8787
/// \brief Month transform that extracts the month component from timestamp inputs.
@@ -91,10 +91,10 @@ class MonthTransform : public TransformFunction {
9191
explicit MonthTransform(std::shared_ptr<Type> const& source_type);
9292

9393
/// \brief Extracts the month (1-12) from each timestamp in the input array.
94-
expected<ArrowArray, Error> Transform(const ArrowArray& input) override;
94+
Result<ArrowArray> Transform(const ArrowArray& input) override;
9595

9696
/// \brief Returns INT32 as the output type.
97-
expected<std::shared_ptr<Type>, Error> ResultType() const override;
97+
Result<std::shared_ptr<Type>> ResultType() const override;
9898
};
9999

100100
/// \brief Day transform that extracts the day of the month from timestamp inputs.
@@ -104,10 +104,10 @@ class DayTransform : public TransformFunction {
104104
explicit DayTransform(std::shared_ptr<Type> const& source_type);
105105

106106
/// \brief Extracts the day (1-31) from each timestamp in the input array.
107-
expected<ArrowArray, Error> Transform(const ArrowArray& input) override;
107+
Result<ArrowArray> Transform(const ArrowArray& input) override;
108108

109109
/// \brief Returns INT32 as the output type.
110-
expected<std::shared_ptr<Type>, Error> ResultType() const override;
110+
Result<std::shared_ptr<Type>> ResultType() const override;
111111
};
112112

113113
/// \brief Hour transform that extracts the hour component from timestamp inputs.
@@ -117,10 +117,10 @@ class HourTransform : public TransformFunction {
117117
explicit HourTransform(std::shared_ptr<Type> const& source_type);
118118

119119
/// \brief Extracts the hour (0-23) from each timestamp in the input array.
120-
expected<ArrowArray, Error> Transform(const ArrowArray& input) override;
120+
Result<ArrowArray> Transform(const ArrowArray& input) override;
121121

122122
/// \brief Returns INT32 as the output type.
123-
expected<std::shared_ptr<Type>, Error> ResultType() const override;
123+
Result<std::shared_ptr<Type>> ResultType() const override;
124124
};
125125

126126
/// \brief Void transform that discards the input and always returns null.
@@ -130,10 +130,10 @@ class VoidTransform : public TransformFunction {
130130
explicit VoidTransform(std::shared_ptr<Type> const& source_type);
131131

132132
/// \brief Returns an all-null array of the same length as the input.
133-
expected<ArrowArray, Error> Transform(const ArrowArray& input) override;
133+
Result<ArrowArray> Transform(const ArrowArray& input) override;
134134

135135
/// \brief Returns null type or a sentinel type indicating void.
136-
expected<std::shared_ptr<Type>, Error> ResultType() const override;
136+
Result<std::shared_ptr<Type>> ResultType() const override;
137137
};
138138

139139
} // namespace iceberg

0 commit comments

Comments
 (0)