@@ -35,9 +35,7 @@ IdentityTransform::IdentityTransform(std::shared_ptr<Type> const& source_type)
3535
3636Result<Literal> IdentityTransform::Transform (const Literal& literal) { return literal; }
3737
38- Result<std::shared_ptr<Type>> IdentityTransform::ResultType () const {
39- return source_type ();
40- }
38+ std::shared_ptr<Type> IdentityTransform::ResultType () const { return source_type (); }
4139
4240Result<std::unique_ptr<TransformFunction>> IdentityTransform::Make (
4341 std::shared_ptr<Type> const & source_type) {
@@ -59,6 +57,10 @@ Result<Literal> BucketTransform::Transform(const Literal& literal) {
5957 " Cannot apply bucket transform to literal with value {} of type {}" ,
6058 literal.ToString (), source_type ()->ToString ());
6159 }
60+ if (literal.IsNull ()) {
61+ return Literal::Null (iceberg::int32 ());
62+ }
63+
6264 int32_t hash_value = 0 ;
6365 std::visit (
6466 [&](auto && value) {
@@ -92,9 +94,7 @@ Result<Literal> BucketTransform::Transform(const Literal& literal) {
9294 return Literal::Int (bucket_index);
9395}
9496
95- Result<std::shared_ptr<Type>> BucketTransform::ResultType () const {
96- return iceberg::int32 ();
97- }
97+ std::shared_ptr<Type> BucketTransform::ResultType () const { return iceberg::int32 (); }
9898
9999Result<std::unique_ptr<TransformFunction>> BucketTransform::Make (
100100 std::shared_ptr<Type> const & source_type, int32_t num_buckets) {
@@ -135,6 +135,10 @@ Result<Literal> TruncateTransform::Transform(const Literal& literal) {
135135 " Cannot apply truncate transform to literal with value {} of type {}" ,
136136 literal.ToString (), source_type ()->ToString ());
137137 }
138+ if (literal.IsNull ()) {
139+ // Return null as is
140+ return literal;
141+ }
138142
139143 switch (source_type ()->type_id ()) {
140144 case TypeId::kInt : {
@@ -183,9 +187,7 @@ Result<Literal> TruncateTransform::Transform(const Literal& literal) {
183187 }
184188}
185189
186- Result<std::shared_ptr<Type>> TruncateTransform::ResultType () const {
187- return source_type ();
188- }
190+ std::shared_ptr<Type> TruncateTransform::ResultType () const { return source_type (); }
189191
190192Result<std::unique_ptr<TransformFunction>> TruncateTransform::Make (
191193 std::shared_ptr<Type> const & source_type, int32_t width) {
@@ -219,6 +221,9 @@ Result<Literal> YearTransform::Transform(const Literal& literal) {
219221 " Cannot apply year transform to literal with value {} of type {}" ,
220222 literal.ToString (), source_type ()->ToString ());
221223 }
224+ if (literal.IsNull ()) {
225+ return Literal::Null (iceberg::int32 ());
226+ }
222227
223228 using namespace std ::chrono; // NOLINT
224229 switch (source_type ()->type_id ()) {
@@ -240,9 +245,7 @@ Result<Literal> YearTransform::Transform(const Literal& literal) {
240245 }
241246}
242247
243- Result<std::shared_ptr<Type>> YearTransform::ResultType () const {
244- return iceberg::int32 ();
245- }
248+ std::shared_ptr<Type> YearTransform::ResultType () const { return iceberg::int32 (); }
246249
247250Result<std::unique_ptr<TransformFunction>> YearTransform::Make (
248251 std::shared_ptr<Type> const & source_type) {
@@ -271,6 +274,9 @@ Result<Literal> MonthTransform::Transform(const Literal& literal) {
271274 " Cannot apply month transform to literal with value {} of type {}" ,
272275 literal.ToString (), source_type ()->ToString ());
273276 }
277+ if (literal.IsNull ()) {
278+ return Literal::Null (iceberg::int32 ());
279+ }
274280
275281 using namespace std ::chrono; // NOLINT
276282 switch (source_type ()->type_id ()) {
@@ -304,9 +310,7 @@ Result<Literal> MonthTransform::Transform(const Literal& literal) {
304310 }
305311}
306312
307- Result<std::shared_ptr<Type>> MonthTransform::ResultType () const {
308- return iceberg::int32 ();
309- }
313+ std::shared_ptr<Type> MonthTransform::ResultType () const { return iceberg::int32 (); }
310314
311315Result<std::unique_ptr<TransformFunction>> MonthTransform::Make (
312316 std::shared_ptr<Type> const & source_type) {
@@ -335,6 +339,9 @@ Result<Literal> DayTransform::Transform(const Literal& literal) {
335339 " Cannot apply day transform to literal with value {} of type {}" ,
336340 literal.ToString (), source_type ()->ToString ());
337341 }
342+ if (literal.IsNull ()) {
343+ return Literal::Null (iceberg::int32 ());
344+ }
338345
339346 using namespace std ::chrono; // NOLINT
340347 switch (source_type ()->type_id ()) {
@@ -357,7 +364,7 @@ Result<Literal> DayTransform::Transform(const Literal& literal) {
357364 }
358365}
359366
360- Result< std::shared_ptr<Type>> DayTransform::ResultType () const { return iceberg::date (); }
367+ std::shared_ptr<Type> DayTransform::ResultType () const { return iceberg::int32 (); }
361368
362369Result<std::unique_ptr<TransformFunction>> DayTransform::Make (
363370 std::shared_ptr<Type> const & source_type) {
@@ -387,6 +394,10 @@ Result<Literal> HourTransform::Transform(const Literal& literal) {
387394 literal.ToString (), source_type ()->ToString ());
388395 }
389396
397+ if (literal.IsNull ()) {
398+ return Literal::Null (int32 ());
399+ }
400+
390401 using namespace std ::chrono; // NOLINT
391402 switch (source_type ()->type_id ()) {
392403 case TypeId::kTimestamp :
@@ -405,9 +416,7 @@ Result<Literal> HourTransform::Transform(const Literal& literal) {
405416 }
406417}
407418
408- Result<std::shared_ptr<Type>> HourTransform::ResultType () const {
409- return iceberg::int32 ();
410- }
419+ std::shared_ptr<Type> HourTransform::ResultType () const { return iceberg::int32 (); }
411420
412421Result<std::unique_ptr<TransformFunction>> HourTransform::Make (
413422 std::shared_ptr<Type> const & source_type) {
@@ -429,10 +438,10 @@ VoidTransform::VoidTransform(std::shared_ptr<Type> const& source_type)
429438 : TransformFunction(TransformType::kVoid , source_type) {}
430439
431440Result<Literal> VoidTransform::Transform (const Literal& literal) {
432- return Literal::Null ();
441+ return literal. IsNull () ? literal : Literal::Null (literal. type () );
433442}
434443
435- Result< std::shared_ptr<Type> > VoidTransform::ResultType () const { return source_type (); }
444+ std::shared_ptr<Type> VoidTransform::ResultType () const { return source_type (); }
436445
437446Result<std::unique_ptr<TransformFunction>> VoidTransform::Make (
438447 std::shared_ptr<Type> const & source_type) {
0 commit comments