[
https://issues.apache.org/jira/browse/AVRO-3188?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Prad Nelluru updated AVRO-3188:
-------------------------------
Description:
We have a schema with a record with a union-type field with the "null" type
being the first type and with a default value of `null`. When given a JSON
datum without that field, decoding fails. I'd expect decoding to fail with that
field being given a value of `null`. Repro unit test to place in CodecTests.cc.
{{static void optionalFieldNotSupported() {
const char *text = "{\"f1\": true }";
InputStreamPtr in =
memoryInputStream(reinterpret_cast<const uint8_t *>(text),
::strlen(text));
const char *schemaStr = "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
"{\"name\":\"f1\", \"type\":\"boolean\"},"
"{\"name\":\"f2\", \"type\":[\"null\", \"long\"],
\"default\": null}"
"]}";
ValidSchema schema = parsing::makeValidSchema(schemaStr);
DecoderPtr d = jsonDecoder(schema);
{
d->init(*in);
avro::GenericDatum datum(schema);
avro::decode(*d, datum);
}
}}}
was:
We have a schema with a record with a union-type field with the "null" type
being the first type and with a default value of `null`. When given a JSON
datum without that field, decoding fails. I'd expect decoding to fail with that
field being given a value of `null`. Repro unit test to place in CodecTests.cc.
static void optionalFieldNotSupported() {
const char *text = "{\"f1\": true }";
InputStreamPtr in =
memoryInputStream(reinterpret_cast<const uint8_t *>(text),
::strlen(text));
const char *schemaStr = "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
"{\"name\":\"f1\", \"type\":\"boolean\"},"
"{\"name\":\"f2\", \"type\":[\"null\", \"long\"],
\"default\": null}"
"]}";
ValidSchema schema = parsing::makeValidSchema(schemaStr);
DecoderPtr d = jsonDecoder(schema);
{
d->init(*in);
avro::GenericDatum datum(schema);
avro::decode(*d, datum);
}
}
> Avro C++ library doesn't accept JSON without a field for union-type fields
> with default = null
> ----------------------------------------------------------------------------------------------
>
> Key: AVRO-3188
> URL: https://issues.apache.org/jira/browse/AVRO-3188
> Project: Apache Avro
> Issue Type: Bug
> Components: c++
> Affects Versions: 1.10.2
> Environment: Debian
> Reporter: Prad Nelluru
> Priority: Minor
>
> We have a schema with a record with a union-type field with the "null" type
> being the first type and with a default value of `null`. When given a JSON
> datum without that field, decoding fails. I'd expect decoding to fail with
> that field being given a value of `null`. Repro unit test to place in
> CodecTests.cc.
> {{static void optionalFieldNotSupported() {
> const char *text = "{\"f1\": true }";
> InputStreamPtr in =
> memoryInputStream(reinterpret_cast<const uint8_t *>(text),
> ::strlen(text));
> const char *schemaStr = "{\"type\":\"record\",\"name\":\"r\",\"fields\":["
> "{\"name\":\"f1\", \"type\":\"boolean\"},"
> "{\"name\":\"f2\", \"type\":[\"null\", \"long\"],
> \"default\": null}"
> "]}";
> ValidSchema schema = parsing::makeValidSchema(schemaStr);
> DecoderPtr d = jsonDecoder(schema);
> {
> d->init(*in);
> avro::GenericDatum datum(schema);
> avro::decode(*d, datum);
> }
> }}}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)