[
https://issues.apache.org/jira/browse/AVRO-3547?focusedWorklogId=785012&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-785012
]
ASF GitHub Bot logged work on AVRO-3547:
----------------------------------------
Author: ASF GitHub Bot
Created on: 27/Jun/22 09:51
Start Date: 27/Jun/22 09:51
Worklog Time Spent: 10m
Work Description: 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);
```
Issue Time Tracking
-------------------
Worklog Id: (was: 785012)
Time Spent: 50m (was: 40m)
> support custom attribute at field level
> ---------------------------------------
>
> Key: AVRO-3547
> URL: https://issues.apache.org/jira/browse/AVRO-3547
> Project: Apache Avro
> Issue Type: Improvement
> Components: c++
> Reporter: Nilesh Yadav
> Priority: Major
> Labels: pull-request-available
> Time Spent: 50m
> Remaining Estimate: 0h
>
> Custom attributes are allowed at field level as per Avro specification :
> [https://avro.apache.org/docs/current/spec.html#schemas|https://www.google.com/url?q=https://avro.apache.org/docs/current/spec.html%23schemas&sa=D&source=buganizer&usg=AOvVaw3JfXMgFX6Eq0Fd0TjDzgb1]
>
> But Avro c++ implementation does not support custom attribute at field level.
> e.g. following schema cannot be parsed correctly due to presence of "sqlName"
> attribute.
> {
> 'doc': 'weather warning',
> 'name': 'weather',
> 'type': 'record',
> 'fields': [
> {
> 'name': 'station',
> 'type':'string',
> 'sqlName':'abc-@12'
> },
> {
> 'name': 'time',
> 'type':'long',
> 'sqlName': '用户名'
> }]
> }
> Update implementation to support custom attribute at field level.
--
This message was sent by Atlassian Jira
(v8.20.7#820007)