evindj commented on code in PR #532:
URL: https://github.com/apache/iceberg-cpp/pull/532#discussion_r2734762597


##########
src/iceberg/expression/json_serde.cc:
##########
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <format>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <nlohmann/json.hpp>
+
+#include "iceberg/expression/expressions.h"
+#include "iceberg/expression/json_serde_internal.h"
+#include "iceberg/expression/literal.h"
+#include "iceberg/util/json_util_internal.h"
+#include "iceberg/util/macros.h"
+
+namespace iceberg {
+
+Result<std::shared_ptr<Expression>> ExpressionFromJson(const nlohmann::json& 
json) {
+  // Handle boolean
+  if (json.is_boolean()) {
+    return json.get<bool>() ? 
std::dynamic_pointer_cast<Expression>(True::Instance())
+                            : 
std::dynamic_pointer_cast<Expression>(False::Instance());
+  }
+  return JsonParseError("Only boolean are currently supported");
+}
+
+nlohmann::json ToJson(const Expression& expr) {
+  switch (expr.op()) {
+    case Expression::Operation::kTrue:
+      return true;
+
+    case Expression::Operation::kFalse:
+      return false;
+    default:
+      throw std::logic_error("Only booleans are currently supported");

Review Comment:
   > My concern is large refactoring afterwards if we don't have a good design 
beforehand
   
   You are correct, I will cleanup my notes and shared as design. but I don't 
expect too much refactoring.



##########
src/iceberg/expression/json_serde_internal.h:
##########
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <nlohmann/json_fwd.hpp>
+
+#include "iceberg/expression/expression.h"
+#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
+
+/// \file iceberg/expression/json_serde_internal.h
+/// JSON serialization and deserialization for expressions.
+
+namespace iceberg {
+
+template <typename Model>
+Result<Model> FromJson(const nlohmann::json& json);
+
+#define ICEBERG_DECLARE_JSON_SERDE(Model)                                      
       \

Review Comment:
   Yeah, as I am looking at other literals, predicates, and terms it does seem 
like it would be better not to have the macro.



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