You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Prad Nelluru (Jira)" <ji...@apache.org> on 2021/08/18 19:26:00 UTC

[jira] [Created] (AVRO-3188) Avro C++ library doesn't support union-type fields with default = null

Prad Nelluru created AVRO-3188:
----------------------------------

             Summary: Avro C++ library doesn't support 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


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)