wgtmac commented on code in PR #553:
URL: https://github.com/apache/iceberg-cpp/pull/553#discussion_r2773102542


##########
src/iceberg/type_fwd.h:
##########
@@ -131,6 +131,9 @@ class Expression;
 class Literal;
 class Term;
 class UnboundPredicate;
+class NamedReference;

Review Comment:
   Let's sort them alphabetically.



##########
src/iceberg/test/expression_json_test.cc:
##########
@@ -63,4 +64,53 @@ TEST(ExpressionJsonTest, OperationTypeTests) {
   EXPECT_FALSE(IsUnaryOperation(Expression::Operation::kTrue));
 }
 
+TEST(ExpressionJsonTest, NameReferenceRoundTrip) {

Review Comment:
   Can we try to reuse `TestJsonConversion` to avoid boilerplate of round trip 
test like this? 
https://github.com/apache/iceberg-cpp/blob/b15ac656cb20788a2103a3321c45f6676958ba69/src/iceberg/test/json_serde_test.cc#L76-L84?
 We can use a simple for-loop or even parameterized test pattern so we don't 
need to repeat this when adding new expr serde later.



##########
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 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));

Review Comment:
   ```suggestion
     return NamedReference::Make(json.get<std::string>());
   ```



##########
src/iceberg/expression/json_serde.cc:
##########
@@ -123,6 +130,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()) {
+    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] = std::string(kTransform);

Review Comment:
   What is the error message in the failed windows ci? Can we figure it out how 
to fix this since other places are good with it?



##########
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 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] = std::string(kTransform);
+  json[kTransform] = transform.transform()->ToString();
+  json[kTerm] = mutable_transform.reference()->name();
+  return json;
+}
+
+Result<std::shared_ptr<UnboundTransform>> UnboundTransformFromJson(

Review Comment:
   Could you please call this in the `ExpressionFromJson` in this PR and verify 
it works in the test case? It is still unclear to me whether the checks below 
is worth because we should already know that `json` is an unbound transform and 
those checks are performed in the `ExpressionFromJson` already.



-- 
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]

Reply via email to