使用反射编写POJO对实木复合地板的文件 [英] Write pojo's to parquet file using reflection

查看:185
本文介绍了使用反射编写POJO对实木复合地板的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI寻找API编写parquest与我的POJO。
我可以使用反射产生的Avro模式,然后使用AvroSchemaConverter创建镶木架构。
另外,我无法找到一个方法来向的POJO GenericRecords(Avro的)转换成别的我可能已经能够使用AvroParquetWriter到的POJO写出来到实木复合地板的文件。
有什么建议?

HI Looking for APIs to write parquest with Pojos that I have. I was able to generate avro schema using reflection and then create parquet schema using AvroSchemaConverter. Also i am not able to find a way to convert Pojos to GenericRecords (avro) else I could have been able to use AvroParquetWriter to write out the Pojos into parquet files. Any suggestions ?

推荐答案

如果你想通过你的Avro有两种选择:

If you want to go through avro you have two options:

1)让Avro的生成你的POJO(参见教程这里 )。所产生的POJO延伸SpecificRecord然后可以用AvroParquetWriter使用。

1) Let avro generate your pojos (see the tutorial here). The generated pojos extend SpecificRecord which can then be used with AvroParquetWriter.

2)收件从POJO到GenericRecord自己的转换。您可以手动做到这一点还是更通用的解决方案是使用反射。然而,我遇到了这种方法的困难,当我试图读取数据。根据提供的模式的Avro发现POJO类路径中,并试图实例化一个SpecificRecord而不是GenericRecord。因为这个原因我去选1。

2) Write the conversion from your pojo to GenericRecord yourself. You can do this either manually or a more generic solution would be to use reflection. However, I encountered difficulties with this approach when I tried to read the data. Based on the supplied schema avro found the pojo in the classpath and tried to instantiate a SpecificRecord instead of GenericRecord. Because of this reason I went with option 1.

实木复合地板还支持现在直接写入POJO。 这里是实木复合地板的GitHub页面上的拉请求。不过,我认为这不是一个正式发布的一部分呢。换句话说,我没有发现这个行家code。

Parquet also supports now writing pojo directly. Here is the pull request on parquet github page. However, I think this is not part of an official release yet. In another words, I did not find this code in maven.

这篇关于使用反射编写POJO对实木复合地板的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆