@@ -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,
@@ -48,7 +52,35 @@ Result<ArrowArray> BucketTransform::Transform(const ArrowArray& input) {
4852}
4953
5054Result<std::shared_ptr<Type>> BucketTransform::ResultType () const {
51- return NotImplemented (" BucketTransform::result_type" );
55+ return iceberg::int32 ();
56+ }
57+
58+ Result<std::unique_ptr<TransformFunction>> BucketTransform::Make (
59+ std::shared_ptr<Type> const & source_type, int32_t num_buckets) {
60+ if (!source_type) {
61+ return NotSupported (" null is not a valid input type for bucket transform" );
62+ }
63+ switch (source_type->type_id ()) {
64+ case TypeId::kInt :
65+ case TypeId::kLong :
66+ case TypeId::kDecimal :
67+ case TypeId::kDate :
68+ case TypeId::kTime :
69+ case TypeId::kTimestamp :
70+ case TypeId::kTimestampTz :
71+ case TypeId::kString :
72+ case TypeId::kUuid :
73+ case TypeId::kFixed :
74+ case TypeId::kBinary :
75+ break ;
76+ default :
77+ return NotSupported (" {} is not a valid input type for bucket transform" ,
78+ source_type->ToString ());
79+ }
80+ if (num_buckets <= 0 ) {
81+ return InvalidArgument (" Number of buckets must be positive, got {}" , num_buckets);
82+ }
83+ return std::make_unique<BucketTransform>(source_type, num_buckets);
5284}
5385
5486TruncateTransform::TruncateTransform (std::shared_ptr<Type> const & source_type,
@@ -60,7 +92,29 @@ Result<ArrowArray> TruncateTransform::Transform(const ArrowArray& input) {
6092}
6193
6294Result<std::shared_ptr<Type>> TruncateTransform::ResultType () const {
63- return NotImplemented (" TruncateTransform::result_type" );
95+ return source_type ();
96+ }
97+
98+ Result<std::unique_ptr<TransformFunction>> TruncateTransform::Make (
99+ std::shared_ptr<Type> const & source_type, int32_t width) {
100+ if (!source_type) {
101+ return NotSupported (" null is not a valid input type for truncate transform" );
102+ }
103+ switch (source_type->type_id ()) {
104+ case TypeId::kInt :
105+ case TypeId::kLong :
106+ case TypeId::kDecimal :
107+ case TypeId::kString :
108+ case TypeId::kBinary :
109+ break ;
110+ default :
111+ return NotSupported (" {} is not a valid input type for truncate transform" ,
112+ source_type->ToString ());
113+ }
114+ if (width <= 0 ) {
115+ return InvalidArgument (" Width must be positive, got {}" , width);
116+ }
117+ return std::make_unique<TruncateTransform>(source_type, width);
64118}
65119
66120YearTransform::YearTransform (std::shared_ptr<Type> const & source_type)
@@ -71,7 +125,24 @@ Result<ArrowArray> YearTransform::Transform(const ArrowArray& input) {
71125}
72126
73127Result<std::shared_ptr<Type>> YearTransform::ResultType () const {
74- return NotImplemented (" YearTransform::result_type" );
128+ return iceberg::int32 ();
129+ }
130+
131+ Result<std::unique_ptr<TransformFunction>> YearTransform::Make (
132+ std::shared_ptr<Type> const & source_type) {
133+ if (!source_type) {
134+ return NotSupported (" null is not a valid input type for year transform" );
135+ }
136+ switch (source_type->type_id ()) {
137+ case TypeId::kDate :
138+ case TypeId::kTimestamp :
139+ case TypeId::kTimestampTz :
140+ break ;
141+ default :
142+ return NotSupported (" {} is not a valid input type for year transform" ,
143+ source_type->ToString ());
144+ }
145+ return std::make_unique<YearTransform>(source_type);
75146}
76147
77148MonthTransform::MonthTransform (std::shared_ptr<Type> const & source_type)
@@ -82,7 +153,24 @@ Result<ArrowArray> MonthTransform::Transform(const ArrowArray& input) {
82153}
83154
84155Result<std::shared_ptr<Type>> MonthTransform::ResultType () const {
85- return NotImplemented (" MonthTransform::result_type" );
156+ return iceberg::int32 ();
157+ }
158+
159+ Result<std::unique_ptr<TransformFunction>> MonthTransform::Make (
160+ std::shared_ptr<Type> const & source_type) {
161+ if (!source_type) {
162+ return NotSupported (" null is not a valid input type for month transform" );
163+ }
164+ switch (source_type->type_id ()) {
165+ case TypeId::kDate :
166+ case TypeId::kTimestamp :
167+ case TypeId::kTimestampTz :
168+ break ;
169+ default :
170+ return NotSupported (" {} is not a valid input type for month transform" ,
171+ source_type->ToString ());
172+ }
173+ return std::make_unique<MonthTransform>(source_type);
86174}
87175
88176DayTransform::DayTransform (std::shared_ptr<Type> const & source_type)
@@ -92,8 +180,23 @@ Result<ArrowArray> DayTransform::Transform(const ArrowArray& input) {
92180 return NotImplemented (" DayTransform::Transform" );
93181}
94182
95- Result<std::shared_ptr<Type>> DayTransform::ResultType () const {
96- return NotImplemented (" DayTransform::result_type" );
183+ Result<std::shared_ptr<Type>> DayTransform::ResultType () const { return iceberg::date (); }
184+
185+ Result<std::unique_ptr<TransformFunction>> DayTransform::Make (
186+ std::shared_ptr<Type> const & source_type) {
187+ if (!source_type) {
188+ return NotSupported (" null is not a valid input type for day transform" );
189+ }
190+ switch (source_type->type_id ()) {
191+ case TypeId::kDate :
192+ case TypeId::kTimestamp :
193+ case TypeId::kTimestampTz :
194+ break ;
195+ default :
196+ return NotSupported (" {} is not a valid input type for day transform" ,
197+ source_type->ToString ());
198+ }
199+ return std::make_unique<DayTransform>(source_type);
97200}
98201
99202HourTransform::HourTransform (std::shared_ptr<Type> const & source_type)
@@ -104,7 +207,23 @@ Result<ArrowArray> HourTransform::Transform(const ArrowArray& input) {
104207}
105208
106209Result<std::shared_ptr<Type>> HourTransform::ResultType () const {
107- return NotImplemented (" HourTransform::result_type" );
210+ return iceberg::int32 ();
211+ }
212+
213+ Result<std::unique_ptr<TransformFunction>> HourTransform::Make (
214+ std::shared_ptr<Type> const & source_type) {
215+ if (!source_type) {
216+ return NotSupported (" null is not a valid input type for hour transform" );
217+ }
218+ switch (source_type->type_id ()) {
219+ case TypeId::kTimestamp :
220+ case TypeId::kTimestampTz :
221+ break ;
222+ default :
223+ return NotSupported (" {} is not a valid input type for hour transform" ,
224+ source_type->ToString ());
225+ }
226+ return std::make_unique<HourTransform>(source_type);
108227}
109228
110229VoidTransform::VoidTransform (std::shared_ptr<Type> const & source_type)
@@ -114,8 +233,14 @@ Result<ArrowArray> VoidTransform::Transform(const ArrowArray& input) {
114233 return NotImplemented (" VoidTransform::Transform" );
115234}
116235
117- Result<std::shared_ptr<Type>> VoidTransform::ResultType () const {
118- return NotImplemented (" VoidTransform::result_type" );
236+ Result<std::shared_ptr<Type>> VoidTransform::ResultType () const { return source_type (); }
237+
238+ Result<std::unique_ptr<TransformFunction>> VoidTransform::Make (
239+ std::shared_ptr<Type> const & source_type) {
240+ if (!source_type) {
241+ return NotSupported (" null is not a valid input type for void transform" );
242+ }
243+ return std::make_unique<VoidTransform>(source_type);
119244}
120245
121246} // namespace iceberg
0 commit comments