View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver.querymatcher;
19  
20  import java.io.IOException;
21  
22  import org.apache.hadoop.hbase.Cell;
23  import org.apache.hadoop.hbase.classification.InterfaceAudience;
24  import org.apache.hadoop.hbase.client.Scan;
25  import org.apache.hadoop.hbase.regionserver.ScanInfo;
26  
27  /**
28   * Query matcher for raw scan.
29   */
30  @InterfaceAudience.Private
31  public abstract class RawScanQueryMatcher extends UserScanQueryMatcher {
32  
33    protected RawScanQueryMatcher(Scan scan, ScanInfo scanInfo, ColumnTracker columns,
34        boolean hasNullColumn, long oldestUnexpiredTS, long now) {
35      super(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS, now);
36    }
37  
38    @Override
39    public MatchCode match(Cell cell) throws IOException {
40      if (filter != null && filter.filterAllRemaining()) {
41        return MatchCode.DONE_SCAN;
42      }
43      MatchCode returnCode = preCheck(cell);
44      if (returnCode != null) {
45        return returnCode;
46      }
47      long timestamp = cell.getTimestamp();
48      byte typeByte = cell.getTypeByte();
49      // For a raw scan, we do not filter out any cells by delete marker, and delete marker is also
50      // returned, so we do not need to track delete.
51      return matchColumn(cell, timestamp, typeByte);
52    }
53  
54    @Override
55    protected void reset() {
56    }
57  
58    @Override
59    protected boolean isGet() {
60      return false;
61    }
62  
63    public static RawScanQueryMatcher create(Scan scan, ScanInfo scanInfo, ColumnTracker columns,
64        boolean hasNullColumn, long oldestUnexpiredTS, long now) {
65      if (scan.isReversed()) {
66        if (scan.includeStopRow()) {
67          return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS,
68              now) {
69  
70            @Override
71            protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
72              return cmpToStopRow >= 0;
73            }
74          };
75        } else {
76          return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS,
77              now) {
78  
79            @Override
80            protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
81              return cmpToStopRow > 0;
82            }
83          };
84        }
85      } else {
86        if (scan.includeStopRow()) {
87          return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS,
88              now) {
89  
90            @Override
91            protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
92              return cmpToStopRow <= 0;
93            }
94          };
95        } else {
96          return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS,
97              now) {
98  
99            @Override
100           protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
101             return cmpToStopRow < 0;
102           }
103         };
104       }
105     }
106   }
107 }