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.DataInput;
22 import java.io.DataOutput;
23 import java.io.IOException;
24 import java.util.Arrays;
25
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
27 import org.apache.hadoop.hbase.classification.InterfaceStability;
28 import org.apache.hadoop.hbase.TableName;
29 import org.apache.hadoop.hbase.HConstants;
30 import org.apache.hadoop.hbase.util.Bytes;
31 import org.apache.hadoop.mapred.InputSplit;
32
33
34
35
36 @InterfaceAudience.Public
37 @InterfaceStability.Stable
38 public class TableSplit implements InputSplit, Comparable<TableSplit> {
39 private TableName m_tableName;
40 private byte [] m_startRow;
41 private byte [] m_endRow;
42 private String m_regionLocation;
43
44
45 public TableSplit() {
46 this((TableName)null, HConstants.EMPTY_BYTE_ARRAY,
47 HConstants.EMPTY_BYTE_ARRAY, "");
48 }
49
50
51
52
53
54
55
56
57 public TableSplit(TableName tableName, byte [] startRow, byte [] endRow,
58 final String location) {
59 this.m_tableName = tableName;
60 this.m_startRow = startRow;
61 this.m_endRow = endRow;
62 this.m_regionLocation = location;
63 }
64
65 public TableSplit(byte [] tableName, byte [] startRow, byte [] endRow,
66 final String location) {
67 this(TableName.valueOf(tableName), startRow, endRow,
68 location);
69 }
70
71
72 public TableName getTable() {
73 return this.m_tableName;
74 }
75
76
77 public byte [] getTableName() {
78 return this.m_tableName.getName();
79 }
80
81
82 public byte [] getStartRow() {
83 return this.m_startRow;
84 }
85
86
87 public byte [] getEndRow() {
88 return this.m_endRow;
89 }
90
91
92 public String getRegionLocation() {
93 return this.m_regionLocation;
94 }
95
96 public String[] getLocations() {
97 return new String[] {this.m_regionLocation};
98 }
99
100 public long getLength() {
101
102 return 0;
103 }
104
105 public void readFields(DataInput in) throws IOException {
106 this.m_tableName = TableName.valueOf(Bytes.readByteArray(in));
107 this.m_startRow = Bytes.readByteArray(in);
108 this.m_endRow = Bytes.readByteArray(in);
109 this.m_regionLocation = Bytes.toString(Bytes.readByteArray(in));
110 }
111
112 public void write(DataOutput out) throws IOException {
113 Bytes.writeByteArray(out, this.m_tableName.getName());
114 Bytes.writeByteArray(out, this.m_startRow);
115 Bytes.writeByteArray(out, this.m_endRow);
116 Bytes.writeByteArray(out, Bytes.toBytes(this.m_regionLocation));
117 }
118
119 @Override
120 public String toString() {
121 StringBuilder sb = new StringBuilder();
122 sb.append("HBase table split(");
123 sb.append("table name: ").append(m_tableName);
124 sb.append(", start row: ").append(Bytes.toStringBinary(m_startRow));
125 sb.append(", end row: ").append(Bytes.toStringBinary(m_endRow));
126 sb.append(", region location: ").append(m_regionLocation);
127 sb.append(")");
128 return sb.toString();
129 }
130
131 @Override
132 public int compareTo(TableSplit o) {
133 return Bytes.compareTo(getStartRow(), o.getStartRow());
134 }
135
136 @Override
137 public boolean equals(Object o) {
138 if (o == null || !(o instanceof TableSplit)) {
139 return false;
140 }
141 TableSplit other = (TableSplit)o;
142 return m_tableName.equals(other.m_tableName) &&
143 Bytes.equals(m_startRow, other.m_startRow) &&
144 Bytes.equals(m_endRow, other.m_endRow) &&
145 m_regionLocation.equals(other.m_regionLocation);
146 }
147
148 @Override
149 public int hashCode() {
150 int result = m_tableName != null ? m_tableName.hashCode() : 0;
151 result = 31 * result + Arrays.hashCode(m_startRow);
152 result = 31 * result + Arrays.hashCode(m_endRow);
153 result = 31 * result + (m_regionLocation != null ? m_regionLocation.hashCode() : 0);
154 return result;
155 }
156 }