java - How can I store an optional numerical value in an avro schema -


i'm writing code stores java resultset avro data/schema. i'm pretty new avro.

the way i'm doing take resultset , query columnmetadata generate avro schema. here convert oracle types avro types. example, turn varchar string , number long.

then take data resultset , write out tsv file have human-readable version of output diagnostic purposes. iterate on what's in tsv file , write out avro file using datumwriter/datafilewriter.

the problem i'm having of (oracle) tables i'm querying have nullable number columns. in cases column null, "" when read tsv file. if try write "" long field, datafilewriter chokes exception:

exception in thread "main" org.apache.avro.file.datafilewriter$appendwriteexception: java.lang.classcastexception: java.lang.string cannot cast java.lang.long 

since message here indicates datafilewriter using java.lang.long (as opposed primitive long) assumed detect cases field long , value "" , set value explicitly null.

when try serialize this, following exception:

exception in thread "main" org.apache.avro.file.datafilewriter$appendwriteexception: java.lang.nullpointerexception: null of long in field column_name of namespace.name 

now exception refers primitive long instead of java.lang.long.

what missing here? possible have avro field optional long?

i've considered not writing tsv file , instead writing avro file directly see in resultset, have hunch i'm going have same problem since datafilewriter doesn't seem "" or null values long fields. suppose make string field, i'd prefer retain column type sorting , whatnot work downstream.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -