pig:用实际的键名和值创建json文件

31moq8wy  于 2021-06-21  发布在  Pig
关注(0)|答案(1)|浏览(369)

我有一个Pig脚本使用 elephant-bird json加载程序。

data_input = LOAD '$DATA_INPUT' USING com.twitter.elephantbird.pig.load.JsonLoader() AS (json:map []);

x = FOREACH data_input GENERATE json#'user__id_str', json#'user__created_at', json#'user__notifications', json#'user__follow_request_sent', json#'user__friends_count', json#'user__name', json#'user__time_zone', json#'user__profile_background_color', json#'user__is_translation_enabled', json#'user__profile_link_color', json#'user__utc_offset', json#'user__profile_sidebar_border_color', json#'user__has_extended_profile', json#'user__profile_background_tile', json#'user__is_translator', json#'user__profile_text_color', json#'user__location', json#'user__profile_banner_url', json#'user__profile_use_background_image', json#'user__default_profile_image', json#'user__description', json#'user__profile_background_image_url_https', json#'user__profile_sidebar_fill_color', json#'user__followers_count', json#'user__profile_image_url', json#'user__geo_enabled', json#'user__entities__description__urls', json#'user__screen_name', json#'user__favourites_count', json#'user__url', json#'user__statuses_count', json#'user__default_profile', json#'user__lang', json#'user__protected', json#'user__listed_count', json#'user__profile_image_url_https', json#'user__contributors_enabled', json#'user__following', json#'user__verified';

STORE x INTO '$DATA_OUTPUT' USING JsonStorage();

我有正确的输出,但字段名是错误的。
我的输出有 val_n 字段名称本身的设置:

{"val_0":"40510796","val_1":"Sat May 16 18:03:53 +0000 2009","val_2":"false"......}

我想要这样的东西:

{"user__id_str":"40510796","user__created_at":"Sat May 16 18:03:53 +0000 2009","user__notifications":"false"...........}

我怎样才能得到列名呢?

bfhwhh0e

bfhwhh0e1#

您是否尝试在generate语句中提供别名:
x=foreach data#input生成json#“user#u id#u str”作为user#u id#u str,json#“user#u created#u at”作为user#u created#;

相关问题