Created
June 13, 2012 18:24
-
-
Save andry1/2925651 to your computer and use it in GitHub Desktop.
avro-c code to dump out schema and records from avro datafile as json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <avro.h> | |
int main(int argc, char **argv) { | |
avro_file_reader_t reader; | |
avro_writer_t stdout_writer = avro_writer_file_fp(stdout, 0); | |
avro_schema_t schema; | |
avro_datum_t record; | |
char *json=NULL; | |
if(argc < 2) { | |
fprintf(stderr, "Please give me an avro file to use\n"); | |
exit(EXIT_FAILURE); | |
} | |
if(avro_file_reader(argv[1], &reader)) { | |
fprintf(stderr, "Unable to open avro file %s: %s\n", argv[1], avro_strerror()); | |
exit(EXIT_FAILURE); | |
} | |
schema = avro_file_reader_get_writer_schema(reader); | |
printf("*** Schema:\n"); | |
avro_schema_to_json(schema, stdout_writer); | |
printf("\n*** Records:\n"); | |
while(!avro_file_reader_read(reader, NULL, &record)) { | |
avro_datum_to_json(record, 0, &json); | |
puts(json); | |
free(json); | |
avro_datum_decref(record); | |
} | |
avro_schema_decref(schema); | |
avro_file_reader_close(reader); | |
printf("\n"); | |
exit(EXIT_SUCCESS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment