View Javadoc

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