1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.mapred;
20
21 import java.io.IOException;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.hadoop.classification.InterfaceAudience;
26 import org.apache.hadoop.classification.InterfaceStability;
27 import org.apache.hadoop.fs.Path;
28 import org.apache.hadoop.hbase.HBaseConfiguration;
29 import org.apache.hadoop.hbase.client.HTable;
30 import org.apache.hadoop.hbase.util.Bytes;
31 import org.apache.hadoop.mapred.FileInputFormat;
32 import org.apache.hadoop.mapred.JobConf;
33 import org.apache.hadoop.mapred.JobConfigurable;
34 import org.apache.hadoop.util.StringUtils;
35
36
37
38
39 @Deprecated
40 @InterfaceAudience.Public
41 @InterfaceStability.Stable
42 public class TableInputFormat extends TableInputFormatBase implements
43 JobConfigurable {
44 private final Log LOG = LogFactory.getLog(TableInputFormat.class);
45
46
47
48
49 public static final String COLUMN_LIST = "hbase.mapred.tablecolumns";
50
51 public void configure(JobConf job) {
52 Path[] tableNames = FileInputFormat.getInputPaths(job);
53 String colArg = job.get(COLUMN_LIST);
54 String[] colNames = colArg.split(" ");
55 byte [][] m_cols = new byte[colNames.length][];
56 for (int i = 0; i < m_cols.length; i++) {
57 m_cols[i] = Bytes.toBytes(colNames[i]);
58 }
59 setInputColumns(m_cols);
60 try {
61 setHTable(new HTable(HBaseConfiguration.create(job), tableNames[0].getName()));
62 } catch (Exception e) {
63 LOG.error(StringUtils.stringifyException(e));
64 }
65 }
66
67 public void validateInput(JobConf job) throws IOException {
68
69 Path [] tableNames = FileInputFormat.getInputPaths(job);
70 if (tableNames == null || tableNames.length > 1) {
71 throw new IOException("expecting one table name");
72 }
73
74
75 if (getHTable() == null) {
76 throw new IOException("could not connect to table '" +
77 tableNames[0].getName() + "'");
78 }
79
80
81 String colArg = job.get(COLUMN_LIST);
82 if (colArg == null || colArg.length() == 0) {
83 throw new IOException("expecting at least one column");
84 }
85 }
86 }