001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.regionserver.querymatcher;
019
020import java.io.IOException;
021
022import org.apache.hadoop.hbase.Cell;
023import org.apache.yetus.audience.InterfaceAudience;
024import org.apache.hadoop.hbase.client.Scan;
025import org.apache.hadoop.hbase.regionserver.ScanInfo;
026
027/**
028 * Query matcher for raw scan.
029 */
030@InterfaceAudience.Private
031public abstract class RawScanQueryMatcher extends UserScanQueryMatcher {
032
033  protected RawScanQueryMatcher(Scan scan, ScanInfo scanInfo, ColumnTracker columns,
034      boolean hasNullColumn, long oldestUnexpiredTS, long now) {
035    super(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS, now);
036  }
037
038  @Override
039  public MatchCode match(Cell cell) throws IOException {
040    if (filter != null && filter.filterAllRemaining()) {
041      return MatchCode.DONE_SCAN;
042    }
043    MatchCode returnCode = preCheck(cell);
044    if (returnCode != null) {
045      return returnCode;
046    }
047    long timestamp = cell.getTimestamp();
048    byte typeByte = cell.getTypeByte();
049    // For a raw scan, we do not filter out any cells by delete marker, and delete marker is also
050    // returned, so we do not need to track delete.
051    return matchColumn(cell, timestamp, typeByte);
052  }
053
054  @Override
055  protected void reset() {
056  }
057
058  @Override
059  protected boolean isGet() {
060    return false;
061  }
062
063  public static RawScanQueryMatcher create(Scan scan, ScanInfo scanInfo, ColumnTracker columns,
064      boolean hasNullColumn, long oldestUnexpiredTS, long now) {
065    if (scan.isReversed()) {
066      if (scan.includeStopRow()) {
067        return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS,
068            now) {
069
070          @Override
071          protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
072            return cmpToStopRow >= 0;
073          }
074        };
075      } else {
076        return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS,
077            now) {
078
079          @Override
080          protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
081            return cmpToStopRow > 0;
082          }
083        };
084      }
085    } else {
086      if (scan.includeStopRow()) {
087        return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS,
088            now) {
089
090          @Override
091          protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
092            return cmpToStopRow <= 0;
093          }
094        };
095      } else {
096        return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS,
097            now) {
098
099          @Override
100          protected boolean moreRowsMayExistsAfter(int cmpToStopRow) {
101            return cmpToStopRow < 0;
102          }
103        };
104      }
105    }
106  }
107}