<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                存儲方式:行存儲。HDFS 自帶的文件格式。 **SequenceFile 特點:** 1、SequenceFile 文件是 Hadoop 用來存儲二進制形式的(key,value)對而 設計的一種平面文件(Flat File)。 2、可以把 SequenceFile 當作一個容器,把所有文件打包到 SequenceFile 類中可以高效的對小文件進行存儲和處理。 3、SequenceFile 文件并不按照其存儲的 key 進行排序存儲,SequenceFile 的內部類 Writer 提供了 append 功能。 4、SequenceFile 中的 key 和 value 可以是任意類型 Writable 或者是自定 義 Writable 類型。 <br/> **SequenceFile 壓縮:** 1、SequenceFile 的<ins>內部格式取決于是否啟用壓縮</ins>,如果是:要么是記錄壓縮,要么是塊壓縮。通過 `io.seqfile.compression.type=RECORD(記錄級壓縮)`或 `io.seqfile.compression.type=BLOCK(塊級壓縮)`決定。 2、有以下三種類型: >A、無壓縮類型:如果沒有啟用壓縮(默認設置),那么每個記錄就由它的記錄長度(字節數)、鍵的長度、鍵和值組成,長度字段為四字節。 >B、記錄壓縮類型:記錄壓縮格式與無壓縮格式基本相同,不同的是值字節是用定義在頭部的編碼器來壓縮。注意,鍵是不壓縮的。 >C、塊壓縮類型:塊壓縮一次壓縮多個記錄,因此它比記錄壓縮更緊湊,而且一般優先選擇。當記錄的字節數達到最小大小,才會添加到塊。該最小值由 `io.seqfile.compress.blocksize 中的屬性定義`,默認值是 1000000字節。格式為記錄數、鍵長度、鍵、值長度、值。 `io.seqfile.compress.blocksize` 參數決定每一個記錄塊壓縮的數據量,默認大小是 1000000 byte ,這個值具體指的是 key 和 value 緩存所占的空間,每要往文件寫一條 key/value 時,都是將 key 和 value 的長度以及 key 和 value 的值緩存在 keyLenBuffer keyBuffer valLenBuffer valBuffer 這四個 DataOutputStream 中,當keyBuffer.getLength() + valBuffer.getLength() 大于或等于io.seqfile.compress.blocksize 時,將這些數據當做一個 block 寫入sequence 文件。 ![](https://img.kancloud.cn/85/74/8574dc90f5f8ca5f1f5eb8677280ab78_1038x631.png) ![](https://img.kancloud.cn/2d/68/2d68021cda6b2f0723065fd44913df0d_1060x436.png) **SequenceFile 文件格式的優點:** ? 支持基于記錄(Record)或塊(Block)的數據壓縮 ? 支持 splittable,能夠作為 MapReduce 的輸入分片 ? 修改簡單:主要負責修改相應的業務邏輯,而不用考慮具體的存儲格式 ? 即使在壓縮時也支持分割<br/> **SequenceFile 文件格式的缺點:** ? 需要一個合并文件的過程,且合并后的文件將不方便查看 **讀寫 SequenceFile:** 需要引入的依賴請查看 ```sql 【HDFS分布式文件系統 -> HDFS JavaAPI -> 基本使用】一節 ``` ```java package datamodel; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.*; import org.apache.hadoop.util.ReflectionUtils; import org.junit.Test; import java.io.IOException; import java.net.URI; public class SequenceFileOps { private static Configuration conf = new Configuration(); // 定義hdfs地址 private static String url = "hdfs://hadoop101:9000"; // 定義測試數據 private static String[] data = {"a,b,c,d,e,f,g", "e,f,g,h,j,k", "l,m,n,o,p,q,r,s", "t,u,v,w,x,y,z"}; /** * 寫數據 */ @Test public void write() throws IOException { // io.seqfile.compression.type=RECORD 記錄壓縮 // io.seqfile.compression.type=BLOCK 塊壓縮 conf.set("io.seqfile.compression.type", "BLOCK"); // 獲取文件系統 FileSystem fs = FileSystem.get(URI.create(url), conf); // 定義在hdfs上的輸出路徑 Path output = new Path("/tmp/myseqfile.seq"); // 定義輸出的key和value IntWritable key = new IntWritable(); Text value = new Text(); // 調用寫出方法 SequenceFile.Writer writer = SequenceFile.createWriter(fs, conf, output, IntWritable.class, Text.class); // 測試循環寫出數據 for (int i = 0; i < 10; i++) { key.set(i); value.set(data[i % data.length]); writer.append(key, value); } //關閉流 IOUtils.closeStream(writer); } /** * 讀數據 */ @Test public void read() throws IOException { FileSystem fs = FileSystem.get(URI.create(url), conf); //定義讀入路徑 Path input = new Path("/tmp/myseqfile.seq"); //創建讀入流 SequenceFile.Reader reader = new SequenceFile.Reader(fs, input, conf); Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf); Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf); while (reader.next(key, value)) { System.out.println("key:" + key); System.out.println("value:" + value); System.out.println("position:" + reader.getPosition()); } } } ``` **查看文件內容:** ```sql [root@hadoop101 hadoop]# hdfs dfs -text /tmp/myseqfile.seq 0 a,b,c,d,e,f,g 1 e,f,g,h,j,k 2 l,m,n,o,p,q,r,s 3 t,u,v,w,x,y,z 4 a,b,c,d,e,f,g 5 e,f,g,h,j,k 6 l,m,n,o,p,q,r,s 7 t,u,v,w,x,y,z 8 a,b,c,d,e,f,g 9 e,f,g,h,j,k ``` **在Hive中使用SequenceFile存儲格式:** ```sql -- 方式一 create external table user_seq_ext( name string, favorite_number int, favorite_color string ) stored as sequencefile; -- 方式二: create external table user_seq_ext( name string, favorite_number int, favorite_color string ) stored as inputformat 'org.apache.hadoop.mapred.SequenceFileInputFormat' outputformat 'org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat'; ```
                  <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>

                              哎呀哎呀视频在线观看