@@ -31,12 +31,16 @@ Result<ArrowArray> IdentityTransform::Transform(const ArrowArray& input) {
3131}
3232
3333Result<std::shared_ptr<Type>> IdentityTransform::ResultType () const {
34- auto src_type = source_type ();
35- if (!src_type || !src_type->is_primitive ()) {
34+ return source_type ();
35+ }
36+
37+ Result<std::unique_ptr<TransformFunction>> IdentityTransform::Make (
38+ std::shared_ptr<Type> const & source_type) {
39+ if (!source_type || !source_type->is_primitive ()) {
3640 return NotSupported (" {} is not a valid input type for identity transform" ,
37- src_type ? src_type ->ToString () : " null" );
41+ source_type ? source_type ->ToString () : " null" );
3842 }
39- return src_type ;
43+ return std::make_unique<IdentityTransform>(source_type) ;
4044}
4145
4246BucketTransform::BucketTransform (std::shared_ptr<Type> const & source_type,
@@ -49,9 +53,6 @@ Result<ArrowArray> BucketTransform::Transform(const ArrowArray& input) {
4953
5054Result<std::shared_ptr<Type>> BucketTransform::ResultType () const {
5155 auto src_type = source_type ();
52- if (!src_type) {
53- return NotSupported (" null is not a valid input type for bucket transform" );
54- }
5556 switch (src_type->type_id ()) {
5657 case TypeId::kInt :
5758 case TypeId::kLong :
@@ -71,6 +72,14 @@ Result<std::shared_ptr<Type>> BucketTransform::ResultType() const {
7172 }
7273}
7374
75+ Result<std::unique_ptr<TransformFunction>> BucketTransform::Make (
76+ std::shared_ptr<Type> const & source_type, int32_t num_buckets) {
77+ if (!source_type) {
78+ return NotSupported (" null is not a valid input type for bucket transform" );
79+ }
80+ return std::make_unique<BucketTransform>(source_type, num_buckets);
81+ }
82+
7483TruncateTransform::TruncateTransform (std::shared_ptr<Type> const & source_type,
7584 int32_t width)
7685 : TransformFunction(TransformType::kTruncate , source_type), width_(width) {}
@@ -81,9 +90,6 @@ Result<ArrowArray> TruncateTransform::Transform(const ArrowArray& input) {
8190
8291Result<std::shared_ptr<Type>> TruncateTransform::ResultType () const {
8392 auto src_type = source_type ();
84- if (!src_type) {
85- return NotSupported (" null is not a valid input type for truncate transform" );
86- }
8793 switch (src_type->type_id ()) {
8894 case TypeId::kInt :
8995 case TypeId::kLong :
@@ -97,6 +103,14 @@ Result<std::shared_ptr<Type>> TruncateTransform::ResultType() const {
97103 }
98104}
99105
106+ Result<std::unique_ptr<TransformFunction>> TruncateTransform::Make (
107+ std::shared_ptr<Type> const & source_type, int32_t width) {
108+ if (!source_type) {
109+ return NotSupported (" null is not a valid input type for truncate transform" );
110+ }
111+ return std::make_unique<TruncateTransform>(source_type, width);
112+ }
113+
100114YearTransform::YearTransform (std::shared_ptr<Type> const & source_type)
101115 : TransformFunction(TransformType::kTruncate , source_type) {}
102116
@@ -106,9 +120,6 @@ Result<ArrowArray> YearTransform::Transform(const ArrowArray& input) {
106120
107121Result<std::shared_ptr<Type>> YearTransform::ResultType () const {
108122 auto src_type = source_type ();
109- if (!src_type) {
110- return NotSupported (" null is not a valid input type for year transform" );
111- }
112123 switch (src_type->type_id ()) {
113124 case TypeId::kDate :
114125 case TypeId::kTimestamp :
@@ -120,6 +131,14 @@ Result<std::shared_ptr<Type>> YearTransform::ResultType() const {
120131 }
121132}
122133
134+ Result<std::unique_ptr<TransformFunction>> YearTransform::Make (
135+ std::shared_ptr<Type> const & source_type) {
136+ if (!source_type) {
137+ return NotSupported (" null is not a valid input type for year transform" );
138+ }
139+ return std::make_unique<YearTransform>(source_type);
140+ }
141+
123142MonthTransform::MonthTransform (std::shared_ptr<Type> const & source_type)
124143 : TransformFunction(TransformType::kMonth , source_type) {}
125144
@@ -129,9 +148,6 @@ Result<ArrowArray> MonthTransform::Transform(const ArrowArray& input) {
129148
130149Result<std::shared_ptr<Type>> MonthTransform::ResultType () const {
131150 auto src_type = source_type ();
132- if (!src_type) {
133- return NotSupported (" null is not a valid input type for month transform" );
134- }
135151 switch (src_type->type_id ()) {
136152 case TypeId::kDate :
137153 case TypeId::kTimestamp :
@@ -143,6 +159,14 @@ Result<std::shared_ptr<Type>> MonthTransform::ResultType() const {
143159 }
144160}
145161
162+ Result<std::unique_ptr<TransformFunction>> MonthTransform::Make (
163+ std::shared_ptr<Type> const & source_type) {
164+ if (!source_type) {
165+ return NotSupported (" null is not a valid input type for month transform" );
166+ }
167+ return std::make_unique<MonthTransform>(source_type);
168+ }
169+
146170DayTransform::DayTransform (std::shared_ptr<Type> const & source_type)
147171 : TransformFunction(TransformType::kDay , source_type) {}
148172
@@ -152,9 +176,6 @@ Result<ArrowArray> DayTransform::Transform(const ArrowArray& input) {
152176
153177Result<std::shared_ptr<Type>> DayTransform::ResultType () const {
154178 auto src_type = source_type ();
155- if (!src_type) {
156- return NotSupported (" null is not a valid input type for day transform" );
157- }
158179 switch (src_type->type_id ()) {
159180 case TypeId::kDate :
160181 case TypeId::kTimestamp :
@@ -166,6 +187,14 @@ Result<std::shared_ptr<Type>> DayTransform::ResultType() const {
166187 }
167188}
168189
190+ Result<std::unique_ptr<TransformFunction>> DayTransform::Make (
191+ std::shared_ptr<Type> const & source_type) {
192+ if (!source_type) {
193+ return NotSupported (" null is not a valid input type for day transform" );
194+ }
195+ return std::make_unique<DayTransform>(source_type);
196+ }
197+
169198HourTransform::HourTransform (std::shared_ptr<Type> const & source_type)
170199 : TransformFunction(TransformType::kHour , source_type) {}
171200
@@ -175,9 +204,6 @@ Result<ArrowArray> HourTransform::Transform(const ArrowArray& input) {
175204
176205Result<std::shared_ptr<Type>> HourTransform::ResultType () const {
177206 auto src_type = source_type ();
178- if (!src_type) {
179- return NotSupported (" null is not a valid input type for hour transform" );
180- }
181207 switch (src_type->type_id ()) {
182208 case TypeId::kTimestamp :
183209 case TypeId::kTimestampTz :
@@ -188,19 +214,29 @@ Result<std::shared_ptr<Type>> HourTransform::ResultType() const {
188214 }
189215}
190216
217+ Result<std::unique_ptr<TransformFunction>> HourTransform::Make (
218+ std::shared_ptr<Type> const & source_type) {
219+ if (!source_type) {
220+ return NotSupported (" null is not a valid input type for hour transform" );
221+ }
222+ return std::make_unique<HourTransform>(source_type);
223+ }
224+
191225VoidTransform::VoidTransform (std::shared_ptr<Type> const & source_type)
192226 : TransformFunction(TransformType::kVoid , source_type) {}
193227
194228Result<ArrowArray> VoidTransform::Transform (const ArrowArray& input) {
195229 return NotImplemented (" VoidTransform::Transform" );
196230}
197231
198- Result<std::shared_ptr<Type>> VoidTransform::ResultType () const {
199- auto src_type = source_type ();
200- if (!src_type) {
232+ Result<std::shared_ptr<Type>> VoidTransform::ResultType () const { return source_type (); }
233+
234+ Result<std::unique_ptr<TransformFunction>> VoidTransform::Make (
235+ std::shared_ptr<Type> const & source_type) {
236+ if (!source_type) {
201237 return NotSupported (" null is not a valid input type for void transform" );
202238 }
203- return src_type ;
239+ return std::make_unique<VoidTransform>(source_type) ;
204240}
205241
206242} // namespace iceberg
0 commit comments