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; 021import org.apache.hadoop.hbase.ExtendedCell; 022import org.apache.hadoop.hbase.client.Scan; 023import org.apache.hadoop.hbase.regionserver.ScanInfo; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * Query matcher for raw scan. 028 */ 029@InterfaceAudience.Private 030public abstract class RawScanQueryMatcher extends UserScanQueryMatcher { 031 032 protected RawScanQueryMatcher(Scan scan, ScanInfo scanInfo, ColumnTracker columns, 033 boolean hasNullColumn, long oldestUnexpiredTS, long now) { 034 super(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS, now); 035 } 036 037 @Override 038 public MatchCode match(ExtendedCell cell) throws IOException { 039 if (filter != null && filter.filterAllRemaining()) { 040 return MatchCode.DONE_SCAN; 041 } 042 MatchCode returnCode = preCheck(cell); 043 if (returnCode != null) { 044 return returnCode; 045 } 046 long timestamp = cell.getTimestamp(); 047 byte typeByte = cell.getTypeByte(); 048 // For a raw scan, we do not filter out any cells by delete marker, and delete marker is also 049 // returned, so we do not need to track delete. 050 return matchColumn(cell, timestamp, typeByte); 051 } 052 053 @Override 054 protected void reset() { 055 } 056 057 @Override 058 protected boolean isGet() { 059 return false; 060 } 061 062 public static RawScanQueryMatcher create(Scan scan, ScanInfo scanInfo, ColumnTracker columns, 063 boolean hasNullColumn, long oldestUnexpiredTS, long now) { 064 if (scan.isReversed()) { 065 if (scan.includeStopRow()) { 066 return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS, 067 now) { 068 069 @Override 070 protected boolean moreRowsMayExistsAfter(int cmpToStopRow) { 071 return cmpToStopRow >= 0; 072 } 073 }; 074 } else { 075 return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS, 076 now) { 077 078 @Override 079 protected boolean moreRowsMayExistsAfter(int cmpToStopRow) { 080 return cmpToStopRow > 0; 081 } 082 }; 083 } 084 } else { 085 if (scan.includeStopRow()) { 086 return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS, 087 now) { 088 089 @Override 090 protected boolean moreRowsMayExistsAfter(int cmpToStopRow) { 091 return cmpToStopRow <= 0; 092 } 093 }; 094 } else { 095 return new RawScanQueryMatcher(scan, scanInfo, columns, hasNullColumn, oldestUnexpiredTS, 096 now) { 097 098 @Override 099 protected boolean moreRowsMayExistsAfter(int cmpToStopRow) { 100 return cmpToStopRow < 0; 101 } 102 }; 103 } 104 } 105 } 106}