1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.omid.transaction;
19
20 import org.apache.hadoop.hbase.Cell;
21 import org.apache.hadoop.hbase.CellUtil;
22 import org.apache.hadoop.hbase.KeyValue;
23 import org.apache.hadoop.hbase.KeyValueUtil;
24 import org.apache.hadoop.hbase.filter.Filter;
25 import org.apache.omid.OmidFilterBase;
26
27 import java.io.IOException;
28 import java.util.List;
29
30
31
32
33
34
35
36
37
38 public class CellSkipFilterBase extends OmidFilterBase {
39 private final Filter filter;
40
41 private KeyValue skipColumn = null;
42
43 public CellSkipFilterBase(Filter filter) {
44 this.filter = filter;
45 }
46
47
48
49
50
51
52
53
54 private boolean skipCellVersion(Cell cell) {
55 return skipColumn != null
56 && CellUtil.matchingRow(cell, skipColumn.getRowArray(), skipColumn.getRowOffset(),
57 skipColumn.getRowLength())
58 && CellUtil.matchingFamily(cell, skipColumn.getFamilyArray(), skipColumn.getFamilyOffset(),
59 skipColumn.getFamilyLength())
60 && CellUtil.matchingQualifier(cell, skipColumn.getQualifierArray(), skipColumn.getQualifierOffset(),
61 skipColumn.getQualifierLength());
62 }
63
64 @Override
65 public ReturnCode filterKeyValue(Cell cell) throws IOException {
66 if (skipCellVersion(cell)) {
67 return ReturnCode.NEXT_COL;
68 }
69
70 ReturnCode code = filter.filterKeyValue(cell);
71 if (code == ReturnCode.NEXT_COL || code == ReturnCode.INCLUDE_AND_NEXT_COL) {
72
73 skipColumn = KeyValueUtil.createFirstOnRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
74 cell.getFamilyArray(), cell.getFamilyOffset(),
75 cell.getFamilyLength(), cell.getQualifierArray(),
76 cell.getQualifierOffset(), cell.getQualifierLength());
77 } else {
78 skipColumn = null;
79 }
80 return code;
81 }
82
83 @Override
84 public boolean filterRow() throws IOException {
85 return filter.filterRow();
86 }
87
88 @Override
89 public Cell transformCell(Cell cell) throws IOException {
90 return filter.transformCell(cell);
91 }
92
93 @Override
94 public void reset() throws IOException {
95 filter.reset();
96 }
97
98 @Override
99 public boolean filterRowKey(byte[] buffer, int offset, int length) throws IOException {
100 return filter.filterRowKey(buffer, offset, length);
101 }
102
103 @Override
104 public boolean filterAllRemaining() throws IOException {
105 return filter.filterAllRemaining();
106 }
107
108 @Override
109 public void filterRowCells(List<Cell> kvs) throws IOException {
110 filter.filterRowCells(kvs);
111 }
112
113 @Override
114 public boolean hasFilterRow() {
115 return filter.hasFilterRow();
116 }
117
118 @Override
119 public Cell getNextCellHint(Cell currentKV) throws IOException {
120 return filter.getNextCellHint(currentKV);
121 }
122
123 @Override
124 public boolean isFamilyEssential(byte[] name) throws IOException {
125 return filter.isFamilyEssential(name);
126 }
127
128 @Override
129 public byte[] toByteArray() throws IOException {
130 return filter.toByteArray();
131 }
132
133 public Filter getInnerFilter() {
134 return filter;
135 }
136 }