Loading protobuf format file into pig script using loadfunc pig UDF

雨燕双飞 提交于 2019-12-03 16:25:46

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!