You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/06/27 09:51:13 UTC

[GitHub] [avro] martin-g commented on a diff in pull request #1736: AVRO-3547: Add support for custom attributes in Avro Schema

martin-g commented on code in PR #1736:
URL: https://github.com/apache/avro/pull/1736#discussion_r907190772


##########
lang/c++/impl/CustomFields.cc:
##########
@@ -0,0 +1,55 @@
+
+/**
+ * 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 "CustomFields.hh"
+#include <boost/make_shared.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include "Exception.hh"

Review Comment:
   ```suggestion
   #include "Exception.hh"
   
   ```



##########
lang/c++/impl/CustomFields.cc:
##########
@@ -0,0 +1,55 @@
+
+/**
+ * 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 "CustomFields.hh"
+#include <boost/make_shared.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include "Exception.hh"
+namespace avro {

Review Comment:
   ```suggestion
   namespace avro {
   
   ```



##########
lang/c++/impl/CustomFields.cc:
##########
@@ -0,0 +1,55 @@
+
+/**
+ * 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 "CustomFields.hh"
+#include <boost/make_shared.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include "Exception.hh"
+namespace avro {
+using json::Entity;
+Entity CustomFields::getField(const std::string &fieldName) const {
+    std::map<std::string, Entity>::const_iterator iter =
+        fields_.find(fieldName);
+    if (iter == fields_.end()) {
+      return Entity();
+    }
+    return iter->second;
+}
+void CustomFields::addField(const std::string& fieldName,
+                            const std::string& fieldValue) {
+  addField(fieldName,
+           json::Entity(boost::make_shared<std::string>(fieldValue)));
+}

Review Comment:
   ```suggestion
   }
   
   ```



##########
lang/c++/impl/CustomFields.cc:
##########
@@ -0,0 +1,55 @@
+
+/**
+ * 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 "CustomFields.hh"
+#include <boost/make_shared.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include "Exception.hh"
+namespace avro {
+using json::Entity;

Review Comment:
   ```suggestion
   using json::Entity;
   
   ```



##########
lang/c++/impl/CustomFields.cc:
##########
@@ -0,0 +1,55 @@
+
+/**
+ * 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 "CustomFields.hh"
+#include <boost/make_shared.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include "Exception.hh"
+namespace avro {
+using json::Entity;
+Entity CustomFields::getField(const std::string &fieldName) const {
+    std::map<std::string, Entity>::const_iterator iter =
+        fields_.find(fieldName);
+    if (iter == fields_.end()) {
+      return Entity();
+    }
+    return iter->second;
+}
+void CustomFields::addField(const std::string& fieldName,
+                            const std::string& fieldValue) {
+  addField(fieldName,
+           json::Entity(boost::make_shared<std::string>(fieldValue)));
+}
+void CustomFields::addField(const std::string& fieldName,
+                            const Entity& fieldValue) {
+  auto iter_and_find =
+      fields_.insert(std::pair<std::string, Entity>(fieldName, fieldValue));
+  if (!iter_and_find.second) {
+    throw Exception(fieldName + " already exists and cannot be added");
+  }
+}

Review Comment:
   ```suggestion
   }
   
   ```



##########
lang/c++/impl/CustomFields.cc:
##########
@@ -0,0 +1,55 @@
+
+/**
+ * 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 "CustomFields.hh"
+#include <boost/make_shared.hpp>
+#include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include <map>
+#include "Exception.hh"
+namespace avro {
+using json::Entity;
+Entity CustomFields::getField(const std::string &fieldName) const {
+    std::map<std::string, Entity>::const_iterator iter =
+        fields_.find(fieldName);
+    if (iter == fields_.end()) {
+      return Entity();
+    }
+    return iter->second;
+}

Review Comment:
   ```suggestion
   }
   
   ```



##########
lang/c++/impl/NodeImpl.cc:
##########
@@ -274,6 +286,9 @@ void NodeRecord::printJson(std::ostream &os, size_t depth) const {
                                                            depth);
             }
         }
+        if(customAttributes_.size() == fields) {
+          printCustomFields(customAttributes_.get(i), depth, os);
+        }
         os << '\n';

Review Comment:
   Should this use `endl` instead ?



##########
lang/c++/impl/NodeImpl.cc:
##########
@@ -83,6 +83,17 @@ std::ostream &operator<<(std::ostream &os, indent x) {
     return os;
 }
 
+void printCustomFields(const CustomFields& customFields, int depth,
+                       std::ostream &os) {
+    std::map<std::string, json::Entity>::const_iterator iter =
+        customFields.fields().begin();
+    while (iter != customFields.fields().end()) {
+      os << ",\n" << indent(depth);

Review Comment:
   ```suggestion
         os << "," << endl  << indent(depth);
   ```



-- 
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: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org