Last change
on this file since 57 was
20,
checked in by waue, 16 years ago
|
將改完的 hadoop 0.17版package 放來備份
目前繼續開發 hadoop 0.16 + hbase 1.3
|
File size:
941 bytes
|
Rev | Line | |
---|
[20] | 1 | package tw.org.nchc.util; |
---|
| 2 | |
---|
| 3 | import java.io.IOException; |
---|
| 4 | |
---|
| 5 | import org.apache.hadoop.fs.FileSystem; |
---|
| 6 | import org.apache.hadoop.fs.Path; |
---|
| 7 | import org.apache.hadoop.io.LongWritable; |
---|
| 8 | import org.apache.hadoop.io.SequenceFile; |
---|
| 9 | import org.apache.hadoop.mapred.JobConf; |
---|
| 10 | |
---|
| 11 | import tw.org.nchc.tuple.Tuple; |
---|
| 12 | |
---|
| 13 | public class LocalTupleRecordWriter { |
---|
| 14 | |
---|
| 15 | private LongWritable mLong = new LongWritable(); |
---|
| 16 | |
---|
| 17 | private long mCnt = 0; |
---|
| 18 | |
---|
| 19 | private SequenceFile.Writer writer; |
---|
| 20 | |
---|
| 21 | public LocalTupleRecordWriter(String file) throws IOException { |
---|
| 22 | JobConf config = new JobConf(); |
---|
| 23 | |
---|
| 24 | writer = SequenceFile.createWriter(FileSystem.get(config), config, |
---|
| 25 | new Path(file), LongWritable.class, Tuple.class); |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | public void add(Tuple tuple) throws IOException { |
---|
| 29 | mLong.set(mCnt); |
---|
| 30 | writer.append(mLong, tuple); |
---|
| 31 | mCnt++; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public long getRecordCount() { |
---|
| 35 | return mCnt; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | public void close() throws IOException { |
---|
| 39 | writer.close(); |
---|
| 40 | } |
---|
| 41 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.