forked from linkedin/goavro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
record field default values for primitive types casted linkedin#139
Because Avro schemas are represented in JSON, record field default values were represented in JSON. JSON has only a single data type for numbers, which is floating point, and the Go standard library decodes the JSON default value into a Go "float64" value, and was storing it in the record field's default value. Similarly, all record field default values which have the Avro "bytes" data type were being stored as Go "string" data type values. And so forth for other default values. Later on when decoding values that were encoded using that schema, `goavro` would return the Go data type for that value stored when compiling the schema. Even when the data type for a record field specified an Avro "int", `goavro` was returning a Go "float64" value. This update addresses all primitive data types, casting them to the expected Go data type corresponding to the Avro data type specified by the schema. Later on when decoding such values, the values will be returned to the caller having the proper corresponding Go data type. Further work remains to address complex Avro data types, such as for records, enumerations, arrays, maps, and fixed. Additionally, some edge cases remain regarding Avro union values. If a record field data type is an Avro union that can store either an Avro "int" or an Avro "float", for example, `goavro` is still storing the default value as a Go "float64" because all numbers are decoded from the JSON schema as Go "float64" values. This is not ideal, and remains an open issue. As mentioned by issue linkedin#139, the same handling for logical types also remains additional work. Furthermore, as issue linkedin#124 refers, it would be nice to be able to provide the same handling for default values that are themselves records or arrays.
- Loading branch information
Karrick S. McDermott
committed
Jul 12, 2019
1 parent
e4677c7
commit 1589033
Showing
2 changed files
with
70 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters