forked from apache/iceberg-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform_function.cc
More file actions
246 lines (210 loc) · 8.26 KB
/
transform_function.cc
File metadata and controls
246 lines (210 loc) · 8.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "iceberg/transform_function.h"
#include "iceberg/type.h"
namespace iceberg {
IdentityTransform::IdentityTransform(std::shared_ptr<Type> const& source_type)
: TransformFunction(TransformType::kIdentity, source_type) {}
Result<ArrowArray> IdentityTransform::Transform(const ArrowArray& input) {
return NotImplemented("IdentityTransform::Transform");
}
Result<std::shared_ptr<Type>> IdentityTransform::ResultType() const {
return source_type();
}
Result<std::unique_ptr<TransformFunction>> IdentityTransform::Make(
std::shared_ptr<Type> const& source_type) {
if (!source_type || !source_type->is_primitive()) {
return NotSupported("{} is not a valid input type for identity transform",
source_type ? source_type->ToString() : "null");
}
return std::make_unique<IdentityTransform>(source_type);
}
BucketTransform::BucketTransform(std::shared_ptr<Type> const& source_type,
int32_t num_buckets)
: TransformFunction(TransformType::kBucket, source_type), num_buckets_(num_buckets) {}
Result<ArrowArray> BucketTransform::Transform(const ArrowArray& input) {
return NotImplemented("BucketTransform::Transform");
}
Result<std::shared_ptr<Type>> BucketTransform::ResultType() const {
return iceberg::int32();
}
Result<std::unique_ptr<TransformFunction>> BucketTransform::Make(
std::shared_ptr<Type> const& source_type, int32_t num_buckets) {
if (!source_type) {
return NotSupported("null is not a valid input type for bucket transform");
}
switch (source_type->type_id()) {
case TypeId::kInt:
case TypeId::kLong:
case TypeId::kDecimal:
case TypeId::kDate:
case TypeId::kTime:
case TypeId::kTimestamp:
case TypeId::kTimestampTz:
case TypeId::kString:
case TypeId::kUuid:
case TypeId::kFixed:
case TypeId::kBinary:
break;
default:
return NotSupported("{} is not a valid input type for bucket transform",
source_type->ToString());
}
if (num_buckets <= 0) {
return InvalidArgument("Number of buckets must be positive, got {}", num_buckets);
}
return std::make_unique<BucketTransform>(source_type, num_buckets);
}
TruncateTransform::TruncateTransform(std::shared_ptr<Type> const& source_type,
int32_t width)
: TransformFunction(TransformType::kTruncate, source_type), width_(width) {}
Result<ArrowArray> TruncateTransform::Transform(const ArrowArray& input) {
return NotImplemented("TruncateTransform::Transform");
}
Result<std::shared_ptr<Type>> TruncateTransform::ResultType() const {
return source_type();
}
Result<std::unique_ptr<TransformFunction>> TruncateTransform::Make(
std::shared_ptr<Type> const& source_type, int32_t width) {
if (!source_type) {
return NotSupported("null is not a valid input type for truncate transform");
}
switch (source_type->type_id()) {
case TypeId::kInt:
case TypeId::kLong:
case TypeId::kDecimal:
case TypeId::kString:
case TypeId::kBinary:
break;
default:
return NotSupported("{} is not a valid input type for truncate transform",
source_type->ToString());
}
if (width <= 0) {
return InvalidArgument("Width must be positive, got {}", width);
}
return std::make_unique<TruncateTransform>(source_type, width);
}
YearTransform::YearTransform(std::shared_ptr<Type> const& source_type)
: TransformFunction(TransformType::kTruncate, source_type) {}
Result<ArrowArray> YearTransform::Transform(const ArrowArray& input) {
return NotImplemented("YearTransform::Transform");
}
Result<std::shared_ptr<Type>> YearTransform::ResultType() const {
return iceberg::int32();
}
Result<std::unique_ptr<TransformFunction>> YearTransform::Make(
std::shared_ptr<Type> const& source_type) {
if (!source_type) {
return NotSupported("null is not a valid input type for year transform");
}
switch (source_type->type_id()) {
case TypeId::kDate:
case TypeId::kTimestamp:
case TypeId::kTimestampTz:
break;
default:
return NotSupported("{} is not a valid input type for year transform",
source_type->ToString());
}
return std::make_unique<YearTransform>(source_type);
}
MonthTransform::MonthTransform(std::shared_ptr<Type> const& source_type)
: TransformFunction(TransformType::kMonth, source_type) {}
Result<ArrowArray> MonthTransform::Transform(const ArrowArray& input) {
return NotImplemented("MonthTransform::Transform");
}
Result<std::shared_ptr<Type>> MonthTransform::ResultType() const {
return iceberg::int32();
}
Result<std::unique_ptr<TransformFunction>> MonthTransform::Make(
std::shared_ptr<Type> const& source_type) {
if (!source_type) {
return NotSupported("null is not a valid input type for month transform");
}
switch (source_type->type_id()) {
case TypeId::kDate:
case TypeId::kTimestamp:
case TypeId::kTimestampTz:
break;
default:
return NotSupported("{} is not a valid input type for month transform",
source_type->ToString());
}
return std::make_unique<MonthTransform>(source_type);
}
DayTransform::DayTransform(std::shared_ptr<Type> const& source_type)
: TransformFunction(TransformType::kDay, source_type) {}
Result<ArrowArray> DayTransform::Transform(const ArrowArray& input) {
return NotImplemented("DayTransform::Transform");
}
Result<std::shared_ptr<Type>> DayTransform::ResultType() const { return iceberg::date(); }
Result<std::unique_ptr<TransformFunction>> DayTransform::Make(
std::shared_ptr<Type> const& source_type) {
if (!source_type) {
return NotSupported("null is not a valid input type for day transform");
}
switch (source_type->type_id()) {
case TypeId::kDate:
case TypeId::kTimestamp:
case TypeId::kTimestampTz:
break;
default:
return NotSupported("{} is not a valid input type for day transform",
source_type->ToString());
}
return std::make_unique<DayTransform>(source_type);
}
HourTransform::HourTransform(std::shared_ptr<Type> const& source_type)
: TransformFunction(TransformType::kHour, source_type) {}
Result<ArrowArray> HourTransform::Transform(const ArrowArray& input) {
return NotImplemented("HourTransform::Transform");
}
Result<std::shared_ptr<Type>> HourTransform::ResultType() const {
return iceberg::int32();
}
Result<std::unique_ptr<TransformFunction>> HourTransform::Make(
std::shared_ptr<Type> const& source_type) {
if (!source_type) {
return NotSupported("null is not a valid input type for hour transform");
}
switch (source_type->type_id()) {
case TypeId::kTimestamp:
case TypeId::kTimestampTz:
break;
default:
return NotSupported("{} is not a valid input type for hour transform",
source_type->ToString());
}
return std::make_unique<HourTransform>(source_type);
}
VoidTransform::VoidTransform(std::shared_ptr<Type> const& source_type)
: TransformFunction(TransformType::kVoid, source_type) {}
Result<ArrowArray> VoidTransform::Transform(const ArrowArray& input) {
return NotImplemented("VoidTransform::Transform");
}
Result<std::shared_ptr<Type>> VoidTransform::ResultType() const { return source_type(); }
Result<std::unique_ptr<TransformFunction>> VoidTransform::Make(
std::shared_ptr<Type> const& source_type) {
if (!source_type) {
return NotSupported("null is not a valid input type for void transform");
}
return std::make_unique<VoidTransform>(source_type);
}
} // namespace iceberg