Search code examples
shellunixavro

how to create a ".avsc" file from an input avro file?


how to create a ".avsc" file from avro header ?

Does the first line of content is a avsc file for that avro? Or does the avsc content should starts from : {"type":"record" upto "}avro?

I tried the above mentioned 2 steps but not able to generate expected avsc file?


Solution

  • There are different ways to do this. You can to use using avro-tools like this

    avro-tools -getschema youravrofile
    

    Or programatically like this

    DatumReader<GenericRecord> datumReader = new GenericDatumReader<>();
    DataFileReader<GenericRecord> dataFileReader = new DataFileReader<>(new File("yourfile.avro"), datumReader);
    Schema schema = dataFileReader.getSchema();
    System.out.println(schema); // this will print the schema for you