wgtmac commented on code in PR #3332:
URL: https://github.com/apache/avro/pull/3332#discussion_r1993707433
##########
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:
I agree that it is weird and this is different to the Java library where the
custom attributes are directly accessed via the Node. However, the current
implementation of `Node::addCustomAttributesForField()` already assigns one
CustomAttribute to each leaf node. So we can only access the CustomAttribute of
leaf node via Record/Map/Array's `customAttributesAt(i)` without breaking
anything.
--
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]