parquet java_Apache Parquet Java API的文档?

我写了一篇关于阅读镶木地板文件的博客文章(

http://www.jofre.de/?p=1459),并提出了以下解决方案,甚至能够读取INT96字段.

您需要以下maven依赖项:

org.apache.parquet

parquet-hadoop

1.9.0

org.apache.hadoop

hadoop-common

2.7.0

代码基本上是:

public class Main {

private static Path path = new Path("file:\\C:\\Users\\file.snappy.parquet");

private static void printGroup(Group g) {

int fieldCount = g.getType().getFieldCount();

for (int field = 0; field < fieldCount; field++) {

int valueCount = g.getFieldRepetitionCount(field);

Type fieldType = g.getType().getType(field);

String fieldName = fieldType.getName();

for (int index = 0; index < valueCount; index++) {

if (fieldType.isPrimitive()) {

System.out.println(fieldName + " " + g.getValueToString(field, index));

}

}

}

}

public static void main(String[] args) throws IllegalArgumentException {

Configuration conf = new Configuration();

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));

for (int i = 0; i < rows; i++) {

final Group g = recordReader.read();

printGroup(g);

// TODO Compare to System.out.println(g);

}

}

} finally {

r.close();

}

} catch (IOException e) {

System.out.println("Error reading parquet file.");

e.printStackTrace();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值