linkedin / linkedin/goavro

Question about default value's representation for fixed, decimal, etc

Open
#139 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
1.1k
Forks
232
PR merge metrics
No merged PRs in 30d

Description

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:
1. Do we accept several native representation?
2. 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?
3. 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read record.go around the default-value validation and compare binaryFromNative with NativeFromTextual. Then inspect fixed.go's string handling and the linked Avro schema behavior for decimal and fixed defaults. Done means agreeing on one consistent default-value representation rule and identifying the corresponding validation behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.