如何为Twitter数据设计HBase架构?

时间:2013-03-07 09:04:02

标签: twitter nosql hbase

我有跟踪Twitter数据,我想为它设计一个模式。我需要执行的查询如下: 得到推文音量的时间间隔,推文与相应的用户信息,推文与相应的主题信息等...基于以下数据,任何人都告诉架构的设计是正确的..(使rowkey为id +时间戳,列族为用户,其他人分为主要栏目。任何建议?

{
   "created_at":"Tue Feb 19 11:16:34 +0000 2013",
   "id":303825398179979265,
   "id_str":"303825398179979265",
   "text":"Unleashing Innovation Conference Kicks Off - Wall Street Journal (India)              http:\/\/t.co\/3bkXJBz1",
   "source":"\u003ca href=\"http:\/\/dlvr.it\" rel=\"nofollow\"\u003edlvr.it\u003c\/a\u003e",
   "truncated":false,
   "in_reply_to_status_id":null,
   "in_reply_to_status_id_str":null,
   "in_reply_to_user_id":null,
   "in_reply_to_user_id_str":null,
   "in_reply_to_screen_name":null,
   "user":{
      "id":948385189,
      "id_str":"948385189",
      "name":"Innovation Plaza",
      "screen_name":"InnovationPlaza",
      "location":"",
      "url":"http:\/\/tinyurl.com\/ee4jiralp",
      "description":"All the latest breaking news about Innovation",
      "protected":false,
      "followers_count":136,
      "friends_count":1489,
      "listed_count":1,
      "created_at":"Wed Nov 14 19:49:18 +0000 2012",
      "favourites_count":0,
      "utc_offset":28800,
      "time_zone":"Beijing",
      "geo_enabled":false,
      "verified":false,
      "statuses_count":149,
      "lang":"en",
      "contributors_enabled":false,
      "is_translator":false,
      "profile_background_color":"131516",
      "profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/781710342\/17a75bf22d9fdad38eebc1c0cd441527.jpeg",
      "profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/781710342\/17a75bf22d9fdad38eebc1c0cd441527.jpeg",
      "profile_background_tile":true,
      "profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/3205718892\/8126617ac6b7a0e80fe219327c573852_normal.jpeg",
      "profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/3205718892\/8126617ac6b7a0e80fe219327c573852_normal.jpeg",
      "profile_link_color":"009999",
      "profile_sidebar_border_color":"FFFFFF",
      "profile_sidebar_fill_color":"EFEFEF",
      "profile_text_color":"333333",
      "profile_use_background_image":true,
      "default_profile":false,
      "default_profile_image":false,
      "following":null,
      "follow_request_sent":null,
      "notifications":null
   },
   "geo":null,
   "coordinates":null,
   "place":null,
   "contributors":null,
   "retweet_count":0,
   "entities":{
      "hashtags":[

      ],
      "urls":[
         {
            "url":"http:\/\/t.co\/3bkXJBz1",
            "expanded_url":"http:\/\/dlvr.it\/2yyG5C",
            "display_url":"dlvr.it\/2yyG5C",
            "indices":[
               73,
               93
            ]
         }
      ],
      "user_mentions":[

      ]
   },
   "favorited":false,
   "retweeted":false,
   "possibly_sensitive":false
}

1 个答案:

答案 0 :(得分:0)

如果您100%确定该ID是唯一的,则可以使用此行作为存储大量数据的行键:

303825398179979265 - > data_CF

您的列族data_CF将在以下行中定义:

"created_at":"Tue Feb 19 11:16:34 +0000 2013"
"id_str":"303825398179979265"
...
"user_id":948385189 { take note here I'm denormalizing your dictionary }
"user_name":"Innovation Plaza"

列表有点棘手。解决方案是放置一些使其独特的东西,前缀为以下类别:

"entities_hashtags_":"\x00" { Here \x00 is a dummy value }

对于URL,如果排序不重要,您可以在其前面加上UUID。它将保证它是独一无二的。

这种方法的优点是,如果你需要更新这个数据中的一个字段,它将以原子方式完成,因为HBase保证了行的原子性。

对于第二个问题,如果您需要即时汇总信息,则必须预先计算并按照您在另一个表中所述的方式存储它。如果您希望通过M / R生成此数据,则可以将时间戳+行ID设置为基于时间。按主题可能是主题+行ID。这允许您编写具有开始停止行的前缀扫描,该行仅包括您感兴趣的时间范围或主题。

玩得开心!