Reading parquet file is working but getting indented format instead of a desired JSON output format. Any ideas? I was thinking that I may need to change GroupRecordConverter but wasn't able to find much documentation. If can point me to that, would also be helpful. Thanks very much for the help.
long num = numLines;
try {
ParquetMetadata readFooter = ParquetFileReader.readFooter(conf, path, ParquetMetadataConverter.NO_FILTER);
MessageType schema = readFooter.getFileMetaData().getSchema();
ParquetFileReader r = new ParquetFileReader(conf,path,readFooter);
PageReadStore pages = null;
try{
while(null != (pages = r.readNextRowGroup())) {
final long rows = pages.getRowCount();
System.out.println("Number of rows: " + rows);
final MessageColumnIO columnIO = new ColumnIOFactory().getColumnIO(schema);
final RecordReader recordReader = columnIO.getRecordReader(pages, new GroupRecordConverter(schema));
String sTemp = "";
for(int i=0; i<rows && num-->0; i++) {
System.out.println(recordReader.read().toString())
}
}
}
}
Current indented output:
data1: value1
data2: value2
models
map
key: data3
value
array: value3
map
key: data4
value
array: value4
data5: value5
...
Desired JSON output:
"data1": "value1",
"data2": "value2",
"models": {
"data3": [
"value3"
],
"data4": [
"value4"
]
},
"data5": "value5"
...
The java parquet lib's cat command tool code, might perhaps serve you as an example... containing the line:
org.apache.parquet.tools.json.JsonRecordFormatter.JsonGroupFormatter formatter = JsonRecordFormatter.fromSchema(metadata.getFileMetaData().getSchema());
See here for full source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With