{"id":215,"date":"2023-03-27T23:07:15","date_gmt":"2023-03-27T15:07:15","guid":{"rendered":"http:\/\/mapleleaf666.vip\/?p=215"},"modified":"2023-11-30T15:11:43","modified_gmt":"2023-11-30T07:11:43","slug":"hive%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"http:\/\/mapleleaf666.vip\/?p=215","title":{"rendered":"Hive\u57fa\u7840\u77e5\u8bc6\u603b\u7ed3"},"content":{"rendered":"\n<p>Hive\u662f\u5efa\u7acb\u5728 Hadoop \u4e0a\u7684\u6570\u636e\u4ed3\u5e93\u57fa\u7840\u6784\u67b6\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u6570\u636e\u63d0\u53d6\u8f6c\u5316\u52a0\u8f7d\uff08ETL\uff09\uff0c\u8fd9\u662f\u4e00\u79cd\u53ef\u4ee5\u5b58\u50a8\u3001\u67e5\u8be2\u548c\u5206\u6790\u5b58\u50a8\u5728 Hadoop \u4e2d\u7684\u5927\u89c4\u6a21\u6570\u636e\u7684\u673a\u5236\u3002Hive \u5b9a\u4e49\u4e86\u7b80\u5355\u7684\u7c7b SQL \u67e5\u8be2\u8bed\u8a00\uff0c\u79f0\u4e3a HQL\uff0c\u5b83\u5141\u8bb8\u719f\u6089 SQL \u7684\u7528\u6237\u67e5\u8be2\u6570\u636e\u3002\u540c\u65f6\uff0c\u8fd9\u4e2a\u8bed\u8a00\u4e5f\u5141\u8bb8\u719f\u6089 MapReduce \u5f00\u53d1\u8005\u7684\u5f00\u53d1\u81ea\u5b9a\u4e49\u7684 mapper \u548c reducer \u6765\u5904\u7406\u5185\u5efa\u7684 mapper \u548c reducer \u65e0\u6cd5\u5b8c\u6210\u7684\u590d\u6742\u7684\u5206\u6790\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">hive\u67b6\u6784<\/h1>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/mapleleaf666.vip\/wp-content\/uploads\/2023\/03\/image-1024x534.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"534\" data-original=\"http:\/\/mapleleaf666.vip\/wp-content\/uploads\/2023\/03\/image-1024x534.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-216\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u670d\u52a1\u7ec4\u4ef6\uff1a<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Driver\u7ec4\u4ef6\uff1a\u8be5\u7ec4\u4ef6\u5305\u62ec\uff1aCompiler\u3001Optimizer\u3001Executor,\u5b83\u53ef\u4ee5\u5c06Hive\u7684\u7f16\u8bd1\u3001\u89e3\u6790\u3001\u4f18\u5316\u8f6c\u5316\u4e3aMapReduce\u4efb\u52a1\u63d0\u4ea4\u7ed9Hadoop1\u4e2d\u7684JobTracker\u6216\u8005\u662fHadoop2\u4e2d\u7684SourceManager\u6765\u8fdb\u884c\u5b9e\u9645\u7684\u6267\u884c\u76f8\u5e94\u7684\u4efb\u52a1\u3002<\/li>\n\n\n\n<li>MetaStore\u7ec4\u4ef6\uff1a\u5b58\u50a8\u7740hive\u7684\u5143\u6570\u636e\u4fe1\u606f\uff0c\u5c06\u81ea\u5df1\u7684\u5143\u6570\u636e\u5b58\u50a8\u5230\u4e86\u5173\u7cfb\u578b\u6570\u636e\u5e93\u5f53\u4e2d\uff0c\u652f\u6301\u7684\u6570\u636e\u5e93\u4e3b\u8981\u6709\uff1aMysql\u3001Derby\u3001\u652f\u6301\u628ametastore\u72ec\u7acb\u51fa\u6765\u653e\u5728\u8fdc\u7a0b\u7684\u96c6\u7fa4\u4e0a\u9762\uff0c\u4f7f\u5f97hive\u66f4\u52a0\u5065\u58ee\u3002\u5143\u6570\u636e\u4e3b\u8981\u5305\u62ec\u4e86\u8868\u7684\u540d\u79f0\u3001\u8868\u7684\u5217\u3001\u5206\u533a\u548c\u5c5e\u6027\u3001\u8868\u7684\u5c5e\u6027\uff08\u662f\u4e0d\u662f\u5916\u90e8\u8868\u7b49\u7b49\uff09\u3001\u8868\u7684\u6570\u636e\u6240\u5728\u7684\u76ee\u5f55\u3002<\/li>\n\n\n\n<li>\u7528\u6237\u63a5\u53e3\uff1aCLI\uff08Command Line Interface)(\u5e38\u7528\u7684\u63a5\u53e3\uff1a\u547d\u4ee4\u884c\u6a21\u5f0f\uff09\u3001Client:Hive\u7684\u5ba2\u6237\u7aef\u7528\u6237\u8fde\u63a5\u81f3Hive Server ,\u5728\u542f\u52a8Client\u7684\u65f6\u5019\uff0c\u9700\u8981\u5236\u5b9aHive Server\u6240\u5728\u7684\u8282\u70b9\uff0c\u5e76\u4e14\u5728\u8be5\u8282\u70b9\u4e0a\u542f\u52a8Hive Server\u3001WUI:\u901a\u8fc7\u6d4f\u89c8\u5668\u7684\u65b9\u5f0f\u8bbf\u95eeHive\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fd0\u4f5c\u6d41\u7a0b\uff1a<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u7528\u6237\u63d0\u4ea4\u67e5\u8be2\u7b49\u4efb\u52a1\u7ed9Driver\u3002<\/li>\n\n\n\n<li>\u7f16\u8bd1\u5668\u83b7\u5f97\u8be5\u7528\u6237\u7684\u4efb\u52a1Plan\u3002<\/li>\n\n\n\n<li>\u7f16\u8bd1\u5668Compiler\u6839\u636e\u7528\u6237\u4efb\u52a1\u53bbMetaStore\u4e2d\u83b7\u53d6\u9700\u8981\u7684Hive\u7684\u5143\u6570\u636e\u4fe1\u606f\u3002<\/li>\n\n\n\n<li>\u7f16\u8bd1\u5668Compiler\u5f97\u5230\u5143\u6570\u636e\u4fe1\u606f\uff0c\u5bf9\u4efb\u52a1\u8fdb\u884c\u7f16\u8bd1\uff0c\u5148\u5c06HiveQL\u8f6c\u6362\u4e3a\u62bd\u8c61\u8bed\u6cd5\u6811\uff0c\u7136\u540e\u5c06\u62bd\u8c61\u8bed\u6cd5\u6811\u8f6c\u6362\u6210\u67e5\u8be2\u5757\uff0c\u5c06\u67e5\u8be2\u5757\u8f6c\u5316\u4e3a\u903b\u8f91\u7684\u67e5\u8be2\u8ba1\u5212\uff0c\u91cd\u5199\u903b\u8f91\u67e5\u8be2\u8ba1\u5212\uff0c\u5c06\u903b\u8f91\u8ba1\u5212\u8f6c\u5316\u4e3a\u7269\u7406\u7684\u8ba1\u5212\uff08MapReduce\uff09, \u6700\u540e\u9009\u62e9\u6700\u4f73\u7684\u7b56\u7565\u3002<\/li>\n\n\n\n<li>\u5c06\u6700\u7ec8\u7684\u8ba1\u5212\u63d0\u4ea4\u7ed9Driver\u3002<\/li>\n\n\n\n<li>Driver\u5c06\u8ba1\u5212Plan\u8f6c\u4ea4\u7ed9ExecutionEngine\u53bb\u6267\u884c\uff0c\u83b7\u53d6\u5143\u6570\u636e\u4fe1\u606f\uff0c\u63d0\u4ea4\u7ed9JobTracker\u6216\u8005SourceManager\u6267\u884c\u8be5\u4efb\u52a1\uff0c\u4efb\u52a1\u4f1a\u76f4\u63a5\u8bfb\u53d6HDFS\u4e2d\u6587\u4ef6\u8fdb\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li>\u83b7\u53d6\u6267\u884c\u7684\u7ed3\u679c\u3002<\/li>\n\n\n\n<li>\u53d6\u5f97\u5e76\u8fd4\u56de\u6267\u884c\u7ed3\u679c\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e2a\u4eba\u4f53\u4f1a\u5230\u7684\u7279\u6027\uff1a<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>hive\u7684\u4f18\u52bf\u5728\u4e8e\u5c06SQL\u8f6c\u5316\u4e3aMapreduce\u4f5c\u4e1a\uff0c\u5728\u7b80\u5316mapreduce\u7684\u540c\u65f6\uff0c\u4f18\u5316\u5176\u64cd\u4f5c<\/li>\n\n\n\n<li>hive\u548c\u5173\u7cfb\u6570\u636e\u5e93\u5b58\u50a8\u6587\u4ef6\u7684\u7cfb\u7edf\u4e0d\u540c\uff0chive\u4f7f\u7528\u7684\u662fhadoop\u7684HDFS\uff08hadoop\u7684\u5206\u5e03\u5f0f\u6587\u4ef6\u7cfb\u7edf\uff09\uff0c\u5173\u7cfb\u6570\u636e\u5e93\u5219\u662f\u670d\u52a1\u5668\u672c\u5730\u7684\u6587\u4ef6\u7cfb\u7edf\uff1bhive\u7684\u8868\u672c\u8d28\u5c31\u662fHadoop\u7684\u76ee\u5f55\/\u6587\u4ef6<\/li>\n\n\n\n<li>\u5173\u7cfb\u6570\u636e\u5e93\u90fd\u662f\u4e3a\u5b9e\u65f6\u67e5\u8be2\u7684\u4e1a\u52a1\u8fdb\u884c\u8bbe\u8ba1\u7684\uff0c\u800chive\u5219\u662f\u4e3a\u6d77\u91cf\u6570\u636e\u505a\u6570\u636e\u6316\u6398\u8bbe\u8ba1\u7684\uff0c\u5b9e\u65f6\u6027\u5f88\u5dee<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">hive\u5e38\u7528\u547d\u4ee4<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u67e5\u770b\u8868\uff08\u9009\u5b9a\u6570\u636e\u5e93\u540e\uff09\nshow tables\uff1b\n\n\/\/\u67e5\u770b\u8868\u7684\u683c\u5f0f\ndesc product;\n\n\/\/\u76f4\u63a5\u63d2\u5165\u6570\u636e\ninsert into customer (id,name,phone) values(1,'Tom','66308200');\n\n\/\/\u5c06\u672c\u5730\u6570\u636e\u63d2\u5165\u5230\u8868\u4e2d\nload data local inpath '\/usr\/hadoop\/customer.txt' into table customer;\n\n\/\/\u5c06\u672c\u5730\u6570\u636e\u8986\u76d6\u5230\u8868\u4e2d\nload data local inpath '\/usr\/hadoop\/customer.txt' OVERWRITE INTO TABLE customer;\n\n\/\/\u521b\u5efa\u8868\n\/\/\u8868\u5185\u6570\u636e\u7528'\\t'\u5206\u5272\uff08\u5373\u201cTab\u6309\u952e\u201d\uff09\nCREATE TABLE orderTable(id int,customer_id int,order_date date,offer_date date)\nROW FORMAT DELIMITED FIELDS TERMINATED BY '\\t';\n\ncreate table if not exists movie(\nmovie_id string,\nmovie_name string,\ndirectors array&lt;string>,\nactors array&lt;string>)\nrow format delimited\nfields terminated by '|'\ncollection items terminated by '%'; \n\u200b\ncreate table if not exists movie_other(\nmovie_id string,\nmovie_name string,\nother_id string)\nrow format delimited\nfields terminated by '|'\ncollection items terminated by '%'; \n\u200b\n\u200b\n\/\/\u88c5\u6570\u636e\nload data local inpath '\/home\/hadoop\/hive_movie_director_actor.txt' OVERWRITE INTO TABLE movie;\n\u200b\nload data local inpath '\/home\/hadoop\/hive_movie_other.txt' OVERWRITE INTO TABLE movie_other;\n\u200b\n\/\/\u4fee\u6539\u8868\u540d\nalter table movie_director_actor rename to movie;\n <\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528HIve\u8fdb\u884c\u6570\u636e\u5206\u6790<\/h1>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5206\u6790\u529f\u80fd\u793a\u4f8b<\/h2>\n\n\n\n<p>\u8fd8\u6709\u5f88\u591a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u529f\u80fd\u3001ETL\u529f\u80fd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u9009\u62e9\u524d\u5341\u6761\u6570\u636e\nselect * from movie limit 5;\/\/\u67e5\u770b\u524d10\u4f4d\u7528\u6237\u5bf9\u5546\u54c1\u7684\u884c\u4e3a\n\n\/\/\u8ba1\u7b97\u8868\u5185\u6761\u6570\nselect count(*) from product;\/\/\u7528\u805a\u5408\u51fd\u6570count()\u8ba1\u7b97\u51fa\u8868\u5185\u6709\u591a\u5c11\u6761\u884c\u6570\u636e \n\n\/\/\u5728\u51fd\u6570\u5185\u90e8\u52a0\u4e0adistinct\uff0c\u67e5\u51fauid\u4e0d\u91cd\u590d\u7684\u6570\u636e\u6709\u591a\u5c11\u6761\nselect count(distinct id) from customer;*\/\/\u5728\u51fd\u6570\u5185\u90e8\u52a0\u4e0adistinct\uff0c\u67e5\u51fauid\u4e0d\u91cd\u590d*<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6848\u4f8b\uff1a\u67e5\u8be2\u4e0d\u91cd\u590d\u7684\u6570\u636e\u6709\u591a\u5c11\u6761(\u4e3a\u4e86\u6392\u9664\u5ba2\u6237\u5237\u5355\u60c5\u51b5)<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>hive>select count(*) from (select uid,item_id,behavior_type,item_category,visit_date,province from bigdata_user group by uid,item_id,behavior_type,item_category,visit_date,province having count(*)=1)a;\n\n\/\/\u67e5\u627e\u5305\u542b\u7279\u5b9a\u4eba\u7269\u7684\u7535\u5f71\nselect movie_name from movie where array_contains(actors, 'RobertDowneyJr.')=true;\n\n\/\/\u67e5\u627e\u5305\u542b\u7279\u5b9a\u5bfc\u6f14\u7684\u7535\u5f71\nselect movie_name from movie where array_contains(directors, 'FrancisFordCoppola')=true;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hive\u662f\u5efa\u7acb\u5728 Hadoop \u4e0a\u7684\u6570\u636e\u4ed3\u5e93\u57fa\u7840\u6784\u67b6\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u6570\u636e\u63d0\u53d6\u8f6c\u5316\u52a0\u8f7d\uff08ET [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":512,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[23,20],"class_list":["post-215","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-note","tag-hive","tag-big-data"],"_links":{"self":[{"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=\/wp\/v2\/posts\/215","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=215"}],"version-history":[{"count":1,"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":217,"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions\/217"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=\/wp\/v2\/media\/512"}],"wp:attachment":[{"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mapleleaf666.vip\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}