使用 Pig 中的elephantbird 进行 Json 解析

2024-03-07

我无法在 Pig 中解析以下数据。这是 Twitter API 在获取某个用户的所有推文后返回的内容。

源数据:(我删除了一些数字,以免无意中侵犯任何人的隐私)

[{"created_at":"Sat Nov 01 23:15:45 +0000 2014","id":5286804225,"id_str":"5286864225","text":"@Beace_ your nan makes me laugh with some of the things she comes out with","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":52812992878592,"in_reply_to_status_id_str":"522","in_reply_to_user_id":398098,"in_reply_to_user_id_str":"3","in_reply_to_screen_name":"Be_","user":{"id":425,"id_str":"42433395","name":"SAINS","screen_name":"sa3","location":"Lincoln","profile_location":null,"description":"","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":92,"friends_count":526,"listed_count":0,"created_at":"Mon May 25 16:18:05 +0000 2009","favourites_count":6,"utc_offset":0,"time_zone":"London","geo_enabled":true,"verified":false,"statuses_count":19,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"EDECE9","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/52016\/DGDCj67z_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/526\/DGDCj67z_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/424395\/13743515","profile_link_color":"088253","profile_sidebar_border_color":"D3D2CF","profile_sidebar_fill_color":"E3E2DE","profile_text_color":"634047","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":1,"entities":{"hashtags":[],"symbols":[],"user_mentions":[{"screen_name":"e_","name":"\u2601\ufe0f effy","id":3998,"id_str":"398","indices":[0,15]}],"urls":[]},"favorited":false,"retweeted":false,"lang":"en"}, {another one goes here ....} ]

我已经尝试了很多东西,但这是我当前的代码:

REGISTER 'hdfs:///user/cloudera/elephant-bird-pig-4.1.jar';
REGISTER 'hdfs:///user/cloudera/elephant-bird-core-4.1.jar';
REGISTER 'hdfs:///user/cloudera/elephant-bird-hadoop-compat-4.1.jar';

--Load Json
loadJson =  LOAD '/user/cloudera/tweetwall' USING com.twitter.elephantbird.pig.load.JsonLoader() AS (json:map []);

describe loadJson;

--dump loadJson;

--PARSING JSON
--txt
--a = FOREACH loadJson GENERATE json#'text' AS ParsedInput;

dump loadJson;

c = FOREACH loadJson GENERATE flatten(json#'text') as (m:map[]);

如果我没有收到错误,我只是得不到任何返回(如脚本运行完成后返回 0 个字节)

例如:

success!

Input(s):
Successfully read 0 records (532459 bytes) from: "/user/cloudera/tweetwall"

Output(s):
Successfully stored 0 records in: "hdfs://quickstart.cloudera:8020/tmp/temp-988640258/tmp-846532109"

Counters:
Total records written : 0
Total bytes written : 0
Spillable Memory Manager spill count : 0
Total bags proactively spilled: 0
Total records proactively spilled: 0

1. You need to give the root name for your input json
    I added "tweets" as your root name
    {"tweets":[<your input>]}

2. This is nested json, so you need to load your json file with 'nested' option in the loader

输入.json

{"tweets":[{"created_at":"Sat Nov 01 23:15:45 +0000 2014","id":5286804225,"id_str":"5286864225","text":"@Beace_ your nan makes me laugh with some of the things she comes out with","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":52812992878592,"in_reply_to_status_id_str":"522","in_reply_to_user_id":398098,"in_reply_to_user_id_str":"3","in_reply_to_screen_name":"Be_","user":{"id":425,"id_str":"42433395","name":"SAINS","screen_name":"sa3","location":"Lincoln","profile_location":null,"description":"","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":92,"friends_count":526,"listed_count":0,"created_at":"Mon May 25 16:18:05 +0000 2009","favourites_count":6,"utc_offset":0,"time_zone":"London","geo_enabled":true,"verified":false,"statuses_count":19,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"EDECE9","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme3\/bg.gif","profile_background_tile":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/52016\/DGDCj67z_normal.jpeg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/526\/DGDCj67z_normal.jpeg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/424395\/13743515","profile_link_color":"088253","profile_sidebar_border_color":"D3D2CF","profile_sidebar_fill_color":"E3E2DE","profile_text_color":"634047","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":0,"favorite_count":1,"entities":{"hashtags":[],"symbols":[],"user_mentions":[{"screen_name":"e_","name":"\u2601\ufe0f effy","id":3998,"id_str":"398","indices":[0,15]}],"urls":[]},"favorited":false,"retweeted":false,"lang":"en"}]}

Pig脚本:

REGISTER '/tmp/json-simple-1.1.jar';
REGISTER '/tmp/elephant-bird-hadoop-compat-4.1.jar';
REGISTER '/tmp/elephant-bird-pig-4.1.jar';

loadJson = LOAD 'input.json' USING com.twitter.elephantbird.pig.load.JsonLoader('-nestedLoad') AS (json:map []);
B = FOREACH loadJson GENERATE flatten(json#'tweets') as (m:map[]);
C = FOREACH B GENERATE FLATTEN(m#'text');
DUMP C;

Output:
(@Beace_ your nan makes me laugh with some of the things she comes out with)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Pig 中的elephantbird 进行 Json 解析 的相关文章

随机推荐

  • 批处理文件:列出特定文件夹中的rar文件并将结果写入文本文件

    我有一个文件夹 其中包含一些 rar 文件和子文件夹 这些子文件夹包含 rar 文件或子文件夹 递归结构 我想编写一个批处理文件 列出此文件夹树 完整路径 中的所有 rar 文件 结果被写入文本文件 Example 具体文件夹 Quest
  • WordPress - 将特色图像添加到自定义帖子类型

    我正在尝试将特色图像添加到我的主题中 但不适用于帖子或页面 我创建了一个名为 属性 的自定义类型 用于房地产经纪人 那么如何启用特色图像 因为它没有出现在场景选项中 希望有人能帮忙 property new Cuztom Post Type
  • Oracle无法从LONG数据类型转换为CLOB数据类型(数据类型不一致错误)

    Oracle 11g 在尝试将 long 数据类型转换为 clob 时出现以下错误 我尝试 select to lob long col name from table1 I get Error Execution 1 39 ORA 009
  • 定制频道wifi直连

    谁能告诉我 有没有自定义 wifi direct 频道的选项 我不仅需要在 ch1 ch6 和 ch11 之间进行自定义 还需要在我选择的其他频道中进行自定义 我怎样才能做到这一点 要更改设备 Wifi Direct 的频道 您需要执行以下
  • 设置创建或更改时间戳

    Using utimes futimes futimens等等 可以设置文件的访问和修改时间戳 修改时间是文件数据最后一次改变的时间 同样 ctime 或更改时间是文件属性 例如权限 最后一次更改的时间 Linux POSIX 维护三个时间
  • WPF TreeView刷新

    我有一个问题 我用TreeView在我的 WPF 项目中可视化我的 XML 数据 问题是 当我编辑我的XmlDocument它不会刷新TreeView 但我注意到当我检查时SelectedNode 这是我编辑的XmlNode 所以我的 编辑
  • 为什么我的文本字符串在 Pygame 中呈现为实心/填充矩形? [复制]

    这个问题在这里已经有答案了 所以我制作了一个 Yo Mama 笑话生成器 它做了它应该做的事情 如果我删除所有 Pygame 特定的代码并将其打印到终端 命令行 它就会起作用 但是当我添加 Pygame 并创建一个应用程序时 它会将文本显示
  • 正则表达式:用一种模式替换另一种模式

    我正在尝试用另一种正则表达式模式替换一种正则表达式模式 st srt Awake 01x02 iNTERNAL WEBRiP XViD GeT srt st mkv Awake S01E02 iNTERNAL WEBRiP XViD GeT
  • laravel5: chdir(): 没有这样的文件或目录 (errno 2)

    当我将 Laravel 5 上的网站构建部署到 VPS 服务器时遇到问题 但在本地计算机上它工作正常 我的页面是http easyway vn http easyway vn 当前页面显示空白并出现错误 无法加载资源 服务器响应状态为 50
  • 我的脚本不会进入下一页进行抓取

    我编写了一个用于网络抓取的代码 除了下一页活动之外 一切都很好 当我运行我的代码时scrape数据只是来自网站scraping第一页不会向前移动以抓取其他页面数据 实际上 我是使用 python 进行网络抓取的新手 所以请指导我 你能修复我
  • 修改Django中间件中的地址

    我不知道是否可行 但我想使用中间件在 URL 末尾添加一些参数 modyf 请求的 URL 后可以不重定向来完成吗 IE 用户点击 some link 中间件将其重写为 some link par1 1 par2 2 其他方法是修改响应并替
  • CSS 负 z-index:这是什么意思?

    如果我向元素的 z index 属性添加负整数值 根据标准 预期效果是什么 我搜索了答案 但只找到了这个 https developer mozilla org en US docs Web CSS z index https develo
  • 我在命令面板中没有看到 hello world 命令

    So the tutorial https code visualstudio com api get started your first extension开发 Visual Studio 代码扩展说要打F5然后是命令面板 我应该在其中
  • Android getColumName 和 getColumnIndex

    我是一名 Android 新手 我的光标有问题 我无法使用以下方式访问数据 cursor get cursor getColumnIndex columnName 我尝试了以下代码来测试是否有错误 while cursor moveToNe
  • 一个模型可以“属于”任一/或多个模型吗?

    抱歉 如果这是一个有点菜鸟的问题 但希望澄清我对此的想法 我有一个模型 它可以属于一个模型 也可以属于另一个模型 例如 假设我有一个团队模型和一个成员模型 这两个模型都可以有一个 BankAccount class Team has man
  • 从 firebase 检索数据返回 NULL

    当我调用listPost 时 它将返回NULL 我想它不会等待侦听器从 firebase 获取帖子 在返回 arrayPost 之前 如何等待从 firebase 获取帖子 public Post listPost ArrayList
  • 用于部署的语言/堆栈[关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 我正在进行相当密集的重写 并可以选择以下选项 JSP Java 运行在 Tomcat 上 PHP 运行在 Apache 下 Ruby 我不确定在
  • 为什么Android虚拟设备太慢?

    我刚刚从 android 开发者网站下载了 adt bundle 来尝试一下 当我点击 运行 按钮时 问题就开始了 Android虚拟设备或 avd 速度非常慢 我有一台相当不错的机器 核心 i7 和 16go 内存 他们不知道吗 我的意思
  • 如何防止模板类被多次派生?

    我有以下模板类 template
  • 使用 Pig 中的elephantbird 进行 Json 解析

    我无法在 Pig 中解析以下数据 这是 Twitter API 在获取某个用户的所有推文后返回的内容 源数据 我删除了一些数字 以免无意中侵犯任何人的隐私 created at Sat Nov 01 23 15 45 0000 2014 i