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

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

问题描述

我对猪知之甚少.我有 protobuf 格式的数据文件.我需要将此文件加载到猪脚本中.我需要编写一个 LoadFunc UDF 来加载它.说函数是 Protobufloader().

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().

我的 PIG 脚本是

my PIG script would be

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

我只想知道如何获取文件输入流.一旦我掌握了文件输入流,我就可以将数据从 protobuf 格式解析为 PIG 元组格式.

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:提前致谢

推荐答案

Twitter 的开源库大象鸟有很多这样的加载器:https://github.com/kevinweil/elephant-bird

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

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

You can use LzoProtobufB64LinePigLoader and 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.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.

但是,他们假设您将数据写入序列化的 protobuffer 并由 lzo 压缩.

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

他们也有相应的作者,在包 com.twitter.elephantbird.pig.store 中.如果您的数据格式稍有不同,您可以根据您的自定义加载程序调整其代码.

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 格式文件加载到 pig 脚本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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