use of org.apache.parquet.tools.read.SimpleRecord in project parquet-mr by apache.
the class HeadCommand method execute.
@Override
public void execute(CommandLine options) throws Exception {
super.execute(options);
long num = DEFAULT;
if (options.hasOption('n')) {
num = Long.parseLong(options.getOptionValue('n'));
}
String[] args = options.getArgs();
String input = args[0];
ParquetReader<SimpleRecord> reader = null;
try {
PrintWriter writer = new PrintWriter(Main.out, true);
reader = ParquetReader.builder(new SimpleReadSupport(), new Path(input)).build();
for (SimpleRecord value = reader.read(); value != null && num-- > 0; value = reader.read()) {
value.prettyPrint(writer);
writer.println();
}
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception ex) {
}
}
}
}
use of org.apache.parquet.tools.read.SimpleRecord in project parquet-mr by apache.
the class CatCommand method execute.
@Override
public void execute(CommandLine options) throws Exception {
super.execute(options);
String[] args = options.getArgs();
String input = args[0];
ParquetReader<SimpleRecord> reader = null;
try {
PrintWriter writer = new PrintWriter(Main.out, true);
reader = ParquetReader.builder(new SimpleReadSupport(), new Path(input)).build();
ParquetMetadata metadata = ParquetFileReader.readFooter(new Configuration(), new Path(input));
JsonRecordFormatter.JsonGroupFormatter formatter = JsonRecordFormatter.fromSchema(metadata.getFileMetaData().getSchema());
for (SimpleRecord value = reader.read(); value != null; value = reader.read()) {
if (options.hasOption('j')) {
writer.write(formatter.formatRecord(value));
} else {
value.prettyPrint(writer);
}
writer.println();
}
} finally {
if (reader != null) {
try {
reader.close();
} catch (Exception ex) {
}
}
}
}
Aggregations