aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/parallelai/spyglass/hbase/HBaseRecordReaderBase.java
blob: e0d0cbe8260abba6187adc5eef88aba7304f9e28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package parallelai.spyglass.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ScannerCallable;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.mapred.RecordReader;

import java.util.TreeSet;

import static org.apache.hadoop.hbase.mapreduce.TableRecordReaderImpl.LOG_PER_ROW_COUNT;

/**
 * Created with IntelliJ IDEA.
 * User: chand_000
 * Date: 29/08/13
 * Time: 15:42
 * To change this template use File | Settings | File Templates.
 */
public abstract class HBaseRecordReaderBase implements
        RecordReader<ImmutableBytesWritable, Result> {

    protected TreeSet<String> keyList;
    protected long initialNoOfKeys = 0;
    protected HBaseConstants.SourceMode sourceMode;
    protected boolean endRowInclusive = true;
    protected int versions = 1;
    protected boolean useSalt = false;

    protected byte[] startRow;
    protected byte[] endRow;

    protected HTable htable;
    protected byte[][] trrInputColumns;

    protected Filter trrRowFilter;

    protected boolean logScannerActivity = false;
    protected int logPerRowCount = 100;
    protected int noOfLogCount = 0;

    @Override
    public String toString() {
        StringBuffer sbuf = new StringBuffer();

        sbuf.append("".format("HBaseRecordReaderRegional : startRow [%s] endRow [%s] endRowInc [%s] ",
                Bytes.toString(startRow), Bytes.toString(endRow), endRowInclusive));
        sbuf.append("".format(" sourceMode [%s] salt [%s] versions [%s] ",
                sourceMode, useSalt, versions));

        return sbuf.toString();
    }

    byte[] getStartRow() {
        return this.startRow;
    }

    /**
     * @param htable
     *          the {@link org.apache.hadoop.hbase.client.HTable} to scan.
     */
    public void setHTable(HTable htable) {
        Configuration conf = htable.getConfiguration();
        logScannerActivity = conf.getBoolean(ScannerCallable.LOG_SCANNER_ACTIVITY,
                false);
        logPerRowCount = conf.getInt(LOG_PER_ROW_COUNT, 100);
        this.htable = htable;
    }

    /**
     * @param inputColumns
     *          the columns to be placed in {@link Result}.
     */
    public void setInputColumns(final byte[][] inputColumns) {
        this.trrInputColumns = inputColumns;
    }

    /**
     * @param startRow
     *          the first row in the split
     */
    public void setStartRow(final byte[] startRow) {
        this.startRow = startRow;
    }

    /**
     *
     * @param endRow
     *          the last row in the split
     */
    public void setEndRow(final byte[] endRow) {
        this.endRow = endRow;
    }

    /**
     * @param rowFilter
     *          the {@link org.apache.hadoop.hbase.filter.Filter} to be used.
     */
    public void setRowFilter(Filter rowFilter) {
        this.trrRowFilter = rowFilter;
    }

    public TreeSet<String> getKeyList() {
        return keyList;
    }

    public void setKeyList(TreeSet<String> keyList) {
        this.keyList = keyList;
        initialNoOfKeys = (this.keyList == null) ? 0 : this.keyList.size();
    }

    public void setVersions(int versions) {
        this.versions = versions;
    }

    public void setUseSalt(boolean useSalt) {
        this.useSalt = useSalt;
    }

    public HBaseConstants.SourceMode getSourceMode() {
        return sourceMode;
    }

    public void setSourceMode(HBaseConstants.SourceMode sourceMode) {
        this.sourceMode = sourceMode;
    }

    public byte[] getEndRow() {
        return endRow;
    }

    public void setEndRowInclusive(boolean isInclusive) {
        endRowInclusive = isInclusive;
    }

    public boolean getEndRowInclusive() {
        return endRowInclusive;
    }

}