我有一个要求,我们需要自定义使用 avrostorage 在 pig 中加载文件的方式:
例如,我有一个具有以下架构的 avro 文件:
{"namespace": "avroColorCount",
"type": "record",
"name": "User2",
"fields": [
{"name": "name", "type": "string"},
{"name": "content", "type" : "bytes" }
]
}
现在如果我使用下面的命令它工作正常:
x = load 'sample.avro' USING AvroStorage() AS (name: chararray, content: bytearray);
但是,如果我只想加载“内容”(第二列),我该怎么做呢?
如果我给,
x = load 'sample.avro' USING AvroStorage() AS (content: bytearray);
它给我错误:
ERROR 1031: Incompatable schema: left is "content:bytearray", right is "name: chararray, content: bytearray"
我知道这可以通过 FILTER 完成。
但我们的要求是在一个步骤中单独获取第二列。
这可能吗?
提前致谢...
最佳答案
下面的代码解决了..
x = LOAD 'sample.avro' USING AvroStorage('{"type":"record","name":"User2","fields":[{"name":"content","type":"bytearray"}]}');
关于hadoop - pig-avro : how to customize the way, avrostorage 加载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22325730/