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.filter; 019 020import java.io.IOException; 021import java.util.ArrayList; 022import java.util.List; 023import org.apache.hadoop.hbase.Cell; 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * Abstract base class to help you implement new Filters. Common "ignore" or NOOP type methods can 028 * go here, helping to reduce boiler plate in an ever-expanding filter library. If you could 029 * instantiate FilterBase, it would end up being a "null" filter - that is one that never filters 030 * anything. 031 */ 032@InterfaceAudience.Private // TODO add filter limited private level 033public abstract class FilterBase extends Filter { 034 035 /** 036 * Filters that are purely stateless and do nothing in their reset() methods can inherit this 037 * null/empty implementation. {@inheritDoc} 038 */ 039 @Override 040 public void reset() throws IOException { 041 } 042 043 @Override 044 public boolean filterRowKey(Cell cell) throws IOException { 045 return filterAllRemaining(); 046 } 047 048 /** 049 * Filters that never filter all remaining can inherit this implementation that never stops the 050 * filter early. {@inheritDoc} 051 */ 052 @Override 053 public boolean filterAllRemaining() throws IOException { 054 return false; 055 } 056 057 /** 058 * By default no transformation takes place {@inheritDoc} 059 */ 060 @Override 061 public Cell transformCell(Cell v) throws IOException { 062 return v; 063 } 064 065 /** 066 * Filters that never filter by modifying the returned List of Cells can inherit this 067 * implementation that does nothing. {@inheritDoc} 068 */ 069 @Override 070 public void filterRowCells(List<Cell> ignored) throws IOException { 071 } 072 073 /** 074 * Filters that never filter by modifying the returned List of Cells can inherit this 075 * implementation that does nothing. {@inheritDoc} 076 */ 077 @Override 078 public boolean hasFilterRow() { 079 return false; 080 } 081 082 /** 083 * Filters that never filter by rows based on previously gathered state from 084 * {@link #filterCell(Cell)} can inherit this implementation that never filters a row. 085 * {@inheritDoc} 086 */ 087 @Override 088 public boolean filterRow() throws IOException { 089 return false; 090 } 091 092 /** 093 * Filters that are not sure which key must be next seeked to, can inherit this implementation 094 * that, by default, returns a null Cell. {@inheritDoc} 095 */ 096 @Override 097 public Cell getNextCellHint(Cell currentCell) throws IOException { 098 return null; 099 } 100 101 /** 102 * By default, we require all scan's column families to be present. Our subclasses may be more 103 * precise. {@inheritDoc} 104 */ 105 @Override 106 public boolean isFamilyEssential(byte[] name) throws IOException { 107 return true; 108 } 109 110 /** 111 * Given the filter's arguments it constructs the filter 112 * <p> 113 * @param filterArguments the filter's arguments 114 * @return constructed filter object 115 */ 116 public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments) { 117 throw new IllegalArgumentException("This method has not been implemented"); 118 } 119 120 /** 121 * Return filter's info for debugging and logging purpose. 122 */ 123 @Override 124 public String toString() { 125 return this.getClass().getSimpleName(); 126 } 127 128 /** 129 * Return length 0 byte array for Filters that don't require special serialization 130 */ 131 @Override 132 public byte[] toByteArray() throws IOException { 133 return new byte[0]; 134 } 135 136 /** 137 * Default implementation so that writers of custom filters aren't forced to implement. 138 * @return true if and only if the fields of the filter that are serialized are equal to the 139 * corresponding fields in other. Used for testing. 140 */ 141 @Override 142 boolean areSerializedFieldsEqual(Filter other) { 143 return true; 144 } 145}