|
| 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/puffin/file_metadata.h" |
| 21 | + |
| 22 | +#include <format> |
| 23 | + |
| 24 | +#include "iceberg/util/formatter_internal.h" |
| 25 | + |
| 26 | +namespace iceberg::puffin { |
| 27 | + |
| 28 | +std::string ToString(const Blob& blob) { |
| 29 | + std::string repr = "Blob["; |
| 30 | + std::format_to(std::back_inserter(repr), "type='{}',inputFields={},", blob.type, |
| 31 | + blob.input_fields); |
| 32 | + std::format_to(std::back_inserter(repr), "snapshotId={},sequenceNumber={},", |
| 33 | + blob.snapshot_id, blob.sequence_number); |
| 34 | + std::format_to(std::back_inserter(repr), "dataSize={}", blob.data.size()); |
| 35 | + if (blob.requested_compression.has_value()) { |
| 36 | + std::format_to(std::back_inserter(repr), ",requestedCompression={}", |
| 37 | + iceberg::puffin::ToString(*blob.requested_compression)); |
| 38 | + } |
| 39 | + if (!blob.properties.empty()) { |
| 40 | + std::format_to(std::back_inserter(repr), ",properties={}", blob.properties); |
| 41 | + } |
| 42 | + std::format_to(std::back_inserter(repr), "]"); |
| 43 | + return repr; |
| 44 | +} |
| 45 | + |
| 46 | +std::string ToString(const BlobMetadata& blob_metadata) { |
| 47 | + std::string repr = "BlobMetadata["; |
| 48 | + std::format_to(std::back_inserter(repr), "type='{}',inputFields={},", |
| 49 | + blob_metadata.type, blob_metadata.input_fields); |
| 50 | + std::format_to(std::back_inserter(repr), "snapshotId={},sequenceNumber={},", |
| 51 | + blob_metadata.snapshot_id, blob_metadata.sequence_number); |
| 52 | + std::format_to(std::back_inserter(repr), "offset={},length={}", blob_metadata.offset, |
| 53 | + blob_metadata.length); |
| 54 | + if (!blob_metadata.compression_codec.empty()) { |
| 55 | + std::format_to(std::back_inserter(repr), ",compressionCodec='{}'", |
| 56 | + blob_metadata.compression_codec); |
| 57 | + } |
| 58 | + if (!blob_metadata.properties.empty()) { |
| 59 | + std::format_to(std::back_inserter(repr), ",properties={}", blob_metadata.properties); |
| 60 | + } |
| 61 | + std::format_to(std::back_inserter(repr), "]"); |
| 62 | + return repr; |
| 63 | +} |
| 64 | + |
| 65 | +std::string ToString(const FileMetadata& file_metadata) { |
| 66 | + std::string repr = "FileMetadata["; |
| 67 | + std::format_to(std::back_inserter(repr), "blobs=["); |
| 68 | + for (size_t i = 0; i < file_metadata.blobs.size(); ++i) { |
| 69 | + if (i > 0) { |
| 70 | + std::format_to(std::back_inserter(repr), ","); |
| 71 | + } |
| 72 | + std::format_to(std::back_inserter(repr), "{}", ToString(file_metadata.blobs[i])); |
| 73 | + } |
| 74 | + std::format_to(std::back_inserter(repr), "]"); |
| 75 | + if (!file_metadata.properties.empty()) { |
| 76 | + std::format_to(std::back_inserter(repr), ",properties={}", file_metadata.properties); |
| 77 | + } |
| 78 | + std::format_to(std::back_inserter(repr), "]"); |
| 79 | + return repr; |
| 80 | +} |
| 81 | + |
| 82 | +} // namespace iceberg::puffin |
0 commit comments