wgtmac commented on code in PR #3332:
URL: https://github.com/apache/avro/pull/3332#discussion_r1993176004


##########
lang/c++/test/SchemaTests.cc:
##########
@@ -658,6 +659,158 @@ static void testMalformedLogicalTypes(const char *schema) 
{
     BOOST_CHECK(datum.logicalType().type() == LogicalType::NONE);
 }
 
+static void testParseCustomAttributes() {
+    const std::string schema = R"({
+        "type": "record",
+        "name": "my_record",
+        "fields": [
+            { "name": "long_field",
+              "type": ["null", "long"],
+              "field-id": 1 },
+            { "name": "array_field",
+              "type": { "type": "array", "items": "int", "element-id": 3 },
+              "field-id": 2,
+              "extra": "1", "extra2": "2" },
+            { "name": "map_field",
+              "type": { "type": "map", "values": "int", "key-id": 5, 
"value-id": 6 },
+              "field-id": 4,
+              "extra": "foo" },
+            { "name": "timestamp_field",
+              "type": "long", "logicalType": "timestamp-micros", 
"adjust-to-utc": true,
+              "field-id": 10,
+              "extra": "bar" }
+        ]
+    })";
+
+    ValidSchema compiledSchema = compileJsonSchemaFromString(schema);
+    const NodePtr &root = compiledSchema.root();
+    BOOST_CHECK_EQUAL(root->customAttributes(), 4);
+
+    // long_field
+    {
+        auto customAttributes = root->customAttributesAt(0);
+        BOOST_CHECK_EQUAL(customAttributes.getAttribute("field-id").value(), 
"1");
+    }
+
+    // array_field
+    {
+        auto customAttributes = root->customAttributesAt(1);
+        BOOST_CHECK_EQUAL(customAttributes.getAttribute("extra").value(), "1");

Review Comment:
   This API aligns with its friends like `names` and `leaves` because they are 
for sub-fields: 
https://github.com/apache/avro/blob/main/lang/c%2B%2B/include/avro/Node.hh#L143-L160



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

Reply via email to