Skip to content

Commit 2c81135

Browse files
author
Innocent
committed
feat: add json serde for expressions
1 parent 6670d09 commit 2c81135

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/iceberg/expression/json_serde_internal.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#pragma once
2121

22+
2223
#include <nlohmann/json_fwd.hpp>
2324

2425
#include "iceberg/expression/expression.h"
@@ -134,6 +135,63 @@ ICEBERG_EXPORT Result<std::unique_ptr<UnboundPredicate>> UnboundPredicateFromJso
134135
/// \return A JSON value representing the term, or an error
135136
ICEBERG_EXPORT Result<nlohmann::json> ToJson(const Term& term);
136137

138+
/// \brief Deserializes a JSON object into a NamedReference.
139+
///
140+
/// \param json A JSON object representing a named reference
141+
/// \return A shared pointer to the deserialized NamedReference or an error
142+
ICEBERG_EXPORT Result<std::unique_ptr<NamedReference>> NamedReferenceFromJson(
143+
const nlohmann::json& json);
144+
145+
/// \brief Serializes a NamedReference into its JSON representation.
146+
///
147+
/// \param ref The named reference to serialize
148+
/// \return A JSON object representing the named reference
149+
ICEBERG_EXPORT nlohmann::json ToJson(const NamedReference& ref);
150+
151+
/// \brief Serializes an UnboundTransform into its JSON representation.
152+
///
153+
/// \param transform The unbound transform to serialize
154+
/// \return A JSON object representing the unbound transform
155+
ICEBERG_EXPORT nlohmann::json ToJson(const UnboundTransform& transform);
156+
157+
/// \brief Deserializes a JSON object into an UnboundTransform.
158+
///
159+
/// \param json A JSON object representing an unbound transform
160+
/// \return A shared pointer to the deserialized UnboundTransform or an error
161+
ICEBERG_EXPORT Result<std::unique_ptr<UnboundTransform>> UnboundTransformFromJson(
162+
const nlohmann::json& json);
163+
164+
/// \brief Serializes a Literal into its JSON representation.
165+
///
166+
/// \param literal The literal to serialize
167+
/// \return A JSON value representing the literal
168+
ICEBERG_EXPORT nlohmann::json ToJson(const Literal& literal);
169+
170+
/// \brief Deserializes a JSON value into a Literal.
171+
///
172+
/// \param json A JSON value representing a literal
173+
/// \return The deserialized Literal or an error
174+
ICEBERG_EXPORT Result<Literal> LiteralFromJson(const nlohmann::json& json);
175+
176+
/// \brief Serializes an UnboundPredicate into its JSON representation.
177+
///
178+
/// \param pred The unbound predicate to serialize
179+
/// \return A JSON object representing the predicate
180+
ICEBERG_EXPORT nlohmann::json ToJson(const UnboundPredicate& pred);
181+
182+
/// \brief Deserializes a JSON object into an UnboundPredicate.
183+
///
184+
/// \param json A JSON object representing an unbound predicate
185+
/// \return A shared pointer to the deserialized UnboundPredicate or an error
186+
ICEBERG_EXPORT Result<std::unique_ptr<UnboundPredicate>> UnboundPredicateFromJson(
187+
const nlohmann::json& json);
188+
189+
/// \brief Serializes a Term into its JSON representation.
190+
///
191+
/// \param term The term to serialize (NamedReference or UnboundTransform)
192+
/// \return A JSON value representing the term
193+
ICEBERG_EXPORT nlohmann::json TermToJson(const Term& term);
194+
137195
/// Check if an operation is a unary predicate
138196
ICEBERG_EXPORT bool IsUnaryOperation(Expression::Operation op);
139197

src/iceberg/test/expression_json_test.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <nlohmann/json.hpp>
2727

2828
#include "iceberg/expression/expression.h"
29-
#include "iceberg/expression/expressions.h"
3029
#include "iceberg/expression/json_serde_internal.h"
3130
#include "iceberg/expression/literal.h"
3231
#include "iceberg/expression/predicate.h"

0 commit comments

Comments
 (0)