<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] # 分桶表數據存儲 分區針對的是數據的存儲路徑,分桶針對的是數據文件 分區提供一個隔離數據和優化查詢的便利方式.不過,并非所有的數據集都可以形成合理的分區,特別是之前提到過的要確定合適劃分大小這個疑慮 分桶是將數據集分解成更容易管理的若干部分的另一個技術 # 數據準備 student.txt ~~~ 1001 ss1 1002 ss2 1003 ss3 1004 ss4 1005 ss5 1006 ss6 1007 ss7 1008 ss8 1009 ss9 1010 ss10 1011 ss11 1012 ss12 1013 ss13 1014 ss14 1015 ss15 1016 ss16 ~~~ # 創建分桶表 ~~~ hive (db1)> create table stu_buck(id int, name string) > clustered by(id) > into 4 buckets > row format delimited fields terminated by ' '; ~~~ 這邊表示按id字段分桶 # 導入數據 ~~~ load data local inpath '/root/study/student.txt' into table stu_buck; ~~~ 數據在hdfs上沒有分成4個文件,還是一個文件沒有分桶 **解決** **通過子查詢的方式導入** 1. 先建個普通的stu表 ~~~ create table stu(id int, name string)row format delimited fields terminated by ' '; ~~~ 2. 向普通的stu表中導入數據 ~~~ load data local inpath '/root/study/student.txt' into table stu; ~~~ 3. 清空stu_buck表中的數據 ~~~ truncate table stu_buck; ~~~ 4. 導入數據到分桶表,通過子查詢方式 ~~~ insert into table stu_buck select id, name from stu; ~~~ 5. 發現還是只有一個分桶 hdfs上看只有一個文件 6. 需要設置一個屬性 ~~~ //設置開啟分桶 set hive.enforce.bucketing=true; //把reduce設置為-1 set mapreduce.job.reduces=-1; //情況下表的數據 truncate table stu_buck; //插入數據 insert into table stu_buck select id, name from stu; ~~~ 7. 查詢分桶的數據 在hdfs上查看對應表的文件,分成了幾部分 # 分桶抽樣查詢 對于非常大的數據集,有時用戶需要使用的是一個具有代表性的查詢結果而不是全部結果.hive可以通過對表進行抽樣來滿足這個需求 ~~~ select * from stu_buck tablesample(bucket 1 out of 4 on id); ~~~ 注: tablesample是抽樣語句,語法:tablesample(bucket x out of y) y必須是table總bucket數的倍數或者因子. hive根據大小,決定抽樣的比例. 例如,table總共分了4份,當y等于2,抽取(4/2)2個bucket的數據 當y=8時,抽取(4/8=)1/2個bucket的數據 x表示從哪個bucket開始抽取. 例如,table總bucket數為4,tablesample(bucket 4 out of 4),表示總共抽取(4/4=)1個bucket的數據,抽取第4個bucket的數據 注意: x的值必須小于等于y的值,否則 ~~~ FAILED:SemanticException [Error 10061]: Numerator should not be bigger than denominator in sample clause for table stu_buck ~~~ # 數據塊抽樣 hive提供了另外一種按照百分比進行抽樣的方式,這種是基于行數的,按照輸入路徑下的數據塊百分比進行的抽樣 ~~~ select * from stu tablesample(0.1 percent); ~~~ 提示: 這種抽樣方式不一定適用于所有的文件格式.另外,這種抽樣的最小抽樣單元是一個HDFS數據塊.因此,如果表的數據大小小于普通的塊大小128M的話,那么將會返回所有行
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看