goavro
goavro copied to clipboard
Question about default value's representation for fixed, decimal, etc
In record.go, the default value given in the schema is validated using binaryFromNative. https://github.com/linkedin/goavro/blob/master/record.go#L77
Should the validation of the default value be made against the textual representation instead of the native representation?
Checking the default value against the native representation has some issues. For example, several types have some native go representation, (eg. decimal's native representation is *big.Rat), you cannot set its default value in the json avro schema.
Interestingly, fixed has its native representation as []byte, but its default value can be given (as the spec allows) as a string. It seems that some workaround in fixed's binaryFromNative was done here https://github.com/linkedin/goavro/blob/master/fixed.go#L41-L42 to accept a string as also native representation.
My questions are:
- Do we accept several native representation?
- If the answer to 1 is yes, should we use this rule to also add a string representation handling in their binaryFromNative to accept those default values represented as string?
- If the answer to 1 is no, should we use NativeFromTextual to validate the default value and have a single native representation?
Or choose there some other consistent rules. In any case, I think the current code is inconsistent in the default value handling.