zhjwpku commented on code in PR #553:
URL: https://github.com/apache/iceberg-cpp/pull/553#discussion_r2763374482
##########
src/iceberg/expression/json_serde.cc:
##########
@@ -123,6 +129,41 @@ nlohmann::json ToJson(Expression::Operation op) {
return json;
}
+nlohmann::json ToJson(const NamedReference& ref) { return
std::string(ref.name()); }
+
+Result<std::shared_ptr<NamedReference>> NamedReferenceFromJson(
+ const nlohmann::json& json) {
+ if (!json.is_string()) [[unlikely]] {
+ return JsonParseError("Expected string for named reference");
+ }
+ ICEBERG_ASSIGN_OR_RAISE(auto ref,
NamedReference::Make(json.get<std::string>()));
+ return std::shared_ptr<NamedReference>(std::move(ref));
+}
+
+nlohmann::json ToJson(const UnboundTransform& transform) {
+ auto& mutable_transform = const_cast<UnboundTransform&>(transform);
+ nlohmann::json json;
+ json[kType] = kTransform;
+ json[kTransform] = transform.transform()->ToString();
+ json[kTerm] = std::string(mutable_transform.reference()->name());
+ return json;
+}
+
+Result<std::shared_ptr<UnboundTransform>> UnboundTransformFromJson(
+ const nlohmann::json& json) {
+ if (json.is_object() && json.contains(kType) && json[kType] == kTransform &&
Review Comment:
From the build error msg, it seems windows don't like `json[kType] ==
kTransform`, you might change this back.
##########
src/iceberg/expression/json_serde.cc:
##########
@@ -123,6 +129,41 @@ nlohmann::json ToJson(Expression::Operation op) {
return json;
}
+nlohmann::json ToJson(const NamedReference& ref) { return
std::string(ref.name()); }
+
+Result<std::shared_ptr<NamedReference>> NamedReferenceFromJson(
+ const nlohmann::json& json) {
+ if (!json.is_string()) [[unlikely]] {
+ return JsonParseError("Expected string for named reference");
+ }
+ ICEBERG_ASSIGN_OR_RAISE(auto ref,
NamedReference::Make(json.get<std::string>()));
+ return std::shared_ptr<NamedReference>(std::move(ref));
+}
+
+nlohmann::json ToJson(const UnboundTransform& transform) {
+ auto& mutable_transform = const_cast<UnboundTransform&>(transform);
+ nlohmann::json json;
+ json[kType] = kTransform;
+ json[kTransform] = transform.transform()->ToString();
+ json[kTerm] = std::string(mutable_transform.reference()->name());
Review Comment:
```suggestion
json[kTerm] = mutable_transform.reference()->name();
```
line 146 seems ok, so the same apply to line 148?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]