|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#include "iceberg/transform/transform_function.h" |
| 21 | + |
| 22 | +#include <format> |
| 23 | + |
| 24 | +#include <iceberg/type.h> |
| 25 | + |
| 26 | +namespace iceberg { |
| 27 | + |
| 28 | +IdentityTransform::IdentityTransform(std::shared_ptr<Type> const& source_type) |
| 29 | + : TransformFunction(TransformType::kIdentity, source_type) {} |
| 30 | + |
| 31 | +expected<ArrowArray, Error> IdentityTransform::Transform(const ArrowArray& input) { |
| 32 | + return unexpected<Error>( |
| 33 | + {.kind = ErrorKind::kNotImplemented, .message = "IdentityTransform::Transform"}); |
| 34 | +} |
| 35 | + |
| 36 | +expected<std::shared_ptr<Type>, Error> IdentityTransform::ResultType() const { |
| 37 | + auto src_type = source_type(); |
| 38 | + if (!src_type || !src_type->is_primitive()) { |
| 39 | + return unexpected(Error{ |
| 40 | + .kind = ErrorKind::kNotSupported, |
| 41 | + .message = std::format("{} is not a valid input type for identity transform", |
| 42 | + src_type ? src_type->ToString() : "null")}); |
| 43 | + } |
| 44 | + return src_type; |
| 45 | +} |
| 46 | + |
| 47 | +BucketTransform::BucketTransform(std::shared_ptr<Type> const& source_type, |
| 48 | + int32_t num_buckets) |
| 49 | + : TransformFunction(TransformType::kBucket, source_type), num_buckets_(num_buckets) {} |
| 50 | + |
| 51 | +expected<ArrowArray, Error> BucketTransform::Transform(const ArrowArray& input) { |
| 52 | + return unexpected<Error>( |
| 53 | + {.kind = ErrorKind::kNotImplemented, .message = "BucketTransform::Transform"}); |
| 54 | +} |
| 55 | + |
| 56 | +expected<std::shared_ptr<Type>, Error> BucketTransform::ResultType() const { |
| 57 | + return unexpected<Error>( |
| 58 | + {.kind = ErrorKind::kNotImplemented, .message = "BucketTransform::result_type"}); |
| 59 | +} |
| 60 | + |
| 61 | +std::string BucketTransform::ToString() const { |
| 62 | + return std::format("{}[{}]", iceberg::ToString(transform_type()), num_buckets_); |
| 63 | +} |
| 64 | + |
| 65 | +TruncateTransform::TruncateTransform(std::shared_ptr<Type> const& source_type, |
| 66 | + int32_t width) |
| 67 | + : TransformFunction(TransformType::kTruncate, source_type), width_(width) {} |
| 68 | + |
| 69 | +expected<ArrowArray, Error> TruncateTransform::Transform(const ArrowArray& input) { |
| 70 | + return unexpected<Error>( |
| 71 | + {.kind = ErrorKind::kNotImplemented, .message = "TruncateTransform::Transform"}); |
| 72 | +} |
| 73 | + |
| 74 | +expected<std::shared_ptr<Type>, Error> TruncateTransform::ResultType() const { |
| 75 | + return unexpected<Error>( |
| 76 | + {.kind = ErrorKind::kNotImplemented, .message = "TruncateTransform::result_type"}); |
| 77 | +} |
| 78 | + |
| 79 | +std::string TruncateTransform::ToString() const { |
| 80 | + return std::format("{}[{}]", iceberg::ToString(transform_type()), width_); |
| 81 | +} |
| 82 | + |
| 83 | +YearTransform::YearTransform(std::shared_ptr<Type> const& source_type) |
| 84 | + : TransformFunction(TransformType::kTruncate, source_type) {} |
| 85 | + |
| 86 | +expected<ArrowArray, Error> YearTransform::Transform(const ArrowArray& input) { |
| 87 | + return unexpected<Error>( |
| 88 | + {.kind = ErrorKind::kNotImplemented, .message = "YearTransform::Transform"}); |
| 89 | +} |
| 90 | + |
| 91 | +expected<std::shared_ptr<Type>, Error> YearTransform::ResultType() const { |
| 92 | + return unexpected<Error>( |
| 93 | + {.kind = ErrorKind::kNotImplemented, .message = "YearTransform::result_type"}); |
| 94 | +} |
| 95 | + |
| 96 | +MonthTransform::MonthTransform(std::shared_ptr<Type> const& source_type) |
| 97 | + : TransformFunction(TransformType::kMonth, source_type) {} |
| 98 | + |
| 99 | +expected<ArrowArray, Error> MonthTransform::Transform(const ArrowArray& input) { |
| 100 | + return unexpected<Error>( |
| 101 | + {.kind = ErrorKind::kNotImplemented, .message = "MonthTransform::Transform"}); |
| 102 | +} |
| 103 | + |
| 104 | +expected<std::shared_ptr<Type>, Error> MonthTransform::ResultType() const { |
| 105 | + return unexpected<Error>( |
| 106 | + {.kind = ErrorKind::kNotImplemented, .message = "MonthTransform::result_type"}); |
| 107 | +} |
| 108 | + |
| 109 | +DayTransform::DayTransform(std::shared_ptr<Type> const& source_type) |
| 110 | + : TransformFunction(TransformType::kDay, source_type) {} |
| 111 | + |
| 112 | +expected<ArrowArray, Error> DayTransform::Transform(const ArrowArray& input) { |
| 113 | + return unexpected<Error>( |
| 114 | + {.kind = ErrorKind::kNotImplemented, .message = "DayTransform::Transform"}); |
| 115 | +} |
| 116 | + |
| 117 | +expected<std::shared_ptr<Type>, Error> DayTransform::ResultType() const { |
| 118 | + return unexpected<Error>( |
| 119 | + {.kind = ErrorKind::kNotImplemented, .message = "DayTransform::result_type"}); |
| 120 | +} |
| 121 | + |
| 122 | +HourTransform::HourTransform(std::shared_ptr<Type> const& source_type) |
| 123 | + : TransformFunction(TransformType::kHour, source_type) {} |
| 124 | + |
| 125 | +expected<ArrowArray, Error> HourTransform::Transform(const ArrowArray& input) { |
| 126 | + return unexpected<Error>( |
| 127 | + {.kind = ErrorKind::kNotImplemented, .message = "HourTransform::Transform"}); |
| 128 | +} |
| 129 | + |
| 130 | +expected<std::shared_ptr<Type>, Error> HourTransform::ResultType() const { |
| 131 | + return unexpected<Error>( |
| 132 | + {.kind = ErrorKind::kNotImplemented, .message = "HourTransform::result_type"}); |
| 133 | +} |
| 134 | + |
| 135 | +VoidTransform::VoidTransform(std::shared_ptr<Type> const& source_type) |
| 136 | + : TransformFunction(TransformType::kVoid, source_type) {} |
| 137 | + |
| 138 | +expected<ArrowArray, Error> VoidTransform::Transform(const ArrowArray& input) { |
| 139 | + return unexpected<Error>( |
| 140 | + {.kind = ErrorKind::kNotImplemented, .message = "VoidTransform::Transform"}); |
| 141 | +} |
| 142 | + |
| 143 | +expected<std::shared_ptr<Type>, Error> VoidTransform::ResultType() const { |
| 144 | + return unexpected<Error>( |
| 145 | + {.kind = ErrorKind::kNotImplemented, .message = "VoidTransform::result_type"}); |
| 146 | +} |
| 147 | + |
| 148 | +} // namespace iceberg |
0 commit comments