Babulal created CARBONDATA-2627:
-----------------------------------

             Summary: remove dependecy of tech.allegro.schema.json2avro
                 Key: CARBONDATA-2627
                 URL: https://issues.apache.org/jira/browse/CARBONDATA-2627
             Project: CarbonData
          Issue Type: Bug
            Reporter: Babulal


currently tech.allegro.schema.json2avro is used for json to avro converter but 
it is not formally supported by AVRO and may feature does not work in converter 
like byte data type. 

Below code can be used instead of 

 

def jsonToAvro( json:String, schemaStr:String) :GenericRecord= {
 var input :InputStream= null;
 var writer :DataFileWriter[GenericRecord] = null;
 var encoder :Encoder= null;
 var output :ByteArrayOutputStream= null;
 try {
 val schema = new org.apache.avro.Schema.Parser().parse(schemaStr);
 val reader = new GenericDatumReader[GenericRecord](schema);
 input = new ByteArrayInputStream(json.getBytes());
 output = new ByteArrayOutputStream();
 val din = new DataInputStream(input);
 writer = new DataFileWriter[GenericRecord](new 
GenericDatumWriter[GenericRecord]());
 writer.create(schema, output);
 val decoder = DecoderFactory.get().jsonDecoder(schema, din);
 var datum :GenericRecord=null;
 datum = reader.read(null, decoder);
 return datum;
 } finally {
 try {
 input.close();
 writer.close();
 } catch {
 case e:Exception => {
 e.printStackTrace()
 }

 }
 }
 }



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to