Hadoop HDFS Sequencefile

Source: Internet
Author: User
Tags stub hadoop fs
Sequencefile is a text storage file consisting of byte streams of binary serialized key/value that can be used during the input/output format of the map/reduce process. During the map/reduce process, the temporary output of map processing files is processed using Sequencefile. So the general Sequencefile are the original files generated in the filesystem for map invocation.
Sequencefile can also be used to process small files: If the key is a small file name, value is the content of the file, you can combine large batches of small files into one large file. Public classSequencefilewritedemo { Public Static voidMain (string[] args) throwsIOException {// TODOauto-generated method stub String uri = "FILE:///REPOSITORIES/WORKSPACE/DEMO/HADOOP1/TARGET/SEQ.SQ"; Configuration conf = NewConfiguration (); FileSystem fs = FileSystem.                          Get (Uri.create (URI), conf); Path PATH = NewPath (URI); Intwritable key = NewIntwritable (); Text value = NewText (); Sequencefile.writer Writer= NULL; Try{ writer = sequencefile. Createwriter (FS, conf, Path, Key.getclass (), Value.getclass ());                   Key.set (1); Value.set (URI); writer.append (key, value); } finally{ioutils. Closestream (writer); }       } } Public classSequencefilereaddemo { Public Static voidMain (string[] args) throwsIOException {// TODOauto-generated method stub String uri = "FILE:///REPOSITORIES/WORKSPACE/DEMO/HADOOP1/TARGET/SEQ.SQ"; Configuration conf = NewConfiguration (); FileSystem fs = FileSystem. Get (Uri.create (URI), conf);
Path PATH = NewPath (URI); Sequencefile.reader Reader= NULL; Try{reader = New Sequencefile.reader (FS, Path, conf); Writable key = (writable) reflectionutils. Newinstance ( Reader.getkeyclass (), conf); Writable value = (writable) reflectionutils.newinstance ( Reader.getvalueclass (), conf); LongPosition = Reader.getposition (); while( Reader.next (key, value)) {String Syncseen = Reader.syncseen ()?                         "*"  :  "" ;   System.                         Out. printf ("[%s%s]\t%s\t%s\n", Position, Syncseen, key, value);  Position = Reader.getposition (); Beginning of Next Record}} finally{ioutils. Closestream (reader); }}} compression type, represented by the internal enumeration class Compressiontype of the Sequencefile class, defines three ways of not using compression: Compressiontype.noneRecord-level compression: Compressiontype.recordBlock-level compression: Compressiontype.blockParameters can be used when using: io.seqfile.compression.type=[none| record| BLOCK]To specify a specific compression method you can view the generated file contents by using the following command: Hadoop fs-textThe numbers.seq sequence file consists of a head and multiple record.
Head 3 bytes are seq, followed by 1 bytes for the version. Then include

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.