jhump commented on code in PR #3266:
URL: https://github.com/apache/avro/pull/3266#discussion_r1928879126
##########
lang/c++/include/avro/CustomAttributes.hh:
##########
@@ -19,27 +19,76 @@
#ifndef avro_CustomAttributes_hh__
#define avro_CustomAttributes_hh__
-#include "Config.hh"
#include <iostream>
#include <map>
#include <optional>
#include <string>
+#include "Config.hh"
+
namespace avro {
// CustomAttributes class stores avro custom attributes.
// Each attribute is represented by a unique name and value.
// User is supposed to create CustomAttributes object and then add it to
Schema.
class AVRO_DECL CustomAttributes {
+
public:
- // Retrieves the custom attribute json entity for that attributeName,
returns an
- // null if the attribute doesn't exist.
+ enum ValueMode {
+ // When a CustomAttributes is created using this mode, all values are
strings.
+ // The value should not be quoted, but any interior quotes and special
+ // characters (such as newlines) must be escaped.
+ string,
+ // When a CustomAttributes is created using this mode, all values are
JSON
+ // values. String values must be quoted and escaped.
+ json
+ };
Review Comment:
The value mode simply determines how this `CustomAttributes` interprets
values provided via `setAttribute` and in turn how they are returned from
`getAttributes` and the `attributes()` map accessor. It's an entirely runtime
property.
We don't need to know the value mode used to serialize a JSON schema. The
JSON string is known to be valid JSON at this point., since the compiler will
have already parsed it into an entity. It may have only string custom
attributes or it might not. If it was serialized using "json" value mode, we
can still process it with "string" value mode, as long as all custom attributes
are strings. And we can always process any input in "json" value mode (the new
non-deprecated mode).
The current logic (prior to this PR) _cannot_ handle custom attributes
unless they are strings. While this library cannot currently _generate_ schemas
that have non-string custom attributes (at least as of v1.11.2), all other Avro
libraries _can_ generate that sort of file. That's the bug we're trying to fix
in this PR: this library currently throws an exception if an Avro file has a
schema with non-string custom attributes.
--
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]