{"id":131959,"date":"2020-07-06T19:14:35","date_gmt":"2020-07-06T11:14:35","guid":{"rendered":"http:\/\/4563.org\/?p=131959"},"modified":"2020-07-06T19:14:35","modified_gmt":"2020-07-06T11:14:35","slug":"hive-%e5%ad%a6%e4%b9%a0%e4%b9%8b%e8%b7%af%ef%bc%88%e4%ba%94%e3%80%81hive%e7%9a%84%e5%88%86%e5%8c%ba%e8%a1%a8%e4%b8%8e%e5%88%86%e6%a1%b6%e8%a1%a8","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=131959","title":{"rendered":"hive \u5b66\u4e60\u4e4b\u8def\uff08\u4e94)\u3001Hive\u7684\u5206\u533a\u8868\u4e0e\u5206\u6876\u8868"},"content":{"rendered":"<p>Hive\u5c06\u8868\u5212\u5206\u4e3a\u5206\u533a(partition)\u8868\u548c\u5206\u6876(bucket)\u8868\u3002<br \/>\u5206\u533a\u53ef\u4ee5\u8ba9\u6570\u636e\u7684\u90e8\u5206\u67e5\u8be2\u53d8\u5f97\u66f4\u5feb\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5728\u52a0\u8f7d\u6570\u636e\u7684\u65f6\u5019\u53ef\u4ee5\u6307\u5b9a\u52a0\u8f7d\u67d0\u4e00\u90e8\u5206\u6570\u636e\uff0c\u5e76\u4e0d\u662f\u5168\u91cf\u7684\u6570\u636e\u3002<br \/>\u5206\u6876\u8868\u901a\u5e38\u662f\u5728\u539f\u59cb\u6570\u636e\u4e2d\u52a0\u5165\u4e00\u4e9b\u989d\u5916\u7684\u7ed3\u6784\uff0c\u8fd9\u4e9b\u7ed3\u6784\u53ef\u4ee5\u7528\u4e8e\u9ad8\u6548\u7684\u67e5\u8be2\uff0c\u4f8b\u5982\uff0c\u57fa\u4e8eID\u7684\u5206\u6876\u53ef\u4ee5\u4f7f\u5f97\u7528\u6237\u7684\u67e5\u8be2\u975e\u5e38\u7684\u5757\u3002<\/p>\n<h1><a href=\"https:\/\/www.studytime.xin\/article\/#Hive\u5206\u533a\u8868\" title=\"Hive\u5206\u533a\u8868\"><\/a>Hive\u5206\u533a\u8868<\/h1>\n<h2><a href=\"https:\/\/www.studytime.xin\/article\/#\u4ec0\u4e48\u662f\u5206\u533a\u8868\uff1f\" title=\"\u4ec0\u4e48\u662f\u5206\u533a\u8868\uff1f\"><\/a>\u4ec0\u4e48\u662f\u5206\u533a\u8868\uff1f<\/h2>\n<p>Hive\u5206\u533a\u662f\u6307\u6309\u7167\u6570\u636e\u8868\u7684\u67d0\u4e00\u4e2a\u5b57\u6bb5\u6216\u591a\u4e2a\u5b57\u6bb5\u8fdb\u884c\u7edf\u4e00\u5f52\u7c7b\uff0c\u5e76\u5b58\u50a8\u5728\u5728hdfs\u4e0a\u7684\u4e0d\u540c\u6587\u4ef6\u5939\u4e2d\u3002\u5f53\u67e5\u8be2\u8fc7\u7a0b\u4e2d\u6307\u5b9a\u4e86\u5206\u533a\u6761\u4ef6\u65f6\uff0c\u53ea\u5c06\u8be5\u5206\u533a\u5bf9\u5e94\u7684\u76ee\u5f55\u4f5c\u4e3aInput\uff0c\u4ece\u800c\u51cf\u5c11MapReduce\u7684\u8f93\u5165\u6570\u636e\uff0c\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5206\u533a\u8868\u7269\u7406\u5b58\u50a8\u7ed3\u6784\" title=\"\u5206\u533a\u8868\u7269\u7406\u5b58\u50a8\u7ed3\u6784\"><\/a>\u5206\u533a\u8868\u7269\u7406\u5b58\u50a8\u7ed3\u6784<\/h3>\n<p>\u5206\u533a\u8868\u8868\u5728hdfs\u4e0a\u4f5c\u4e3a\u4e00\u4e2a\u6587\u4ef6\u5939\u5b58\u5728\u3002<\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><span>9<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>0: jdbc:hive2:&#x2F;&#x2F;node03:10000&gt; dfs -ls &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;score;<\/span><br><span>+----------------------------------------------------+--+<\/span><br><span>|                     DFS Output                     |<\/span><br><span>+----------------------------------------------------+--+<\/span><br><span>| Found 4 items                                      |<\/span><br><span>| drwxr-xr-x   - hadoop supergroup          0 2020-06-07 15:57 &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;score&#x2F;month&#x3D;201803 |<\/span><br><span>| drwxr-xr-x   - hadoop supergroup          0 2020-06-07 15:57 &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;score&#x2F;month&#x3D;201804 |<\/span><br><span>| drwxr-xr-x   - hadoop supergroup          0 2020-06-07 15:57 &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;score&#x2F;month&#x3D;201805 |<\/span><br><span>| drwxr-xr-x   - hadoop supergroup          0 2020-06-07 15:53 &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;score&#x2F;month&#x3D;201806 |<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5206\u533a\u8868\u4f7f\u7528\u573a\u666f\" title=\"\u5206\u533a\u8868\u4f7f\u7528\u573a\u666f\"><\/a>\u5206\u533a\u8868\u4f7f\u7528\u573a\u666f<\/h3>\n<p>\u5b9e\u9645\u5de5\u4f5c\u4e2d\u5206\u533a\u8868\u5e38\u5e38\u88ab\u8fd0\u7528\u4e8e\u6309\u7167\u67d0\u4e00\u7ef4\u5ea6\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\u7684\u573a\u666f\u4e0b\uff0c\u6570\u636e\u88ab\u6309\u7167\u67d0\u4e00\u4e2a\u65e5\u671f\u3001\u5e74\u6708\u65e5\u7b49\u7b49\uff0c\u5c06\u4e00\u4e2a\u5927\u7684\u6587\u4ef6\u5207\u5206\u6210\u4e00\u4e2a\u4e2a\u5c0f\u6587\u4ef6\uff0c\u5206\u800c\u6cbb\u4e4b\uff0c\u8fd9\u6837\u5904\u7406\u8d77\u6765\u6027\u80fd\u5c31\u597d\u591a\u4e86\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5206\u533a\u8868\u8bed\u6cd5\" title=\"\u5206\u533a\u8868\u8bed\u6cd5\"><\/a>\u5206\u533a\u8868\u8bed\u6cd5<\/h3>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u521b\u5efa\u5206\u533a\u8868\u8bed\u6cd5\" title=\"\u521b\u5efa\u5206\u533a\u8868\u8bed\u6cd5\"><\/a>\u521b\u5efa\u5206\u533a\u8868\u8bed\u6cd5<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>hive (myhive)&gt; create table score(s_id string, c_id string, s_score int) partitioned by (month string) row format delimited fields terminated by &#39;t&#39;;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u521b\u5efa\u4e00\u4e2a\u8868\u5e26\u591a\u4e2a\u5206\u533a\" title=\"\u521b\u5efa\u4e00\u4e2a\u8868\u5e26\u591a\u4e2a\u5206\u533a\"><\/a>\u521b\u5efa\u4e00\u4e2a\u8868\u5e26\u591a\u4e2a\u5206\u533a<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>hive (myhive)&gt; create table score2 (s_id string,c_id string, s_score int) partitioned by (year string, month string, day string) row format delimited fields terminated by &#39;t&#39;;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u52a0\u8f7d\u6570\u636e\u5230\u5206\u533a\u8868\u5f53\u4e2d\u53bb\" title=\"\u52a0\u8f7d\u6570\u636e\u5230\u5206\u533a\u8868\u5f53\u4e2d\u53bb\"><\/a>\u52a0\u8f7d\u6570\u636e\u5230\u5206\u533a\u8868\u5f53\u4e2d\u53bb<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>hive (myhive)&gt;load data local inpath &#39;&#x2F;kkb&#x2F;install&#x2F;hivedatas&#x2F;score.csv&#39; into table score partition (month&#x3D;&#39;201806&#39;);<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u52a0\u8f7d\u6570\u636e\u5230\u591a\u5206\u533a\u8868\u5f53\u4e2d\u53bb\" title=\"\u52a0\u8f7d\u6570\u636e\u5230\u591a\u5206\u533a\u8868\u5f53\u4e2d\u53bb\"><\/a>\u52a0\u8f7d\u6570\u636e\u5230\u591a\u5206\u533a\u8868\u5f53\u4e2d\u53bb<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>hive (myhive)&gt; load data local inpath &#39;&#x2F;kkb&#x2F;install&#x2F;hivedatas&#x2F;score.csv&#39; into table score2 partition(year&#x3D;&#39;2018&#39;, month&#x3D;&#39;06&#39;, day&#x3D;&#39;01&#39;);<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u67e5\u770b\u5206\u533a\" title=\"\u67e5\u770b\u5206\u533a\"><\/a>\u67e5\u770b\u5206\u533a<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><span>9<\/span><br><span>10<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>show  partitions  score;<\/span><br><span><\/span><br><span>+---------------+--+<\/span><br><span>|   partition   |<\/span><br><span>+---------------+--+<\/span><br><span>| month&#x3D;201803  |<\/span><br><span>| month&#x3D;201804  |<\/span><br><span>| month&#x3D;201805  |<\/span><br><span>| month&#x3D;201806  |<\/span><br><span>+---------------+--+<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u5206\u533a\" title=\"\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u5206\u533a\"><\/a>\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u5206\u533a<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>alter table score add partition(month&#x3D;&#39;201805&#39;);<\/span><br><span><\/span><br><span>alter table score add partition(month&#x3D;&#39;201804&#39;) partition(month &#x3D; &#39;201803&#39;);<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p>\u7279\u6b8a\u8bf4\u660e\uff1a\u6dfb\u52a0\u5206\u533a\u4e4b\u540e\u5c31\u53ef\u4ee5\u5728hdfs\u6587\u4ef6\u7cfb\u7edf\u5f53\u4e2d\u770b\u5230\u8868\u4e0b\u9762\u591a\u4e86\u4e00\u4e2a\u6587\u4ef6\u5939<\/p>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u5220\u9664\u5206\u533a\" title=\"\u5220\u9664\u5206\u533a\"><\/a>\u5220\u9664\u5206\u533a<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>alter table score drop partition(month &#x3D; &#39;201806&#39;);<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p>\u7279\u6b8a\u8bf4\u660e\uff1a\u540c\u5185\u90e8\u8868\u548c\u5916\u90e8\u8868\u4e00\u81f4\uff0c\u5982\u679c\u8be5\u5206\u533a\u8868\u4e3a\u5916\u90e8\u8868\uff0c\u5219\u5206\u533a\u5bf9\u5e94\u7684HDFS\u76ee\u5f55\u6570\u636e\u4e0d\u4f1a\u88ab\u5220\u9664\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5206\u533a\u8868\u7ec3\u4e60\u4e00\" title=\"\u5206\u533a\u8868\u7ec3\u4e60\u4e00\"><\/a>\u5206\u533a\u8868\u7ec3\u4e60\u4e00<\/h3>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u9700\u6c42\u63cf\u8ff0\uff1a\" title=\"\u9700\u6c42\u63cf\u8ff0\uff1a\"><\/a>\u9700\u6c42\u63cf\u8ff0\uff1a<\/h4>\n<ul>\n<li>\u73b0\u5728\u6709\u4e00\u4e2a\u6587\u4ef6score.csv\u6587\u4ef6\uff0c\u91cc\u9762\u6709\u4e09\u4e2a\u5b57\u6bb5\uff0c\u5206\u522b\u662fs_id string, c_id string, s_score int<\/li>\n<li>\u5b57\u6bb5\u90fd\u662f\u4f7f\u7528 t\u8fdb\u884c\u5206\u5272<\/li>\n<li>\u5b58\u653e\u5728\u96c6\u7fa4\u7684\u8fd9\u4e2a\u76ee\u5f55\u4e0b\/scoredatas\/day=20180607\uff0c\u8fd9\u4e2a\u6587\u4ef6\u6bcf\u5929\u90fd\u4f1a\u751f\u6210\uff0c\u5b58\u653e\u5230\u5bf9\u5e94\u7684\u65e5\u671f\u6587\u4ef6\u5939\u4e0b\u9762\u53bb<\/li>\n<li>\u6587\u4ef6\u522b\u4eba\u4e5f\u9700\u8981\u516c\u7528\uff0c\u4e0d\u80fd\u79fb\u52a8<\/li>\n<li>\u8bf7\u521b\u5efahive\u5bf9\u5e94\u7684\u8868\uff0c\u5e76\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u8868\u4e2d\uff0c\u8fdb\u884c\u6570\u636e\u7edf\u8ba1\u5206\u6790\uff0c\u4e14\u5220\u9664\u8868\u4e4b\u540e\uff0c\u6570\u636e\u4e0d\u80fd\u5220\u9664<\/li>\n<\/ul>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u9700\u6c42\u5b9e\u73b0\" title=\"\u9700\u6c42\u5b9e\u73b0:\"><\/a>\u9700\u6c42\u5b9e\u73b0:<\/h4>\n<ul>\n<li>\u672c\u5730\u4e0a\u4f20\u6570\u636e\u5230hdfs<\/li>\n<\/ul>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>cd &#x2F;opt&#x2F;module&#x2F;hive-1.1.0-cdh5.14.2&#x2F;data&#x2F;test<\/span><br><span>hdfs dfs -mkdir -p &#x2F;scoredatas&#x2F;day&#x3D;20180607<\/span><br><span>hdfs dfs -put score.csv &#x2F;scoredatas&#x2F;day&#x3D;20180607&#x2F;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<ul>\n<li>\u521b\u5efa\u5916\u90e8\u5206\u533a\u8868\uff0c\u5e76\u6307\u5b9a\u6587\u4ef6\u6570\u636e\u5b58\u653e\u76ee\u5f55<\/li>\n<\/ul>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>create external table score4(s_id string, c_id string, s_score int) partitioned by (day string) row format delimited fields terminated by &#39;t&#39; location &#39;&#x2F;scoredatas&#39;;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<ul>\n<li>\u8fdb\u884c\u8868\u7684\u4fee\u590d\uff0c\u8bf4\u767d\u4e86\u5c31\u662f\u5efa\u7acb\u6211\u4eec\u8868\u4e0e\u6211\u4eec\u6570\u636e\u6587\u4ef6\u4e4b\u95f4\u7684\u4e00\u4e2a\u5173\u7cfb\u6620\u5c04(),\u4fee\u590d\u6210\u529f\u4e4b\u540e\u5373\u53ef\u770b\u5230\u6570\u636e\u5df2\u7ecf\u5168\u90e8\u52a0\u8f7d\u5230\u8868\u5f53\u4e2d\u53bb\u4e86<br \/><code>msck repair table score4;<\/code><\/li>\n<\/ul>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u9759\u6001\u4e0e\u52a8\u6001\u5206\u533a\u7684\u5b9e\u73b0\" title=\"\u9759\u6001\u4e0e\u52a8\u6001\u5206\u533a\u7684\u5b9e\u73b0\"><\/a>\u9759\u6001\u4e0e\u52a8\u6001\u5206\u533a\u7684\u5b9e\u73b0<\/h3>\n<p>\u4e0a\u6587\u8bb2\u5230\u7684\u6570\u636e\u5bfc\u5165\u573a\u666f\u5373\u4e3a\u9759\u6001\u5206\u533a\u7684\u4f7f\u7528\u573a\u666f\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u52a8\u6001\u5206\u533a\" title=\"\u52a8\u6001\u5206\u533a\"><\/a>\u52a8\u6001\u5206\u533a<\/h3>\n<p>\u6307\u6309\u7167\u9700\u6c42\u5b9e\u73b0\u628a\u6570\u636e\u81ea\u52a8\u5bfc\u5165\u5230\u8868\u7684\u4e0d\u540c\u5206\u533a\u4e2d\uff0c\u4e0d\u9700\u8981\u624b\u52a8\u6307\u5b9a\u3002<\/p>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u521b\u5efa\u8868\" title=\"\u521b\u5efa\u8868\"><\/a>\u521b\u5efa\u8868<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><span>9<\/span><br><span>10<\/span><br><span>11<\/span><br><span>12<\/span><br><span>13<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>--\u521b\u5efa\u666e\u901a\u8868<\/span><br><span>create table t_order(<\/span><br><span>    order_number string,<\/span><br><span>    order_price  double, <\/span><br><span>    order_time   string<\/span><br><span>)row format delimited fields terminated by &#39;t&#39;;<\/span><br><span><\/span><br><span>--\u521b\u5efa\u76ee\u6807\u5206\u533a\u8868<\/span><br><span>create table order_dynamic_partition(<\/span><br><span>    order_number string,<\/span><br><span>    order_price  double    <\/span><br><span>)partitioned BY(order_time string)<\/span><br><span>row format delimited fields terminated by &#39;t&#39;;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u51c6\u5907\u6570\u636e\" title=\"\u51c6\u5907\u6570\u636e\"><\/a>\u51c6\u5907\u6570\u636e<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><span>9<\/span><br><span>10<\/span><br><span>11<\/span><br><span>12<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>cd &#x2F;opt&#x2F;module&#x2F;hive-1.1.0-cdh5.14.2&#x2F;data&#x2F;test<\/span><br><span>vim order_partition.txt<\/span><br><span><\/span><br><span>10001\t100\t2019-03-02 <\/span><br><span>10002\t200\t2019-03-02<\/span><br><span>10003\t300\t2019-03-02<\/span><br><span>10004\t400\t2019-03-03<\/span><br><span>10005\t500\t2019-03-03<\/span><br><span>10006\t600\t2019-03-03<\/span><br><span>10007\t700\t2019-03-04<\/span><br><span>10008\t800\t2019-03-04<\/span><br><span>10009\t900\t2019-03-04<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u5411\u666e\u901a\u8868t-order\u52a0\u8f7d\u6570\u636e\" title=\"\u5411\u666e\u901a\u8868t_order\u52a0\u8f7d\u6570\u636e\"><\/a>\u5411\u666e\u901a\u8868t_order\u52a0\u8f7d\u6570\u636e<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>load data local inpath &#39;&#x2F;opt&#x2F;module&#x2F;hive-1.1.0-cdh5.14.2&#x2F;data&#x2F;test&#x2F;order_partition.txt&#39; overwrite into table t_order;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u52a8\u6001\u52a0\u8f7d\u6570\u636e\u5230\u5206\u533a\u8868\u4e2d\" title=\"\u52a8\u6001\u52a0\u8f7d\u6570\u636e\u5230\u5206\u533a\u8868\u4e2d\"><\/a>\u52a8\u6001\u52a0\u8f7d\u6570\u636e\u5230\u5206\u533a\u8868\u4e2d<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>-- \u8981\u60f3\u8fdb\u884c\u52a8\u6001\u5206\u533a\uff0c\u9700\u8981\u8bbe\u7f6e\u53c2\u6570<\/span><br><span>-- \u5f00\u542f\u52a8\u6001\u5206\u533a\u529f\u80fd<\/span><br><span>hive&gt; set hive.exec.dynamic.partition&#x3D;true; <\/span><br><span>-- \u8bbe\u7f6ehive\u4e3a\u975e\u4e25\u683c\u6a21\u5f0f<\/span><br><span>hive&gt; set hive.exec.dynamic.partition.mode&#x3D;nonstrict; <\/span><br><span>hive&gt; insert into table order_dynamic_partition partition(order_time) select order_number, order_price, order_time from t_order;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u67e5\u770b\u5206\u533a-1\" title=\"\u67e5\u770b\u5206\u533a\"><\/a>\u67e5\u770b\u5206\u533a<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><span>9<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>show partitions order_dynamic_partition;<\/span><br><span><\/span><br><span>+------------------------+--+<\/span><br><span>|       partition        |<\/span><br><span>+------------------------+--+<\/span><br><span>| order_time&#x3D;2019-03-02  |<\/span><br><span>| order_time&#x3D;2019-03-03  |<\/span><br><span>| order_time&#x3D;2019-03-04  |<\/span><br><span>+------------------------+--+<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h2><a href=\"https:\/\/www.studytime.xin\/article\/#Hive\u5206\u6876\u8868\" title=\"Hive\u5206\u6876\u8868\"><\/a>Hive\u5206\u6876\u8868<\/h2>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u4ec0\u4e48\u662f\u5206\u6876\u8868\uff1f\" title=\"\u4ec0\u4e48\u662f\u5206\u6876\u8868\uff1f\"><\/a>\u4ec0\u4e48\u662f\u5206\u6876\u8868\uff1f<\/h3>\n<p>Hive\u5206\u6876\u662f\u76f8\u5bf9\u5206\u533a\u8fdb\u884c\u66f4\u7ec6\u7c92\u5ea6\u7684\u5212\u5206\u3002\u662f\u5c06\u6574\u4e2a\u6570\u636e\u5185\u5bb9\u6309\u7167\u67d0\u5217\u53d6hash\u503c\uff0c\u5bf9\u6876\u7684\u4e2a\u6570\u53d6\u6a21\u7684\u65b9\u5f0f\u51b3\u5b9a\u8be5\u6761\u8bb0\u5f55\u5b58\u653e\u5728\u54ea\u4e2a\u6876\u5f53\u4e2d\uff1b\u5177\u6709\u76f8\u540chash\u503c\u7684\u6570\u636e\u8fdb\u5165\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u5982\u8981\u5b89\u88c5name\u5c5e\u6027\u5206\u4e3a3\u4e2a\u6876\uff0c\u5c31\u662f\u5bf9name\u5c5e\u6027\u503c\u7684hash\u503c\u5bf93\u53d6\u6478\uff0c\u6309\u7167\u53d6\u6a21\u7ed3\u679c\u5bf9\u6570\u636e\u5206\u6876\u3002\u5982\u53d6\u6a21\u7ed3\u679c\u4e3a0\u7684\u6570\u636e\u8bb0\u5f55\u5b58\u653e\u5230\u4e00\u4e2a\u6587\u4ef6\uff0c\u53d6\u6a21\u4e3a1\u7684\u6570\u636e\u5b58\u653e\u5230\u4e00\u4e2a\u6587\u4ef6\uff0c\u53d6\u6a21\u4e3a2\u7684\u6570\u636e\u5b58\u653e\u5230\u4e00\u4e2a\u6587\u4ef6\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u521b\u5efa\u5206\u6876\u8868\" title=\"\u521b\u5efa\u5206\u6876\u8868\"><\/a>\u521b\u5efa\u5206\u6876\u8868<\/h3>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u5728\u521b\u5efa\u5206\u6876\u8868\u4e4b\u524d\u8981\u6267\u4ee5\u4e0b\u7684\u547d\u4ee4\uff0c\u5f00\u542f\u5bf9\u5206\u6876\u8868\u7684\u652f\u6301\u4ee5\u53careduce\u4e2a\u6570\" title=\"\u5728\u521b\u5efa\u5206\u6876\u8868\u4e4b\u524d\u8981\u6267\u4ee5\u4e0b\u7684\u547d\u4ee4\uff0c\u5f00\u542f\u5bf9\u5206\u6876\u8868\u7684\u652f\u6301\u4ee5\u53careduce\u4e2a\u6570\"><\/a>\u5728\u521b\u5efa\u5206\u6876\u8868\u4e4b\u524d\u8981\u6267\u4ee5\u4e0b\u7684\u547d\u4ee4\uff0c\u5f00\u542f\u5bf9\u5206\u6876\u8868\u7684\u652f\u6301\u4ee5\u53careduce\u4e2a\u6570<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>set hive.enforce.bucketing&#x3D;true;<\/span><br><span><\/span><br><span># \u8bbe\u7f6e\u4e0e\u6876\u76f8\u540c\u7684reduce\u4e2a\u6570\uff08\u9ed8\u8ba4\u53ea\u6709\u4e00\u4e2areduce\uff09<\/span><br><span>set mapreduce.job.reduces&#x3D;4;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u521b\u5efa\u5206\u6876\u8868-1\" title=\"\u521b\u5efa\u5206\u6876\u8868\"><\/a>\u521b\u5efa\u5206\u6876\u8868<\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>create table myhive1.user_buckets_demo(id int, name string)<\/span><br><span>clustered by(id) <\/span><br><span>into 4 buckets <\/span><br><span>row format delimited fields terminated by &#39;t&#39;;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u5982\u4f55\u5411\u5206\u6876\u8868\u4e2d\u5bfc\u5165\u6570\u636e\" title=\"\u5982\u4f55\u5411\u5206\u6876\u8868\u4e2d\u5bfc\u5165\u6570\u636e\"><\/a>\u5982\u4f55\u5411\u5206\u6876\u8868\u4e2d\u5bfc\u5165\u6570\u636e<\/h4>\n<p>\u5411\u5206\u6876\u8868\u4e2d\u5bfc\u5165\u6570\u636e\uff0c\u4e0d\u53ef\u4ee5\u76f4\u63a5\u52a0\u8f7d\uff0c\u9700\u8981\u5148\u5bfc\u5165\u666e\u901a\u6807\uff0c\u518d\u5bfc\u5165\u5206\u6876\u8868\u4e2d\uff0c\u8fd9\u79cd\u548c\u52a8\u6001\u5206\u533a\u7c7b\u4f3c\u3002<\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><span>9<\/span><br><span>10<\/span><br><span>11<\/span><br><span>12<\/span><br><span>13<\/span><br><span>14<\/span><br><span>15<\/span><br><span>16<\/span><br><span>17<\/span><br><span>18<\/span><br><span>19<\/span><br><span>20<\/span><br><span>21<\/span><br><span>22<\/span><br><span>23<\/span><br><span>24<\/span><br><span>25<\/span><br><span>26<\/span><br><span>27<\/span><br><span>28<\/span><br><span>29<\/span><br><span>30<\/span><br><span>31<\/span><br><span>32<\/span><br><span>33<\/span><br><span>34<\/span><br><span>35<\/span><br><span>36<\/span><br><span>37<\/span><br><span>38<\/span><br><span>39<\/span><br><span>40<\/span><br><span>41<\/span><br><span>42<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span># \u521b\u5efa\u666e\u901a\u8868<\/span><br><span>create table user_demo(id int, name string)<\/span><br><span>row format delimited fields terminated by &#39;t&#39;;<\/span><br><span><\/span><br><span># \u51c6\u5907\u6570\u636e\u6587\u4ef6 buckets.txt<\/span><br><span>cd &#x2F;opt&#x2F;module&#x2F;hive-1.1.0-cdh5.14.2&#x2F;data&#x2F;test<\/span><br><span>vim user_bucket.txt<\/span><br><span><\/span><br><span>1\tanzhulababy1<\/span><br><span>2\tanzhulababy2<\/span><br><span>3\tanzhulababy3<\/span><br><span>4\tanzhulababy4<\/span><br><span>5\tanzhulababy5<\/span><br><span>6\tanzhulababy6<\/span><br><span>7\tanzhulababy7<\/span><br><span>8\tanzhulababy8<\/span><br><span>9\tanzhulababy9<\/span><br><span>10\tanzhulababy10<\/span><br><span><\/span><br><span># \u5411\u666e\u901a\u6807\u4e2d\u5bfc\u5165\u6570\u636e<\/span><br><span>load data local inpath &#39;&#x2F;opt&#x2F;module&#x2F;hive-1.1.0-cdh5.14.2&#x2F;data&#x2F;test&#x2F;user_bucket.txt&#39;  overwrite into table user_demo; <\/span><br><span><\/span><br><span># \u67e5\u770b\u6570\u636e<\/span><br><span>select * from user_demo;<\/span><br><span><\/span><br><span>+---------------+-----------------+--+<\/span><br><span>| user_demo.id  | user_demo.name  |<\/span><br><span>+---------------+-----------------+--+<\/span><br><span>| 1             | anzhulababy1    |<\/span><br><span>| 2             | anzhulababy2    |<\/span><br><span>| 3             | anzhulababy3    |<\/span><br><span>| 4             | anzhulababy4    |<\/span><br><span>| 5             | anzhulababy5    |<\/span><br><span>| 6             | anzhulababy6    |<\/span><br><span>| 7             | anzhulababy7    |<\/span><br><span>| 8             | anzhulababy8    |<\/span><br><span>| 9             | anzhulababy9    |<\/span><br><span>| 10            | anzhulababy10   |<\/span><br><span>+---------------+-----------------+--+<\/span><br><span><\/span><br><span># \u52a0\u8f7d\u6570\u636e\u5230\u6876\u8868user_buckets_demo\u4e2d<\/span><br><span>insert into table user_buckets_demo select * from user_demo;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5206\u6876\u8868\u7269\u7406\u5b58\u50a8\u7ed3\u6784\" title=\"\u5206\u6876\u8868\u7269\u7406\u5b58\u50a8\u7ed3\u6784\"><\/a>\u5206\u6876\u8868\u7269\u7406\u5b58\u50a8\u7ed3\u6784<\/h3>\n<p>\u5206\u6876\u8868\u8868\u5728hdfs\u4e0a\u4f5c\u4e3a\u4e00\u4e2a\u6587\u4ef6\u5b58\u5728\u3002<\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><span>9<\/span><br><span>10<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>0: jdbc:hive2:&#x2F;&#x2F;node03:10000&gt; dfs -ls &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;user_buckets_demo;<\/span><br><span>+----------------------------------------------------+--+<\/span><br><span>|                     DFS Output                     |<\/span><br><span>+----------------------------------------------------+--+<\/span><br><span>| Found 4 items                                      |<\/span><br><span>| -rwxr-xr-x   3 hadoop supergroup         30 2020-06-08 13:30 &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;user_buckets_demo&#x2F;000000_0 |<\/span><br><span>| -rwxr-xr-x   3 hadoop supergroup         45 2020-06-08 13:30 &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;user_buckets_demo&#x2F;000001_0 |<\/span><br><span>| -rwxr-xr-x   3 hadoop supergroup         47 2020-06-08 13:30 &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;user_buckets_demo&#x2F;000002_0 |<\/span><br><span>| -rwxr-xr-x   3 hadoop supergroup         30 2020-06-08 13:30 &#x2F;user&#x2F;hive&#x2F;warehouse&#x2F;myhive1.db&#x2F;user_buckets_demo&#x2F;000003_0 |<\/span><br><span>+----------------------------------------------------+--+<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5206\u901a\u8868\u4f7f\u7528\u573a\u666f\" title=\"\u5206\u901a\u8868\u4f7f\u7528\u573a\u666f\"><\/a>\u5206\u901a\u8868\u4f7f\u7528\u573a\u666f<\/h3>\n<ul>\n<li>\u53d6\u6837sampling\u66f4\u9ad8\u6548\u3002\u6ca1\u6709\u5206\u6876\u7684\u8bdd\u9700\u8981\u626b\u63cf\u6574\u4e2a\u6570\u636e\u96c6\u3002<\/li>\n<li>\u63d0\u5347\u67d0\u4e9b\u67e5\u8be2\u64cd\u4f5c\u6548\u7387\uff0c\u4f8b\u5982map side join<\/li>\n<\/ul>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5982\u4f55\u62bd\u6837\u67e5\u8be2\u6876\u8868\u7684\u6570\u636e\" title=\"\u5982\u4f55\u62bd\u6837\u67e5\u8be2\u6876\u8868\u7684\u6570\u636e\"><\/a>\u5982\u4f55\u62bd\u6837\u67e5\u8be2\u6876\u8868\u7684\u6570\u636e<\/h3>\n<p>tablesample\u62bd\u6837\u8bed\u53e5\u8bed\u6cd5\uff1atablesample(bucket  x  out  of  y)<\/p>\n<ul>\n<li>x\u8868\u793a\u4ece\u7b2c\u51e0\u4e2a\u6876\u5f00\u59cb\u53d6\u6570\u636e<\/li>\n<li>y\u4e0e\u8fdb\u884c\u91c7\u6837\u7684\u6876\u6570\u7684\u4e2a\u6570\u3001\u6bcf\u4e2a\u91c7\u6837\u6876\u7684\u91c7\u6837\u6bd4\u4f8b\u6709\u5173<\/li>\n<\/ul>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>select * from user_buckets_demo tablesample(bucket 1 out of 2);<\/span><br><span>-- \u9700\u8981\u91c7\u6837\u7684\u603b\u6876\u6570&#x3D;4&#x2F;2&#x3D;2\u4e2a<\/span><br><span>-- \u5148\u4ece\u7b2c1\u4e2a\u6876\u4e2d\u53d6\u51fa\u6570\u636e<\/span><br><span>-- 1+2&#x3D;3\uff0c\u518d\u4ece\u7b2c3\u4e2a\u6876\u4e2d\u53d6\u51fa\u6570\u636e<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p>\u7279\u6b8a\u8bf4\u660e\uff1a\u5206\u533a\u8868\u53ef\u4ee5\u4e0e\u5206\u6876\u8868\u4e00\u8d77\u4f7f\u7528<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hive\u5c06\u8868\u5212\u5206\u4e3a\u5206\u533a(parti&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/131959"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=131959"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/131959\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131959"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=131959"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=131959"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}