iceberg-cpp
Loading...
Searching...
No Matches
json_serde_internal.h
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#include <map>
23#include <memory>
24#include <optional>
25#include <string>
26#include <string_view>
27#include <unordered_map>
28
29#include <nlohmann/json_fwd.hpp>
30
31#include "iceberg/result.h"
34#include "iceberg/type_fwd.h"
35
36namespace iceberg {
37
46ICEBERG_EXPORT nlohmann::json ToJson(const SortField& sort_field);
47
57ICEBERG_EXPORT Result<std::unique_ptr<SortField>> SortFieldFromJson(
58 const nlohmann::json& json);
59
68ICEBERG_EXPORT nlohmann::json ToJson(const SortOrder& sort_order);
69
80ICEBERG_EXPORT Result<std::unique_ptr<SortOrder>> SortOrderFromJson(
81 const nlohmann::json& json, const std::shared_ptr<Schema>& current_schema);
82
88ICEBERG_EXPORT Result<std::unique_ptr<SortOrder>> SortOrderFromJson(
89 const nlohmann::json& json);
90
95ICEBERG_EXPORT nlohmann::json ToJson(const Schema& schema);
96
101ICEBERG_EXPORT Result<std::string> ToJsonString(const Schema& schema);
102
107ICEBERG_EXPORT Result<std::unique_ptr<Schema>> SchemaFromJson(const nlohmann::json& json);
108
113ICEBERG_EXPORT nlohmann::json ToJson(const Type& type);
114
119ICEBERG_EXPORT Result<std::unique_ptr<Type>> TypeFromJson(const nlohmann::json& json);
120
125ICEBERG_EXPORT nlohmann::json ToJson(const SchemaField& field);
126
131ICEBERG_EXPORT Result<std::unique_ptr<SchemaField>> FieldFromJson(
132 const nlohmann::json& json);
133
143ICEBERG_EXPORT nlohmann::json ToJson(const PartitionField& partition_field);
144
156ICEBERG_EXPORT Result<std::unique_ptr<PartitionField>> PartitionFieldFromJson(
157 const nlohmann::json& json, bool allow_field_id_missing = false);
158
169ICEBERG_EXPORT nlohmann::json ToJson(const PartitionSpec& partition_spec);
170
181ICEBERG_EXPORT Result<std::string> ToJsonString(const PartitionSpec& partition_spec);
182
195ICEBERG_EXPORT Result<std::unique_ptr<PartitionSpec>> PartitionSpecFromJson(
196 const std::shared_ptr<Schema>& schema, const nlohmann::json& json,
197 int32_t default_spec_id);
198
204ICEBERG_EXPORT Result<std::unique_ptr<PartitionSpec>> PartitionSpecFromJson(
205 const nlohmann::json& json);
206
211ICEBERG_EXPORT nlohmann::json ToJson(const SnapshotRef& snapshot_ref);
212
217ICEBERG_EXPORT Result<std::unique_ptr<SnapshotRef>> SnapshotRefFromJson(
218 const nlohmann::json& json);
219
224ICEBERG_EXPORT nlohmann::json ToJson(const Snapshot& snapshot);
225
230ICEBERG_EXPORT Result<std::unique_ptr<Snapshot>> SnapshotFromJson(
231 const nlohmann::json& json);
232
237ICEBERG_EXPORT nlohmann::json ToJson(const StatisticsFile& statistics_file);
238
243ICEBERG_EXPORT Result<std::unique_ptr<StatisticsFile>> StatisticsFileFromJson(
244 const nlohmann::json& json);
245
250ICEBERG_EXPORT nlohmann::json ToJson(
251 const PartitionStatisticsFile& partition_statistics_file);
252
257ICEBERG_EXPORT Result<std::unique_ptr<PartitionStatisticsFile>>
258PartitionStatisticsFileFromJson(const nlohmann::json& json);
259
264ICEBERG_EXPORT nlohmann::json ToJson(const SnapshotLogEntry& snapshot_log_entry);
265
270ICEBERG_EXPORT Result<SnapshotLogEntry> SnapshotLogEntryFromJson(
271 const nlohmann::json& json);
272
277ICEBERG_EXPORT nlohmann::json ToJson(const MetadataLogEntry& metadata_log_entry);
278
283ICEBERG_EXPORT Result<MetadataLogEntry> MetadataLogEntryFromJson(
284 const nlohmann::json& json);
285
290ICEBERG_EXPORT nlohmann::json ToJson(const TableMetadata& table_metadata);
291
296ICEBERG_EXPORT Result<std::string> ToJsonString(const TableMetadata& table_metadata);
297
302ICEBERG_EXPORT Result<std::unique_ptr<TableMetadata>> TableMetadataFromJson(
303 const nlohmann::json& json);
304
309ICEBERG_EXPORT Result<nlohmann::json> FromJsonString(const std::string& json_string);
310
315ICEBERG_EXPORT Result<std::string> ToJsonString(const nlohmann::json& json);
316
321ICEBERG_EXPORT nlohmann::json ToJson(const MappedField& field);
322
327ICEBERG_EXPORT Result<MappedField> MappedFieldFromJson(const nlohmann::json& json);
328
333ICEBERG_EXPORT nlohmann::json ToJson(const MappedFields& mapped_fields);
334
339ICEBERG_EXPORT Result<std::unique_ptr<MappedFields>> MappedFieldsFromJson(
340 const nlohmann::json& json);
341
346ICEBERG_EXPORT nlohmann::json ToJson(const NameMapping& name_mapping);
347
352ICEBERG_EXPORT Result<std::unique_ptr<NameMapping>> NameMappingFromJson(
353 const nlohmann::json& json);
354
359ICEBERG_EXPORT Result<std::string> UpdateMappingFromJsonString(
360 std::string_view mapping_json,
361 const std::unordered_map<int32_t, std::shared_ptr<SchemaField>>& updates,
362 const std::multimap<int32_t, int32_t>& adds);
363
369ICEBERG_EXPORT nlohmann::json ToJson(const TableIdentifier& identifier);
370
375ICEBERG_EXPORT Result<TableIdentifier> TableIdentifierFromJson(
376 const nlohmann::json& json);
377
382ICEBERG_EXPORT nlohmann::json ToJson(const Namespace& ns);
383
388ICEBERG_EXPORT Result<Namespace> NamespaceFromJson(const nlohmann::json& json);
389
394ICEBERG_EXPORT nlohmann::json ToJson(const TableUpdate& update);
395
400ICEBERG_EXPORT Result<std::unique_ptr<TableUpdate>> TableUpdateFromJson(
401 const nlohmann::json& json);
402
407ICEBERG_EXPORT nlohmann::json ToJson(const TableRequirement& requirement);
408
413ICEBERG_EXPORT Result<std::unique_ptr<TableRequirement>> TableRequirementFromJson(
414 const nlohmann::json& json);
415
416} // namespace iceberg