使用loadfunc pig UDF将protobuf格式文件加载到猪脚本中 [英] Loading protobuf format file into pig script using loadfunc pig UDF

查看:125
本文介绍了使用loadfunc pig UDF将protobuf格式文件加载到猪脚本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对猪的知识很少。我有protobuf格式的数据文件。我需要将这个文件加载到猪脚本中。我需要编写一个LoadFunc UDF来加载它。说功能是 Protobufloader()



我的PIG脚本是

  A = LOAD'abc_protobuf。 dat'使用Protobufloader()作为(姓名,电话号码,电子邮件); 

我想知道的是如何获取文件输入流。一旦我得到了文件输入流,我可以解析从protobuf格式到PIG元组格式的数据。

PS:提前致谢

解决方案

Twitter的开源库大象鸟有许多这样的装载者:
https://github.com/kevinweil/elephant-bird



您可以使用LzoProtobufB64LinePigLoader和LzoProtobufBlockPigLoader。
https:/ /github.com/kevinweil/elephant-bird/tree/master/src/java/com/twitter/elephantbird/pig/load



使用它,你只需要做:

  define ProtoLoader com.twitter.elephantbird.pig.load.LzoProtobufB64LineLoader('your.proto。班级名称'); 
a =使用ProtoLoader加载'/ your / file';
b = foreach生成
field1,field2;

加载后,它将自动转换为具有适当模式的猪元组。



然而,他们假设你将数据写入序列化的protobuffer中并由lzo压缩。

它们也有相应的编写器,包com .twitter.elephantbird.pig.store。
如果您的数据格式稍有不同,您可以将其代码调整到您的自定义加载程序。


I have very little knowledge of pig. I have protobuf format data file. I need to load this file into a pig script. I need to write a LoadFunc UDF to load it. say function is Protobufloader().

my PIG script would be

A = LOAD 'abc_protobuf.dat' USING Protobufloader() as (name, phonenumber, email);

All i wish to know is How do i get the file input stream. Once i get hold of file input stream, i can parse the data from protobuf format to PIG tuple format.

PS: thanks in advance

解决方案

Twitter's open source library elephant bird has many such loaders: https://github.com/kevinweil/elephant-bird

You can use LzoProtobufB64LinePigLoader and LzoProtobufBlockPigLoader. https://github.com/kevinweil/elephant-bird/tree/master/src/java/com/twitter/elephantbird/pig/load

To use it, you just need to do:

define ProtoLoader com.twitter.elephantbird.pig.load.LzoProtobufB64LineLoader('your.proto.class.name');
a = load '/your/file' using ProtoLoader;
b = foreach a generate
  field1, field2;

After loading, it will be automatically translated to pig tuples with proper schema.

However, they assume you write your data in serialized protobuffer and compressed by lzo.

They have corresponding writers as well, in package com.twitter.elephantbird.pig.store. If your data format is a bit different, you can adapt their code to your custom loader.

这篇关于使用loadfunc pig UDF将protobuf格式文件加载到猪脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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