|
| 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 | +#pragma once |
| 21 | + |
| 22 | +/// \file iceberg/partition_field.h |
| 23 | +/// A partition field in a partition spec |
| 24 | + |
| 25 | +#include <cstdint> |
| 26 | +#include <memory> |
| 27 | +#include <string> |
| 28 | +#include <string_view> |
| 29 | +#include <vector> |
| 30 | + |
| 31 | +#include "iceberg/iceberg_export.h" |
| 32 | +#include "iceberg/type_fwd.h" |
| 33 | +#include "iceberg/util/formattable.h" |
| 34 | + |
| 35 | +namespace iceberg { |
| 36 | + |
| 37 | +/// \brief a field with its transform. |
| 38 | +class ICEBERG_EXPORT PartitionField : public util::Formattable { |
| 39 | + public: |
| 40 | + /// \brief Construct a field. |
| 41 | + /// \param[in] source_id The source field ID. |
| 42 | + /// \param[in] field_id The partition field ID. |
| 43 | + /// \param[in] name The partition field name. |
| 44 | + /// \param[in] transform The transform function. |
| 45 | + PartitionField(int32_t source_id, int32_t field_id, std::string name, |
| 46 | + std::shared_ptr<TransformFunction> transform); |
| 47 | + |
| 48 | + /// \brief Get the source field ID. |
| 49 | + int32_t source_id() const; |
| 50 | + |
| 51 | + /// \brief Get the partition field ID. |
| 52 | + int32_t field_id() const; |
| 53 | + |
| 54 | + /// \brief Get the partition field name. |
| 55 | + std::string_view name() const; |
| 56 | + |
| 57 | + /// \brief Get the transform type. |
| 58 | + std::shared_ptr<TransformFunction> const& transform() const; |
| 59 | + |
| 60 | + std::string ToString() const override; |
| 61 | + |
| 62 | + friend bool operator==(const PartitionField& lhs, const PartitionField& rhs) { |
| 63 | + return lhs.Equals(rhs); |
| 64 | + } |
| 65 | + |
| 66 | + friend bool operator!=(const PartitionField& lhs, const PartitionField& rhs) { |
| 67 | + return !(lhs == rhs); |
| 68 | + } |
| 69 | + |
| 70 | + private: |
| 71 | + /// \brief Compare two fields for equality. |
| 72 | + [[nodiscard]] bool Equals(const PartitionField& other) const; |
| 73 | + |
| 74 | + int32_t source_id_; |
| 75 | + int32_t field_id_; |
| 76 | + std::string name_; |
| 77 | + std::shared_ptr<TransformFunction> transform_; |
| 78 | +}; |
| 79 | + |
| 80 | +} // namespace iceberg |
0 commit comments