iceberg-cpp
Loading...
Searching...
No Matches
json_serde_internal.h
Go to the documentation of this file.
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 <memory>
23#include <unordered_map>
24#include <vector>
25
26#include <nlohmann/json_fwd.hpp>
27
28#include "iceberg/catalog/rest/iceberg_rest_export.h"
30#include "iceberg/result.h"
31#include "iceberg/type_fwd.h"
32
35
36namespace iceberg::rest {
37
38template <typename Model>
39Result<Model> FromJson(const nlohmann::json& json);
40
41#define ICEBERG_DECLARE_JSON_SERDE(Model) \
42 ICEBERG_REST_EXPORT Result<Model> Model##FromJson(const nlohmann::json& json); \
43 \
44 template <> \
45 ICEBERG_REST_EXPORT Result<Model> FromJson(const nlohmann::json& json); \
46 \
47 ICEBERG_REST_EXPORT nlohmann::json ToJson(const Model& model);
48
51ICEBERG_DECLARE_JSON_SERDE(CatalogConfig)
52ICEBERG_DECLARE_JSON_SERDE(ErrorResponse)
53ICEBERG_DECLARE_JSON_SERDE(ListNamespacesResponse)
54ICEBERG_DECLARE_JSON_SERDE(CreateNamespaceRequest)
55ICEBERG_DECLARE_JSON_SERDE(CreateNamespaceResponse)
56ICEBERG_DECLARE_JSON_SERDE(GetNamespaceResponse)
57ICEBERG_DECLARE_JSON_SERDE(UpdateNamespacePropertiesRequest)
58ICEBERG_DECLARE_JSON_SERDE(UpdateNamespacePropertiesResponse)
59ICEBERG_DECLARE_JSON_SERDE(ListTablesResponse)
60ICEBERG_DECLARE_JSON_SERDE(RegisterTableRequest)
61ICEBERG_DECLARE_JSON_SERDE(RenameTableRequest)
62ICEBERG_DECLARE_JSON_SERDE(OAuthTokenResponse)
63
64#undef ICEBERG_DECLARE_JSON_SERDE
65
66// These models embed a Schema/TableMetadata whose ToJson returns Result, so their own
67// ToJson returns Result too. FromJson is declared like the macro-based models above.
68ICEBERG_REST_EXPORT Result<LoadTableResult> LoadTableResultFromJson(
69 const nlohmann::json& json);
70template <>
71ICEBERG_REST_EXPORT Result<LoadTableResult> FromJson(const nlohmann::json& json);
72ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(const LoadTableResult& model);
73
74ICEBERG_REST_EXPORT Result<CreateTableRequest> CreateTableRequestFromJson(
75 const nlohmann::json& json);
76template <>
77ICEBERG_REST_EXPORT Result<CreateTableRequest> FromJson(const nlohmann::json& json);
78ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(const CreateTableRequest& model);
79
80ICEBERG_REST_EXPORT Result<CommitTableRequest> CommitTableRequestFromJson(
81 const nlohmann::json& json);
82template <>
83ICEBERG_REST_EXPORT Result<CommitTableRequest> FromJson(const nlohmann::json& json);
84ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(const CommitTableRequest& model);
85
86ICEBERG_REST_EXPORT Result<CommitTableResponse> CommitTableResponseFromJson(
87 const nlohmann::json& json);
88template <>
89ICEBERG_REST_EXPORT Result<CommitTableResponse> FromJson(const nlohmann::json& json);
90ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(const CommitTableResponse& model);
91
92ICEBERG_REST_EXPORT Result<PlanTableScanResponse> PlanTableScanResponseFromJson(
93 const nlohmann::json& json,
94 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
95 partition_specs_by_id,
96 const Schema& schema);
97ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(
98 const PlanTableScanResponse& response,
99 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
100 partition_specs_by_id,
101 const Schema& schema);
102
103ICEBERG_REST_EXPORT Result<FetchPlanningResultResponse>
104FetchPlanningResultResponseFromJson(
105 const nlohmann::json& json,
106 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
107 partition_specs_by_id,
108 const Schema& schema);
109ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(
110 const FetchPlanningResultResponse& response,
111 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
112 partition_specs_by_id,
113 const Schema& schema);
114
115ICEBERG_REST_EXPORT Result<FetchScanTasksResponse> FetchScanTasksResponseFromJson(
116 const nlohmann::json& json,
117 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
118 partition_specs_by_id,
119 const Schema& schema);
120ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(
121 const FetchScanTasksResponse& response,
122 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
123 partition_specs_by_id,
124 const Schema& schema);
125
126ICEBERG_REST_EXPORT Result<PlanTableScanRequest> PlanTableScanRequestFromJson(
127 const nlohmann::json& json);
128template <>
129ICEBERG_REST_EXPORT Result<PlanTableScanRequest> FromJson(const nlohmann::json& json);
130ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(const PlanTableScanRequest& request);
131
132ICEBERG_REST_EXPORT Result<FetchScanTasksRequest> FetchScanTasksRequestFromJson(
133 const nlohmann::json& json);
134template <>
135ICEBERG_REST_EXPORT Result<FetchScanTasksRequest> FromJson(const nlohmann::json& json);
136ICEBERG_REST_EXPORT nlohmann::json ToJson(const FetchScanTasksRequest& request);
137
138ICEBERG_REST_EXPORT Result<nlohmann::json> ToJson(
139 const DataFile& df,
140 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
141 partition_specs_by_id,
142 const Schema& schema);
143
144ICEBERG_REST_EXPORT Result<DataFile> DataFileFromJson(
145 const nlohmann::json& json,
146 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
147 partition_spec_by_id,
148 const Schema& schema);
149
150ICEBERG_REST_EXPORT Result<std::vector<std::shared_ptr<FileScanTask>>>
151FileScanTasksFromJson(const nlohmann::json& json,
152 const std::vector<std::shared_ptr<DataFile>>& delete_files,
153 const std::unordered_map<int32_t, std::shared_ptr<PartitionSpec>>&
154 partition_spec_by_id,
155 const Schema& schema);
156
157} // namespace iceberg::rest