View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
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  
25  import org.apache.hadoop.hbase.HConstants;
26  import org.apache.hadoop.hbase.util.Bytes;
27  import org.apache.hadoop.mapred.InputSplit;
28  
29  /**
30   * A table split corresponds to a key range [low, high)
31   */
32  @Deprecated
33  public class TableSplit implements InputSplit, Comparable<TableSplit> {
34    private byte [] m_tableName;
35    private byte [] m_startRow;
36    private byte [] m_endRow;
37    private String m_regionLocation;
38  
39    /** default constructor */
40    public TableSplit() {
41      this(HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY,
42        HConstants.EMPTY_BYTE_ARRAY, "");
43    }
44  
45    /**
46     * Constructor
47     * @param tableName
48     * @param startRow
49     * @param endRow
50     * @param location
51     */
52    public TableSplit(byte [] tableName, byte [] startRow, byte [] endRow,
53        final String location) {
54      this.m_tableName = tableName;
55      this.m_startRow = startRow;
56      this.m_endRow = endRow;
57      this.m_regionLocation = location;
58    }
59  
60    /** @return table name */
61    public byte [] getTableName() {
62      return this.m_tableName;
63    }
64  
65    /** @return starting row key */
66    public byte [] getStartRow() {
67      return this.m_startRow;
68    }
69  
70    /** @return end row key */
71    public byte [] getEndRow() {
72      return this.m_endRow;
73    }
74  
75    /** @return the region's hostname */
76    public String getRegionLocation() {
77      return this.m_regionLocation;
78    }
79  
80    public String[] getLocations() {
81      return new String[] {this.m_regionLocation};
82    }
83  
84    public long getLength() {
85      // Not clear how to obtain this... seems to be used only for sorting splits
86      return 0;
87    }
88  
89    public void readFields(DataInput in) throws IOException {
90      this.m_tableName = Bytes.readByteArray(in);
91      this.m_startRow = Bytes.readByteArray(in);
92      this.m_endRow = Bytes.readByteArray(in);
93      this.m_regionLocation = Bytes.toString(Bytes.readByteArray(in));
94    }
95  
96    public void write(DataOutput out) throws IOException {
97      Bytes.writeByteArray(out, this.m_tableName);
98      Bytes.writeByteArray(out, this.m_startRow);
99      Bytes.writeByteArray(out, this.m_endRow);
100     Bytes.writeByteArray(out, Bytes.toBytes(this.m_regionLocation));
101   }
102 
103   @Override
104   public String toString() {
105     return m_regionLocation + ":" +
106       Bytes.toStringBinary(m_startRow) + "," + Bytes.toStringBinary(m_endRow);
107   }
108 
109   @Override
110   public int compareTo(TableSplit o) {
111     return Bytes.compareTo(getStartRow(), o.getStartRow());
112   }
113 
114   @Override
115   public boolean equals(Object o) {
116     if (o == null || !(o instanceof TableSplit)) {
117       return false;
118     }
119     TableSplit other = (TableSplit)o;
120     return Bytes.equals(m_tableName, other.m_tableName) &&
121       Bytes.equals(m_startRow, other.m_startRow) &&
122       Bytes.equals(m_endRow, other.m_endRow) &&
123       m_regionLocation.equals(other.m_regionLocation);
124   }
125 }