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.IOException;
22  
23  import org.apache.hadoop.classification.InterfaceAudience;
24  import org.apache.hadoop.classification.InterfaceStability;
25  import org.apache.hadoop.hbase.client.HTable;
26  import org.apache.hadoop.hbase.client.Result;
27  import org.apache.hadoop.hbase.client.Table;
28  import org.apache.hadoop.hbase.filter.Filter;
29  import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
30  import org.apache.hadoop.mapred.RecordReader;
31  
32  
33  /**
34   * Iterate over an HBase table data, return (Text, RowResult) pairs
35   */
36  @Deprecated
37  @InterfaceAudience.Public
38  @InterfaceStability.Stable
39  public class TableRecordReader
40  implements RecordReader<ImmutableBytesWritable, Result> {
41  
42    private TableRecordReaderImpl recordReaderImpl = new TableRecordReaderImpl();
43  
44    /**
45     * Restart from survivable exceptions by creating a new scanner.
46     *
47     * @param firstRow
48     * @throws IOException
49     */
50    public void restart(byte[] firstRow) throws IOException {
51      this.recordReaderImpl.restart(firstRow);
52    }
53  
54    /**
55     * Build the scanner. Not done in constructor to allow for extension.
56     *
57     * @throws IOException
58     */
59    public void init() throws IOException {
60      this.recordReaderImpl.restart(this.recordReaderImpl.getStartRow());
61    }
62  
63    /**
64     * @param htable the {@link HTable} to scan.
65     */
66    public void setHTable(Table htable) {
67      this.recordReaderImpl.setHTable(htable);
68    }
69  
70    /**
71     * @param inputColumns the columns to be placed in {@link Result}.
72     */
73    public void setInputColumns(final byte [][] inputColumns) {
74      this.recordReaderImpl.setInputColumns(inputColumns);
75    }
76  
77    /**
78     * @param startRow the first row in the split
79     */
80    public void setStartRow(final byte [] startRow) {
81      this.recordReaderImpl.setStartRow(startRow);
82    }
83  
84    /**
85     *
86     * @param endRow the last row in the split
87     */
88    public void setEndRow(final byte [] endRow) {
89      this.recordReaderImpl.setEndRow(endRow);
90    }
91  
92    /**
93     * @param rowFilter the {@link Filter} to be used.
94     */
95    public void setRowFilter(Filter rowFilter) {
96      this.recordReaderImpl.setRowFilter(rowFilter);
97    }
98  
99    public void close() {
100     this.recordReaderImpl.close();
101   }
102 
103   /**
104    * @return ImmutableBytesWritable
105    *
106    * @see org.apache.hadoop.mapred.RecordReader#createKey()
107    */
108   public ImmutableBytesWritable createKey() {
109     return this.recordReaderImpl.createKey();
110   }
111 
112   /**
113    * @return RowResult
114    *
115    * @see org.apache.hadoop.mapred.RecordReader#createValue()
116    */
117   public Result createValue() {
118     return this.recordReaderImpl.createValue();
119   }
120 
121   public long getPos() {
122 
123     // This should be the ordinal tuple in the range;
124     // not clear how to calculate...
125     return this.recordReaderImpl.getPos();
126   }
127 
128   public float getProgress() {
129     // Depends on the total number of tuples and getPos
130     return this.recordReaderImpl.getPos();
131   }
132 
133   /**
134    * @param key HStoreKey as input key.
135    * @param value MapWritable as input value
136    * @return true if there was more data
137    * @throws IOException
138    */
139   public boolean next(ImmutableBytesWritable key, Result value)
140   throws IOException {
141     return this.recordReaderImpl.next(key, value);
142   }
143 }