{"id":162,"date":"2021-09-01T16:59:44","date_gmt":"2021-09-01T08:59:44","guid":{"rendered":"https:\/\/www.gaohui.xyz\/?p=162"},"modified":"2021-12-14T19:30:35","modified_gmt":"2021-12-14T11:30:35","slug":"%e5%9f%ba%e4%ba%8ecos%e7%9a%84hive%e6%95%b0%e6%8d%ae%e5%86%b7%e7%83%ad%e5%88%86%e5%b1%82%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/www.gaohui.xyz\/?p=162","title":{"rendered":"\u57fa\u4e8eCOS\u7684Hive\u6570\u636e\u51b7\u70ed\u5206\u5c42\u65b9\u6848"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u5b58\u7b97\u5206\u79bb\u53ca\u51b7\u70ed\u5206\u5c42\u65b9\u6848\u7b80\u4ecb<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1.1 \u5b58\u7b97\u4e00\u4f53\u7684\u95ee\u9898<\/h3>\n\n\n\n<p>\u5728Hadoop\u751f\u6001\u4e2d\uff0c\u4e00\u76f4\u662f\u4ee5HDFS\u4f5c\u4e3a\u57fa\u7840\u5b58\u50a8\u6570\u636e\uff0c\u8ba1\u7b97\u8d44\u6e90\u548c\u5b58\u50a8\u8d44\u6e90\u8026\u5408\u5728\u4e00\u8d77\uff0c\u5c06\u6570\u636e\u5c3d\u91cf\u7684\u9760\u8fd1\u8ba1\u7b97\u8d44\u6e90\uff0c\u4e5f\u5c31\u662f\u6240\u8c13\u7684\u79fb\u52a8\u8ba1\u7b97\u6bd4\u79fb\u52a8\u6570\u636e\u66f4\u5212\u7b97\u3002<\/p>\n\n\n\n<p>\u4f46\u968f\u7740\u6570\u5b57\u65f6\u4ee3\u6570\u636e\u91cf\u7206\u53d1\u5f0f\u7684\u589e\u957f\u3001\u8ba1\u7b97\u5b58\u50a8\u89c4\u6a21\u7684\u4e0d\u65ad\u6269\u5927\uff0c\u8fd9\u79cd\u8ba1\u7b97\u3001\u5b58\u50a8\u8026\u5408\u7684\u67b6\u6784\u5e26\u6765\u7684\u591a\u79cd\u95ee\u9898\u4e0d\u65ad\u6d6e\u73b0\u51fa\u6765\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u5b58\u50a8\u8ba1\u7b97\u8026\u5408\uff0c\u65e0\u6cd5\u5355\u72ec\u6269\u5bb9\u8ba1\u7b97\u6216\u8005\u5b58\u50a8\u8d44\u6e90<\/li><li>\u6570\u636e\u4e09\u526f\u672c\u5b58\u50a8\uff0c\u8f83\u4f4e\u7684\u7a7a\u95f4\u5229\u7528\u7387\u589e\u52a0\u6210\u672c<\/li><li>\u96c6\u7fa4\u6269\u5bb9\u9700\u505a\u6570\u636e\u5747\u8861\uff0c\u5360\u7528\u7f51\u7edc\u8d44\u6e90\u5f71\u54cd\u4e1a\u52a1<\/li><li>HDFS\u6587\u4ef6\u6570\u76ee\u589e\u957f\u5e26\u6765\u5143\u6570\u636e\u81a8\u80c0\u95ee\u9898<\/li><li>\u51b7\u6570\u636e\u4f4e\u6210\u672c\u5b58\u50a8\u6bd4\u8f83\u96be\u5b9e\u73b0<\/li><\/ul>\n\n\n\n<p>\u540c\u65f6\u968f\u7740\u7f51\u7edc\u5e26\u5bbd\u7684\u53d1\u5c55\uff0c\u79fb\u52a8\u8ba1\u7b97\u5e26\u6765\u7684\u6536\u76ca\u4e5f\u4e0d\u90a3\u4e48\u660e\u663e\uff0c\u800c\u5b58\u7b97\u4e00\u4f53\u5e26\u6765\u7684\u4e0a\u9762\u90a3\u4e9b\u95ee\u9898\u4e5f\u5f00\u59cb\u5f71\u54cd\u4e1a\u52a1\u7684\u53d1\u5c55\uff0c\u8d8a\u6765\u8d8a\u591a\u7684\u5ba2\u6237\u5f00\u59cb\u8003\u8651\u5c06\u5927\u6570\u636e\u90e8\u7f72\u5230\u4e91\u4e0a\uff0c\u5e76\u91c7\u7528\u5bf9\u8c61\u5b58\u50a8\u4f5c\u4e3a\u6570\u636e\u5b58\u50a8\u7684\u5b58\u7b97\u5206\u79bb\u65b9\u6848\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.2 \u5b58\u7b97\u5206\u79bb\u7684\u4f18\u52bf<\/h3>\n\n\n\n<p>\u57fa\u4e8e\u817e\u8baf\u4e91EMR+Goosefs+COS\u7684\u5b58\u7b97\u5206\u79bb\u65b9\u6848\uff0c\u63d0\u4f9b\u4e86\u6258\u7ba1\u7684Hadoop\u8ba1\u7b97\u5e73\u53f0\uff0c\u8ba1\u7b97\u7aef\u7f13\u5b58\u670d\u52a1\u4ee5\u53ca\u9ad8\u53ef\u7528\u3001\u9ad8\u6027\u80fd\u7684\u6d77\u91cf\u5bf9\u8c61\u5b58\u50a8\u670d\u52a1\uff0c\u76f8\u5bf9\u4e8e\u4f20\u7edf\u7684\u5b58\u7b97\u4e00\u4f53\u65b9\u6848\uff0c\u5177\u5907\u5982\u4e0b\u4f18\u52bf\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6839\u636e\u4e1a\u52a1\u573a\u666f\uff0c\u6309\u9700\u6269\u7f29\u5bb9\u8ba1\u7b97\u8d44\u6e90\uff0c\u63d0\u4f9b\u5f39\u6027\u80fd\u529b<\/li><li>\u6d77\u91cf\u5b58\u50a8\u7a7a\u95f4\uff0c\u65e0\u9700\u8003\u8651\u5b58\u50a8\u5bb9\u91cf\u6269\u5bb9\u3001\u6587\u4ef6\u6570\u76ee\u7b49\u95ee\u9898<\/li><li>\u8ba1\u7b97\u7aef\u7f13\u5b58\u65b9\u6848\uff0c\u63d0\u5347\u6027\u80fd\uff0c\u8f7b\u677e\u5e94\u5bf9\u6570\u636e\u6e56\u573a\u666f<\/li><li>\u5b58\u50a8\u751f\u547d\u5468\u671f\u7ba1\u7406\uff0c\u70ed\u6570\u636e\u3001\u6e29\u6570\u636e\u53ca\u51b7\u6570\u636e\u5206\u5c42\u5b58\u50a8\uff0c\u964d\u4f4e\u5b58\u50a8\u6210\u672c<\/li><\/ul>\n\n\n\n<p>\u540c\u65f6\u817e\u8baf\u4e91COS\u63d0\u4f9b\u4e86\u652f\u6301\u6807\u51c6Hadoop\u6587\u4ef6\u7cfb\u7edf\u7684hadoop-cos\u63d2\u4ef6\uff0c\u4f7f\u5404\u79cd\u5927\u6570\u636e\u8ba1\u7b97\u6846\u67b6\u80fd\u591f\u50cf\u8bbf\u95eeHDFS\u4e00\u6837\uff0c\u8bfb\u5199\u5b58\u50a8\u5728COS\u4e0a\u7684\u6570\u636e\uff0c\u51cf\u5c11\u5927\u6570\u636e\u4e1a\u52a1\u5728\u8fc1\u79fb\u5230\u5b58\u7b97\u5206\u79bb\u67b6\u6784\u7684\u8fc1\u79fb\u6210\u672c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.3 \u51b7\u70ed\u5206\u5c42\u7684\u9700\u6c42<\/h3>\n\n\n\n<p>\u6211\u4eec\u5728\u548c\u5404\u7c7b\u5ba2\u6237\u4ea4\u6d41\u7684\u65f6\u5019\u53d1\u73b0\uff0c\u5927\u5bb6\u666e\u904d\u8ba4\u53ef\u5b58\u7b97\u5206\u79bb\u662f\u5927\u6570\u636e\u53d1\u5c55\u7684\u8d8b\u52bf\uff0c\u7279\u522b\u662f\u5728\u6570\u636e\u6e56\u7684\u573a\u666f\uff0c\u4f46\u662f\u4e0d\u53ef\u907f\u514d\u7684\u5b58\u5728\u4e00\u5b9a\u7684\u5347\u7ea7\u3001\u6539\u9020\u6210\u672c\u3002\u5f53\u524d\u8fd8\u6709\u4e0d\u5c11\u5ba2\u6237\u7684\u5927\u6570\u636e\u7cfb\u7edf\u8fd8\u662f\u5728IDC\u57fa\u4e8e\u7269\u7406\u670d\u52a1\u5668\u4ee5\u53ca\u672c\u5730\u76d8\u81ea\u5efa\u7684\uff0c\u6216\u8005\u662f\u4e91\u4e0a\u8d2d\u4e70\u7269\u7406\u673a\u6216\u865a\u62df\u673a\u57fa\u4e8e\u672c\u5730\u76d8\u3001\u4e91\u76d8\u81ea\u5efa\uff0c\u7531\u4e8e\u5404\u65b9\u9762\u539f\u56e0\uff0c\u77ed\u671f\u5185\u8fd8\u4e0d\u65b9\u4fbf\u5bf9\u5927\u6570\u636e\u7cfb\u7edf\u505a\u5347\u7ea7\u6539\u9020\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u81ea\u5efa\u5927\u6570\u636e\u7cfb\u7edf\uff0c\u7279\u522b\u662f\u5b58\u7b97\u4e00\u4f53\u5e26\u6765\u7684HDFS\u5b58\u50a8\u5bb9\u91cf\u8fc7\u9ad8\u7ba1\u7406\u56f0\u96be\u95ee\u9898\u3001\u8ba1\u7b97\u5b58\u50a8\u8d44\u6e90\u4e0d\u5339\u914d\u5e26\u6765\u7684\u8d44\u6e90\u6d6a\u8d39\u95ee\u9898\u4ee5\u53caHDFS\u6587\u4ef6\u7cfb\u7edf\u6587\u4ef6\u6570\u76ee\u8fc7\u591a\u5e26\u6765\u7684\u5143\u6570\u636e\u81a8\u80c0\u95ee\u9898\uff0c\u90fd\u56f0\u6270\u7740\u5927\u6570\u636e\u7ba1\u7406\u5458\uff0c\u8fd9\u4e2a\u95ee\u9898\u5728\u79bb\u7ebf\u6570\u4ed3Hive\u7684\u573a\u666f\u4e0b\u5c24\u4e3a\u660e\u663e\u3002<\/p>\n\n\n\n<p>\u817e\u8baf\u4e91\u63d0\u4f9b\u4e86Hive\u573a\u666f\u4e0bHDFS+COS\u7684\u6570\u636e\u51b7\u70ed\u5206\u5c42\u65b9\u6848\u3002\u5bf9\u4e8e\u540c\u4e00\u4e2aHive\u8868\uff0c\u4e0d\u540c\u7684\u5206\u533a\u6570\u636e\u8bbf\u95ee\u70ed\u5ea6\u4e0d\u4e00\u6837\uff0c\u5bf9\u4e8e\u4e00\u4e9b\u65f6\u95f4\u8f83\u8001\u7684\u5206\u533a\uff0c\u8bbf\u95ee\u9891\u6b21\u4f1a\u6bd4\u8f83\u4f4e\uff0c\u8bbf\u95ee\u6027\u80fd\u4e5f\u6ca1\u6709\u592a\u9ad8\u7684\u8981\u6c42\uff0c\u53ef\u4ee5\u5229\u7528IDC\u5230\u4e91\u4e0a\u7684\u4e13\u7ebf\u6216\u8005\u4e91\u4e0a\u7684\u5185\u7f51\u8d44\u6e90\uff0c\u5c06IDC\u6216\u8005\u4e91\u4e0a\u81ea\u5efa\u7684HDFS\u4e0a\u7684Hive\u51b7\u5206\u533a\u79fb\u52a8\u5230\u5bf9\u8c61\u5b58\u50a8COS\u4e0a\uff0c\u5b9e\u73b0\u6570\u636e\u7684\u51b7\u70ed\u5206\u5c42\u3002\u7531\u4e8e\u4e0d\u5bf9Hive\u8868\u505a\u4fee\u6539\uff0c\u4e0d\u4f1a\u5bf9\u4e1a\u52a1\u7aef\u8bbf\u95ee\u9020\u6210\u4efb\u4f55\u5f71\u54cd\uff0c\u53ef\u4ee5\u5b9e\u73b0\u4e1a\u52a1\u7aef\u900f\u660e\u7684\u6570\u636e\u51b7\u70ed\u5206\u5c42\u5b58\u50a8\u3002<\/p>\n\n\n\n<p>Hive\u7684\u51b7\u70ed\u5206\u5c42\u65b9\u6848\u5177\u5907\u5982\u4e0b\u4f18\u52bf\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>\u964d\u4f4e\u6210\u672c<\/strong>\uff1a\u51b7\u6570\u636e\u5b58\u653e\u81f3COS\uff0c\u5e76\u7ed3\u5408COS\u591a\u5b58\u50a8\u7c7b\u578b\uff08\u6807\u51c6\u3001\u4f4e\u9891\u3001\u5f52\u6863\u3001\u6df1\u5ea6\u5f52\u6863\uff09\u4ee5\u53ca\u751f\u547d\u5468\u671f\u7b56\u7565\u81ea\u52a8\u6c89\u964d\uff0c\u8f83\u5c11\u5b58\u50a8\u6210\u672c\u3002<\/li><li><strong>\u51cf\u5c11HDFS\u6587\u4ef6\u6570\u636e<\/strong>\uff1a\u51b7\u6570\u636e\u79fb\u52a8\u5230COS\u4e4b\u540e\uff0cHDFS\u6587\u4ef6\u7cfb\u7edf\u6587\u4ef6\u6570\u76ee\u51cf\u5c11\uff0c\u89e3\u51b3\u5143\u6570\u636e\u81a8\u80c0\u95ee\u9898\u3002<\/li><li><strong>\u4e1a\u52a1\u7aef\u900f\u660e<\/strong>\uff1a\u540c\u4e00\u4e2aHive\u8868\u4e0d\u540c\u7684\u5206\u533a\u5b58\u653e\u4e0d\u540c\u7684\u5b58\u50a8\u7c7b\u578b\uff0c\u4f46\u662f\u4e1a\u52a1\u8bbf\u95eeHive\u8868\u7684\u65b9\u5f0f\u4e0d\u53d8\uff0c\u5b58\u50a8\u6539\u9020\u5bf9\u4e1a\u52a1\u7aef\u900f\u660e\u3002<\/li><li><strong>\u957f\u671f\u6f14\u8fdb<\/strong>\uff1a\u51b7\u70ed\u5206\u5c42\u867d\u7136\u4f5c\u4e3a\u4e00\u4e2a\u8fc7\u6e21\u65b9\u6848\uff0c\u4f46\u662f\u4e0d\u5f71\u54cd\u5927\u6570\u636e\u67b6\u6784\u7531\u5b58\u7b97\u4e00\u4f53\u5230\u5b58\u7b97\u5206\u79bb\u7684\u6280\u672f\u67b6\u6784\u957f\u671f\u6f14\u8fdb\u3002<\/li><\/ul>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u4ecb\u7ecd\u5982\u4f55\u5728\u4e1a\u52a1\u7aef\u65e0\u611f\u77e5\u7684\u60c5\u51b5\u4e0b\uff0c\u5c06Hive\u8868\u4e2d\u51b7\u6570\u636e\u5206\u533a\u4eceHDFS\u8fc1\u79fb\u5230\u817e\u8baf\u4e91\u5bf9\u8c61\u5b58\u50a8COS\u4e0a\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Hive\u6570\u636e\u7684\u51b7\u70ed\u5206\u5c42\u5b58\u50a8<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u751f\u6210\u6d4b\u8bd5\u6570\u636e<\/h3>\n\n\n\n<p>\u4e3a\u4e86\u9a8c\u8bc1Hive\u6570\u636e\u51b7\u70ed\u5206\u5c42\u65b9\u6848\uff0c\u6211\u4eec\u5229\u7528\u811a\u672c\u751f\u6210\u4e86\u4e00\u6279\u6570\u636e\uff0c\u5e76\u5199\u5165\u5230csv\u6587\u4ef6\u4e2d\uff0c\u5305\u542border_id\u3001seller_id\u3001price\u3001tag\u3001order_date\u7b49\u5b57\u6bb5\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[hadoop@10 \/data]$ head 3.csv<br>order_1629443046,seller_261,434.37,1,20210721<br>order_1629443047,seller_252,901.47,0,20210729<br>order_1629443048,seller_65,858.44,1,20210818<br>order_1629443049,seller_99,923.94,0,20210729<br>order_1629443050,seller_81,868.92,1,20210812<br>order_1629443051,seller_142,989.22,0,20210722<br>order_1629443052,seller_0,430.96,0,20210810<br>order_1629443053,seller_27,665.8,0,20210802<br>order_1629443054,seller_85,74.3,1,20210819<br>order_1629443055,seller_34,913.02,0,20210723<\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u6839\u636eCSV\u4e2d\u4e2a\u5b57\u6bb5\u7684\u5185\u5bb9\uff0c\u521b\u5efa\u4e00\u4e2a\u6d4b\u8bd5\u8868\uff0c\u8fd9\u4e2aHive\u8868\u9ed8\u8ba4\u7684\u5b58\u50a8\u8def\u5f84\u662f\u5728HDFS\u4e0a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">create table order_sample (order_id string, seller_id string, price double, tag int)  partitioned by (dt string) ROW FORMAT SERDE 'org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe' WITH SERDEPROPERTIES &nbsp;('serialization.format' = '1') STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat' OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat' LOCATION 'hdfs:\/\/\/data\/order_sample';<\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u521b\u5efa\u4e00\u4e2a\u4e2d\u95f4\u8f6c\u6362\u8868\uff0c\u5e76\u5bfc\u5165CSV\u6570\u636e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">create table test (order_id string, seller_id string, price double, tag int, order_date string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' stored as textfile;<br>\u200b<br>load data local inpath '\/data\/3.csv' into table test;<\/pre>\n\n\n\n<p>\u5c06\u4e2d\u95f4\u8f6c\u6362\u8868\u4e2d\u5404\u4e2a\u5206\u533a\u7684\u6570\u636e\u5bfc\u5165\u6570\u636e\u81f3\u6d4b\u8bd5\u8868\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">for i in `hive -e \"select order_date from test group by order_date;\"`<br>do<br>hive -e \"insert overwrite table order_sample PARTITION(dt) select * from test where order_date='${i}';\"<br>done<\/pre>\n\n\n\n<p>\u67e5\u770b\u6d4b\u8bd5\u8868\u6570\u636e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">hive&gt; select count(*) from order_sample;<br>OK<br>30000000<br>Time taken: 2.767 seconds, Fetched: 1 row(s)<br>hive&gt; select * from order_sample limit 10;<br>OK<br>SLF4J: Failed to load class \"org.slf4j.impl.StaticLoggerBinder\".<br>SLF4J: Defaulting to no-operation (NOP) logger implementation<br>SLF4J: See http:\/\/www.slf4j.org\/codes.html#StaticLoggerBinder for further details.<br>order_1629443046  seller_261  434.37  1 20210721<br>order_1629443066  seller_292  3.02  1 20210721<br>order_1629443121  seller_51 209.34  1 20210721<br>order_1629443122  seller_47 619.43  1 20210721<br>order_1629443123  seller_230  92.58 1 20210721<br>order_1629443136  seller_32 553.62  0 20210721<br>order_1629443148  seller_272  767.66  0 20210721<br>order_1629443168  seller_265  803.19  0 20210721<br>order_1629443172  seller_255  749.48  1 20210721<br>order_1629443179  seller_64 839.39  1 20210721<br>Time taken: 0.221 seconds, Fetched: 10 row(s)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 Hive\u51b7\u6570\u636e\u8fc1\u79fb\u81f3COS<\/h3>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f7f\u7528distcp\uff0c\u5c06\u90e8\u5206\u51b7\u6570\u636e\u6240\u5728\u7684\u5206\u533a\u4e0a\u7684\u6570\u636e\u4eceHDFS\u590d\u5236\u5230COS\u4e0a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">hadoop distcp hdfs:\/\/\/data\/order_sample\/dt=20210721\/ cosn:\/\/hui-shanghai-1250000000\/data\/order_sample\/dt=20210721\/\nhadoop distcp hdfs:\/\/\/data\/order_sample\/dt=20210722\/ cosn:\/\/hui-shanghai-<meta charset=\"utf-8\">1250000000\/data\/order_sample\/dt=20210722\/\nhadoop distcp hdfs:\/\/\/data\/order_sample\/dt=20210723\/ cosn:\/\/hui-shanghai-<meta charset=\"utf-8\">1250000000\/data\/order_sample\/dt=20210723\/<\/pre>\n\n\n\n<p>\u5728Hive\u4e2d\uff0c\u4fee\u6539\u5df2\u7ecf\u8fc1\u5230COS\u4e0a\u7684\u51b7\u6570\u636e\u5206\u533a\u7684\u8def\u5f84\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">alter table order_sample partition (dt='20210721') set location \"cosn:\/\/hui-shanghai-<meta charset=\"utf-8\">1250000000\/data\/order_sample\/dt=20210721\/\";\nalter table order_sample partition (dt='20210722') set location \"cosn:\/\/hui-shanghai-<meta charset=\"utf-8\">1250000000\/data\/order_sample\/dt=20210722\/\";\nalter table order_sample partition (dt='20210723') set location \"cosn:\/\/hui-shanghai-<meta charset=\"utf-8\">1250000000\/data\/order_sample\/dt=20210723\/\";<\/pre>\n\n\n\n<p>\u4e3a\u4e86\u9a8c\u8bc1\u8fc1\u79fb\u5230COS\u4e0a\u7684\u5206\u533a\u7684\u8bbf\u95ee\uff0c\u6211\u4eec\u5220\u9664\u8fd9\u90e8\u5206\u5206\u533a\u5728HDFS\u4e0a\u5bf9\u5e94\u7684\u6587\u4ef6\u5939\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">hadoop dfs -rm -r -f hdfs:\/\/\/data\/order_sample\/dt=20210721\/<br>hadoop dfs -rm -r -f hdfs:\/\/\/data\/order_sample\/dt=20210722\/<br>hadoop dfs -rm -r -f hdfs:\/\/\/data\/order_sample\/dt=20210723\/<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u6df7\u5408\u5206\u533a\u9a8c\u8bc1<\/h2>\n\n\n\n<p>\u5728\u4e0a\u9762\u7684\u6b65\u9aa4\u4e2d\uff0c\u6211\u4eec\u5728Hive\u4e2d\u4fee\u6539\u4e86\u90e8\u5206\u5206\u533a\u6240\u5728\u7684\u8def\u5f84\u5e76\u6307\u5411\u4e86COS\uff0c\u5728Hive metastor\u4f1a\u540c\u6b65\u66f4\u65b0\u76f8\u5e94\u7684\u5b57\u6bb5\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u67e5\u8be2Hive metastore\u76f8\u5173\u7684\u8868\uff0c\u4ee5\u786e\u8ba4\u5206\u533a\u8def\u5f84\u5df2\u7ecf\u4fee\u6539\u3002<\/p>\n\n\n\n<p>\u5728Hive metastor\u7684\u8868\u4e2d\uff0c\u4ee5\u4e0b\u51e0\u4e2a\u8868\u5b58\u50a8\u4e86Hive\u8868\u53ca\u5206\u533a\u7684\u76f8\u5173\u4fe1\u606f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>TBLS\u8868\uff1aHive\u8868\u7684\u5177\u4f53\u4fe1\u606f<\/li><li>PARTITIONS\u8868\uff1aHive\u8868\u5206\u533a\u7684\u4fe1\u606f<\/li><li>SDS\u8868\uff1a\u63d0\u4f9btable\/partition\u5bf9\u5e94\u7684\u6587\u4ef6\u7cfb\u7edf\u8def\u5f84location\uff0c\u4ee5\u53ca\u5bf9\u8fd9\u4e2a\u6570\u636e\u8bfb\u53d6\u7684InputFormat\u3001\u662f\u5426\u538b\u7f29\u3001\u662f\u5426\u662f\u5b50\u6587\u4ef6\u5939\u5b58\u50a8\u3001SerDe\u7c7b\uff08\u5bf9\u5e94\u4e8eSERDES\u8868\uff09<\/li><\/ul>\n\n\n\n<p>EMR\u7684Hive metastor\u5b58\u50a8\u5728\u817e\u8baf\u4e91CDB MySQL\u6570\u636e\u5e93\u4e2d\uff0c\u8fde\u63a5\u76f8\u5173\u7684MySQL\u793a\u4f8b\uff0c\u5e76\u901a\u8fc7\u5982\u4e0bSQL\u8bed\u53e5\u67e5\u770b\u5206\u533a\u7684\u8def\u5f84\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">select TBLS.TBL_NAME,PARTITIONS.PART_NAME,SDS.LOCATION\nfrom SDS,TBLS,PARTITIONS\nwhere PARTITIONS.SD_ID = SDS.SD_ID\nand TBLS.TBL_ID=PARTITIONS.TBL_ID\norder by 1,2;\n\nTBLS_TBL_NAME\tPARTITIONS_PART_NAME\tSDS_LOCATION\norder_sample\tdt=20210721\tcosn:\/\/hui-shanghai-<meta charset=\"utf-8\">1250000000\/data\/order_sample\/dt=20210721\/\norder_sample\tdt=20210722\tcosn:\/\/hui-shanghai-<meta charset=\"utf-8\">1250000000\/data\/order_sample\/dt=20210722\/\norder_sample\tdt=20210723\tcosn:\/\/hui-shanghai-<meta charset=\"utf-8\">1250000000\/data\/order_sample\/dt=20210723\/\norder_sample\tdt=20210724\thdfs:\/\/10.0.0.10:4007\/data\/order_sample\/dt=20210724\norder_sample\tdt=20210725\thdfs:\/\/10.0.0.10:4007\/data\/order_sample\/dt=20210725\norder_sample\tdt=20210726\thdfs:\/\/10.0.0.10:4007\/data\/order_sample\/dt=20210726\norder_sample\tdt=20210727\thdfs:\/\/10.0.0.10:4007\/data\/order_sample\/dt=20210727\norder_sample\tdt=20210728\thdfs:\/\/10.0.0.10:4007\/data\/order_sample\/dt=20210728\norder_sample\tdt=20210729\thdfs:\/\/10.0.0.10:4007\/data\/order_sample\/dt=20210729\norder_sample\tdt=20210730\thdfs:\/\/10.0.0.10:4007\/data\/order_sample\/dt=20210730<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"462\" src=\"https:\/\/hui-tokyo-1258674280.cos.ap-tokyo.myqcloud.com\/wordpress\/2021\/09\/image-1024x462.png\" alt=\"\" class=\"wp-image-163\" srcset=\"https:\/\/www.gaohui.xyz\/wp-content\/uploads\/2021\/09\/image-1024x462.png 1024w, https:\/\/www.gaohui.xyz\/wp-content\/uploads\/2021\/09\/image-300x135.png 300w, https:\/\/www.gaohui.xyz\/wp-content\/uploads\/2021\/09\/image-768x346.png 768w, https:\/\/www.gaohui.xyz\/wp-content\/uploads\/2021\/09\/image-1536x693.png 1536w, https:\/\/www.gaohui.xyz\/wp-content\/uploads\/2021\/09\/image-2048x924.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u5728Hive\u4e2d\u67e5\u8be2COS\u4ee5\u53caHDFS\u5206\u533a\u4e0a\u7684\u6570\u636e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">select * from order_sample where dt='20210721' limit 10;<br>select * from order_sample where dt='20210722' limit 10;<br>select * from order_sample where dt='20210723' limit 10;<br>select * from order_sample where dt='20210724' limit 10;<br>select * from order_sample where dt='20210725' limit 10;<br>select * from order_sample where dt='20210726' limit 10;<\/pre>\n\n\n\n<p>\u4e0b\u9762\u7684\u67e5\u8be2\u9a8c\u8bc1\u4e86\uff0c\u5f53\u9700\u8981\u8bbf\u95ee\u7684\u6570\u636e\u5728HDFS\u548cCOS\u4e0a\u6df7\u5408\u5b58\u50a8\u65f6\uff0c\u4e1a\u52a1\u7aef\u7684\u8bbf\u95ee\u662f\u5b8c\u5168\u900f\u660e\u65e0\u611f\u77e5\u7684\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">hive&gt; select count(*),dt from order_sample where dt&lt;'20210801' group by dt;<br>Query ID = hadoop_20210823165807_f3c7db99-94df-4bd5-aa48-22e058f42a0a<br>Total jobs = 1<br>Launching Job 1 out of 1<br>Status: Running (Executing on YARN cluster with App id application_1629447707661_0175)<br><br>OK<br>967674\t20210721<br>967639\t20210722<br>969561\t20210723<br>967100\t20210724<br>966771\t20210725<br>967459\t20210726<br>968008\t20210727<br>965999\t20210728<br>967780\t20210729<br>967701\t20210730<br>968122\t20210731<br>Time taken: 38.665 seconds, Fetched: 11 row(s)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5b58\u7b97\u5206\u79bb\u53ca\u51b7\u70ed\u5206\u5c42\u65b9\u6848\u7b80\u4ecb 1.1 \u5b58\u7b97\u4e00\u4f53\u7684\u95ee\u9898 \u5728Hadoop\u751f\u6001\u4e2d\uff0c &hellip; <a href=\"https:\/\/www.gaohui.xyz\/?p=162\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-162","post","type-post","status-publish","format-standard","hentry","category-cos"],"_links":{"self":[{"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=\/wp\/v2\/posts\/162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=162"}],"version-history":[{"count":2,"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions"}],"predecessor-version":[{"id":166,"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=\/wp\/v2\/posts\/162\/revisions\/166"}],"wp:attachment":[{"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gaohui.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}