{"id":1246,"date":"2013-10-09T15:34:34","date_gmt":"2013-10-09T06:34:34","guid":{"rendered":"http:\/\/kazu.tv\/blog\/?p=1246"},"modified":"2013-10-09T15:35:40","modified_gmt":"2013-10-09T06:35:40","slug":"dynamodb-s3-emr-cohort-analysis-2","status":"publish","type":"post","link":"https:\/\/kazu.tv\/blog\/2013\/10\/09\/dynamodb-s3-emr-cohort-analysis-2\/","title":{"rendered":"DynamoDB + S3 + EMR\u3067\u30b3\u30db\u30fc\u30c8\u5206\u6790(cohort analysis)\u3092\u3059\u308b(2)"},"content":{"rendered":"<p>\u3061\u3087\u3063\u3068<a title=\"DynamoDB + S3 + EMR\u3067\u30b3\u30db\u30fc\u30c8\u5206\u6790(cohort analysis)\u3092\u3059\u308b(1)\" href=\"http:\/\/kazu.tv\/blog\/2013\/09\/29\/dynamodb-s3-emr-cohort-analysis-1\/\">\u524d\u56de<\/a>\u304b\u3089\u9593\u304c\u7a7a\u3044\u3066\u3057\u307e\u3063\u305f\u3051\u3069\u3001DynamoDB\u4e0a\u306e\u30c7\u30fc\u30bf\u3084\u305d\u306e\u4ed6\u306e\u30c7\u30fc\u30bf\u3092S3\u306b\u96c6\u3081\u3066\u3001EMR\u4e0a\u306eHive\u3092\u4f7f\u3063\u3066\u30b3\u30db\u30fc\u30c8\u5206\u6790\u3092\u3059\u308b\u3068\u3044\u3046\u8a71\u306e\u7b2c2\u56de\u3002\u4eca\u56de\u306fHive\u306e\u8a71\u3092\u4e2d\u5fc3\u306b\u66f8\u3044\u3066\u3044\u304f\u3002<\/p>\n<p>\u203bHive\u3092\u4f7f\u3046\u306e\u306f\u4eca\u56de\u304c\u5b9f\u8cea\u521d\u3081\u3066\u3067\u3001EMR\u306b\u3064\u3044\u3066\u3082\u3042\u307e\u308a\u7d4c\u9a13\u306f\u8c4a\u5bcc\u3067\u306f\u306a\u3044\u306e\u3067\u3001\u4f55\u304b\u304a\u304b\u3057\u3044\u70b9\u306a\u3069\u304c\u3042\u3063\u305f\u3089\u3054\u6307\u6458\u9802\u3051\u308b\u3068\u5e78\u3044\u3067\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<h2>Hive\u30c6\u30fc\u30d6\u30eb\u3068S3\u306e\u300c\u30d5\u30a9\u30eb\u30c0\u300d\u69cb\u6210<\/h2>\n<p>\u521d\u3081\u306b\u66f8\u3044\u3066\u304a\u304f\u3068\u3001S3\u306b\u306f\u53b3\u5bc6\u306b\u306f\u300c\u30d5\u30a9\u30eb\u30c0\u300d\u3068\u3044\u3046\u6982\u5ff5\u306f\u306a\u304f\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u306b\u300c\/\u300d\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u3068\u3001AWS Management Console\u3084\u305d\u306e\u4ed6\u30c4\u30fc\u30eb\u304b\u3089\u30d5\u30a9\u30eb\u30c0\u306e\u3088\u3046\u306b\u898b\u3048\u308b\u3001\u3068\u3044\u3046\u3060\u3051\u3002<\/p>\n<p>Hive\u306eexternal table\u3067\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u3068\u300c\u30d5\u30a9\u30eb\u30c0\u300d\u304c1\u5bfe1\u3067\u5bfe\u5fdc\u3059\u308b\u3002\u4f8b\u3048\u3070Hive\u3067\u4ee5\u4e0b\u306e\u3088\u3046\u306bS3\u4e0a\u306btable_a\u3092\u4f5c\u6210\u3059\u308b\u30b1\u30fc\u30b9\u3092\u8003\u3048\u308b\u3002<\/p>\n<pre class=\"brush: sql;\">CREATE EXTERNAL TABLE table_a (\r\ncol1 string,\r\ncol2 string\r\n)\r\nROW FORMAT DELIMITED\r\n    FIELDS TERMINATED BY '\\t'\r\n    LINES TERMINATED BY '\\n'\r\nLOCATION 's3:\/\/bucket\/hive\/table_a\/';<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001table_a\u306b\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3063\u305f\u5834\u5408\u3001s3:\/\/bucket\/hive\/table_a\/ \u4ee5\u4e0b\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u66f8\u304d\u8fbc\u307e\u308c\u308b\u3002\u305d\u306e\u969b\u3001\u30d5\u30a1\u30a4\u30eb\u306f1\u3064\u3068\u306f\u9650\u3089\u305a\u8907\u6570\u306e\u5834\u5408\u3082\u3042\u308b\u306e\u3067\u8981\u6ce8\u610f\u3002<\/p>\n<p>\u9006\u306b\u3001Hive\u4ee5\u5916\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u304b\u3089S3\u4e0a\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3001\u305d\u308c\u3092Hive\u306e\u30c6\u30fc\u30d6\u30eb\u3068\u8a8d\u8b58\u3055\u305b\u305f\u3044\u5834\u5408\u3001\u4e0a\u306e\u3088\u3046\u306a\u30d5\u30a9\u30eb\u30c0\u69cb\u6210\u3092\u5b88\u3063\u3066\u304a\u3051\u3070OK(\u30d5\u30a1\u30a4\u30eb\u540d\u306f\u4efb\u610f\u3067\u69cb\u308f\u306a\u3044)\u3002<\/p>\n<h2>\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3<\/h2>\n<p>Hive\u3067\u306f\u30c6\u30fc\u30d6\u30eb\u3092\u300c\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u5316\u300d\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u8a73\u3057\u304f\u306fHive\u306e<a title=\"Hive\u306eWiki\u306ePartitioned Tables\u306e\u9805\" href=\"https:\/\/cwiki.apache.org\/confluence\/display\/Hive\/LanguageManual+DDL#LanguageManualDDL-PartitionedTables\" target=\"_blank\">Wiki<\/a>\u3092\u53c2\u7167\u3057\u3066\u6b32\u3057\u3044\u304c\u3001\u4f8b\u3048\u3070\u3001\u6642\u7cfb\u5217\u30c7\u30fc\u30bf\u3092\u6708\u6bce\u306b\u9055\u3046\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u306b\u3059\u308b\u3068\u8a00\u3063\u305f\u4f7f\u3044\u65b9\u304c\u8003\u3048\u3089\u308c\u308b\u3002\u30e1\u30ea\u30c3\u30c8\u306f\u3001\u5927\u96d1\u628a\u306b\u8a00\u3048\u3070RDBMS\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u5316\u3068\u540c\u3058\u3088\u3046\u306a\u3082\u306e\u3002<\/p>\n<p>Wiki\u306e\u4f8b\u306b\u5023\u3063\u3066\u3001\u4ee5\u4e0b\u306e\u69d8\u306a\u30c6\u30fc\u30d6\u30eb\u3092\u8003\u3048\u308b(\u5c11\u3057\u3060\u3051\u6539\u5909)\u3002<\/p>\n<pre class=\"brush: sql;\">CREATE TABLE table_name (\r\nid\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int,\r\nname\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 string\r\n)\r\nPARTITIONED BY (date string) -- yyyy-mm-dd \u5f62\u5f0f\r\nLOCATION 's3:\/\/bucket\/hive\/table_name\/';<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001\u30c6\u30fc\u30d6\u30eb\u306b\u30c7\u30fc\u30bf\u3092\u6295\u5165\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u300c\u30d5\u30a9\u30eb\u30c0\u300d\u306b\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002<\/p>\n<ul>\n<li>s3:\/\/bucket\/hive\/table_name\/date=2013-10-01\/<\/li>\n<li>s3:\/\/bucket\/hive\/table_name\/date=2013-10-02\/<\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u306e\u69d8\u306a\u8907\u6570\u306e\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u306e\u5834\u5408\u3001<\/p>\n<pre class=\"brush: sql;\">CREATE TABLE page_view(viewTime INT, userid BIGINT,\r\n     page_url STRING, referrer_url STRING,\r\n     ip STRING COMMENT 'IP Address of the User')\r\nCOMMENT 'This is the page view table'\r\nPARTITIONED BY(dt STRING, country STRING)\r\nLOCATION 's3:\/\/bucket\/hive\/table_name\/';<\/pre>\n<p>\u4ee5\u4e0b\u306e\u69d8\u306a\u30d5\u30a9\u30eb\u30c0\u304c\u4f5c\u6210\u3055\u308c\u308b\u3002<\/p>\n<ul>\n<li>s3:\/\/bucket\/hive\/table_name\/dt=2013-10-01\/country=US\/<\/li>\n<li>s3:\/\/bucket\/hive\/table_name\/dt=2013-10-02\/country=US\/<\/li>\n<li>s3:\/\/bucket\/hive\/table_name\/dt=2013-10-02\/country=JP\/<\/li>\n<\/ul>\n<h2>Hive\u306eexternal table\u3068\u30d5\u30a1\u30a4\u30eb\u5f62\u5f0f<\/h2>\n<p>\u4e0a\u306e\u65b9\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306aCREATE TABLE\u6587\u3092\u8f09\u305b\u305f\u3002<\/p>\n<pre class=\"brush: sql;\">CREATE EXTERNAL TABLE table_a (\r\ncol1 string,\r\ncol2 string\r\n)\r\nROW FORMAT DELIMITED\r\n    FIELDS TERMINATED BY '\\t'\r\n    LINES TERMINATED BY '\\n'\r\nLOCATION 's3:\/\/bucket\/hive\/table_a\/';<\/pre>\n<p>\u5f8c\u534a\u306e ROW FORMAT \u4ee5\u964d\u3060\u304c\u3001\u3053\u308c\u306f\u3001s3:\/\/bucket\/hive\/table_a\/ \u4ee5\u4e0b\u306b\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u306b\u5bfe\u3057<\/p>\n<ul>\n<li>\\n\u3092\u884c(\u30ec\u30b3\u30fc\u30c9)\u533a\u5207\u308a<\/li>\n<li>\\t\u3092\u30d5\u30a3\u30fc\u30eb\u30c9\u533a\u5207\u308a<\/li>\n<\/ul>\n<p>\u3068\u307f\u306a\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u3093\u3067\u30c6\u30fc\u30d6\u30eb\u3068\u3057\u3066\u6271\u3046\u3068\u3044\u3046\u3053\u3068\u3092\u610f\u5473\u3057\u3066\u3044\u308b\u3002\u3064\u307e\u308a\u3001TSV\u30d5\u30a1\u30a4\u30eb\u3092\u30c6\u30fc\u30d6\u30eb\u3068\u3057\u3066\u6271\u3046\u5834\u5408\u306b\u3001\u3053\u3046\u3057\u305fexternal table\u3092\u5b9a\u7fa9\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n<h2>recover partitions<\/h2>\n<p>Hive\u4ee5\u5916\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3067S3\u4e0a\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3066\u3001Hive\u304b\u3089\u30d1\u30fc\u30c6\u30a3\u30b7\u30e7\u30f3\u4ed8\u304d\u306eexternal table\u3092\u5b9a\u7fa9\u3059\u308b\u969b\u3001\u4ee5\u4e0b\u306e\u30b9\u30c6\u30fc\u30c8\u30e1\u30f3\u30c8\u3092\u5b9f\u884c\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n<pre class=\"brush: sql;\">ALTER TABLE table_name RECOVER PARTITIONS;<\/pre>\n<p>\u3053\u308c\u306f\u3001Hive\u306b\u5bfe\u3059\u308bAmazon Elastic MapReduce\u72ec\u81ea\u306e\u62e1\u5f35\u3002\u8a73\u7d30\u306f<a href=\"http:\/\/docs.aws.amazon.com\/ElasticMapReduce\/latest\/DeveloperGuide\/emr-hive-additional-features.html#emr-hive-recovering-partitions\" target=\"_blank\">\u3053\u306e\u8fba<\/a>\u3002<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u4eca\u56de\u306fS3\u4e0a\u306b\u7f6e\u3044\u305f\u30c7\u30fc\u30bf\u3092Hive\u304b\u3089\u6271\u3046\u65b9\u6cd5\u306b\u3064\u3044\u3066\u4e3b\u306b\u8aac\u660e\u3057\u305f\u3002\u6b21\u56de\u3067\u3001\u5177\u4f53\u7684\u306a\u30b3\u30db\u30fc\u30c8\u5206\u6790\u3092\u5b9f\u65bd\u3057\u3066\u3044\u304f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3061\u3087\u3063\u3068\u524d\u56de\u304b\u3089\u9593\u304c\u7a7a\u3044\u3066\u3057\u307e\u3063\u305f\u3051\u3069\u3001DynamoDB\u4e0a\u306e\u30c7\u30fc\u30bf\u3084\u305d\u306e\u4ed6\u306e\u30c7\u30fc\u30bf\u3092S3\u306b\u96c6\u3081\u3066\u3001EMR\u4e0a\u306eHive\u3092\u4f7f\u3063\u3066\u30b3\u30db\u30fc\u30c8\u5206\u6790\u3092\u3059\u308b\u3068\u3044\u3046\u8a71\u306e\u7b2c2\u56de\u3002\u4eca\u56de\u306fHive\u306e\u8a71\u3092\u4e2d\u5fc3\u306b\u66f8\u3044\u3066\u3044\u304f\u3002 \u203bHive\u3092\u4f7f\u3046\u306e\u306f&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[911,914,912],"class_list":["post-1246","post","type-post","status-publish","format-standard","hentry","category-15","tag-emr","tag-hive","tag-s3"],"_links":{"self":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/comments?post=1246"}],"version-history":[{"count":3,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1246\/revisions"}],"predecessor-version":[{"id":1249,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/posts\/1246\/revisions\/1249"}],"wp:attachment":[{"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/media?parent=1246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/categories?post=1246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kazu.tv\/blog\/wp-json\/wp\/v2\/tags?post=1246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}