1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.chukwa.util;
19
20
21 import java.io.IOException;
22 import java.net.URI;
23 import java.net.URISyntaxException;
24 import org.apache.hadoop.chukwa.conf.ChukwaConfiguration;
25 import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecord;
26 import org.apache.hadoop.chukwa.extraction.engine.ChukwaRecordKey;
27 import org.apache.hadoop.fs.FileSystem;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.io.SequenceFile;
30
31 public class DumpRecord {
32
33
34
35
36
37
38 public static void main(String[] args) throws IOException, URISyntaxException {
39 System.out.println("Input file:" + args[0]);
40
41 ChukwaConfiguration conf = new ChukwaConfiguration();
42 String fsName = conf.get("writer.hdfs.filesystem");
43 FileSystem fs = FileSystem.get(new URI(fsName), conf);
44
45 SequenceFile.Reader r = new SequenceFile.Reader(fs, new Path(args[0]), conf);
46
47 ChukwaRecordKey key = new ChukwaRecordKey();
48 ChukwaRecord record = new ChukwaRecord();
49 try {
50 while (r.next(key, record)) {
51 System.out.println("\t ===== KEY ===== ");
52
53 System.out.println("DataType: " + key.getReduceType());
54 System.out.println("\nKey: " + key.getKey());
55 System.out.println("\t ===== Value =====");
56
57 String[] fields = record.getFields();
58 System.out.println("Timestamp : " + record.getTime());
59 for (String field : fields) {
60 System.out.println("[" + field + "] :" + record.getValue(field));
61 }
62 }
63 } catch (Exception e) {
64 e.printStackTrace();
65 }
66
67 }
68
69 }