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