json - 在PIG的JsonLoader中定义架构

标签 json hadoop schema apache-pig

我尝试使用JsonLoader从JSON文件中使用Pig时输入数据集的架构。

数据格式为:

{
  'cat_a':'some_text',
  'cat_b':{(attribute_name):(attribute_value)}
}

我试图将架构描述为:
LOAD 'filename' USING JsonLoader('cat_a:chararray, cat_b:(attribute_name:chararray,attribute_value:int)');

我觉得我为cat_b描述的模式不正确。

有人可以帮忙吗?
提前致谢。

最佳答案

如果您的json是格式

{"recipe":"Tacos","ingredients":[{"name":"Beef"},{"name":"Lettuce"},{"name":"Cheese"}]}

将上面的json存储在test.json

运行以下命令
a = LOAD '/home/abhijit/Desktop/test.json' USING JsonLoader('recipe:chararray,ingredients: {(name:chararray)}');

dump a;

您将输出为
(Tacos,{(Beef),(Lettuce),(Cheese)},)

如果您的json像下面的格式
{"recipe":"Tacos","ingredients":[{"name":"Beef"},{"name":"Lettuce"},{"name":"Cheese"}],"inventor":{"name":"Alex","age":25}}

a = LOAD '/home/abhijit/Desktop/test.json' USING JsonLoader('recipe:chararray,ingredients: {(name:chararray)},inventor: (name:chararray, age:int)');


dump a;

输出将是
(Tacos,{(Beef),(Lettuce),(Cheese)},(Alex,25))

关于json - 在PIG的JsonLoader中定义架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36347051/

相关文章:

python - 解析嵌套的 JSON 数据

hadoop - 从 org.apache.hadoop.hive.ql.exec.DDLTask 创建配置单元表 : FAILED: Execution Error, 返回代码 1 时出错。元异常

hadoop - Apache pig -错误 6007 : Unable to check name

database - 在 postgresql 中同一数据库的模式之间有效地移动数据

json - java.lang.NoSuchFieldError : USE_DEFAULTS thrown while validating json schema through json schema validator

json - Perl 无法加载 SSLeay.dll,因为未安装 LWP::Protocol::https

arrays - 将 json 对象的字符串编码到 json 数组中

python - 如何使用 pandas 将 Excel 文件转换为 json?

hadoop - 在 Mesos 上运行 Impala

php - 如何查询特定 VARCHAR 字段的长度/值限制?