You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi @SanderElias. By default, forValue only supports the standard Avro types. You can extend type inference via the valueHook option, often in combination with a logical type.
For example, to infer Dates:
/** Minimal date logical type. */classDateTypeextendsavro.types.LogicalType{_fromValue(val){returnnewDate(val);}_toValue(date){returndateinstanceofDate ? +date : undefined;}}// Type where all `Date` fields are represented as `DateType`s.consttype=avro.Type.forValue(data,{valueHook: (val,opts)=>{if(valinstanceofDate){returnnewDateType({type: 'long',logicalType: 'timestamp-millis'},opts);}// Optionally add more logic here... Returning `undefined` falls back to// default inference.},});console.log(type.clone(data));// { city: 'Cambridge', date: 2020-10-19T15:52:29.621Z }
See this sample:
I would expect that dates would be handled properly. Or did I misunderstood something?
I'm willing to create a PR for this if there is an interest.
The text was updated successfully, but these errors were encountered: