001/*002 * Licensed to the Apache Software Foundation (ASF) under one003 * or more contributor license agreements. See the NOTICE file004 * distributed with this work for additional information005 * regarding copyright ownership. The ASF licenses this file006 * to you under the Apache License, Version 2.0 (the007 * "License"); you may not use this file except in compliance008 * with the License. You may obtain a copy of the License at009 *010 * http://www.apache.org/licenses/LICENSE-2.0011 *012 * Unless required by applicable law or agreed to in writing, software013 * 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 and016 * limitations under the License.017 */018package org.apache.hadoop.hbase;019020import java.util.Comparator;021022import org.apache.yetus.audience.InterfaceAudience;023import org.apache.yetus.audience.InterfaceStability;024025/**026 * Comparator for comparing cells and has some specialized methods that allows comparing individual027 * cell components like row, family, qualifier and timestamp028 */029@InterfaceAudience.Public030@InterfaceStability.Evolving031public interface CellComparator extends Comparator<Cell> {032 /**033 * A comparator for ordering cells in user-space tables. Useful when writing cells in sorted034 * order as necessary for bulk import (i.e. via MapReduce)035 * <p>036 * CAUTION: This comparator may provide inaccurate ordering for cells from system tables,037 * and should not be relied upon in that case.038 */039 static CellComparator getInstance() {040 return CellComparatorImpl.COMPARATOR;041 }042043 /**044 * Lexographically compares two cells. The key part of the cell is taken for comparison which045 * includes row, family, qualifier, timestamp and type046 * @param leftCell the left hand side cell047 * @param rightCell the right hand side cell048 * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both049 * cells are equal050 */051 @Override052 int compare(Cell leftCell, Cell rightCell);053054 /**055 * Compare cells.056 * @param ignoreSequenceid True if we are to compare the key portion only and ignore057 * the sequenceid. Set to false to compare key and consider sequenceid.058 * @return 0 if equal, -1 if a &lt; b, and +1 if a &gt; b.059 */060 int compare(Cell leftCell, Cell rightCell, boolean ignoreSequenceid);061062 /**063 * Lexographically compares the rows of two cells.064 * @param leftCell the left hand side cell065 * @param rightCell the right hand side cell066 * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both067 * cells are equal068 */069 int compareRows(Cell leftCell, Cell rightCell);070071 /**072 * Compares the row part of the cell with a simple plain byte[] like the073 * stopRow in Scan.074 * @param cell the cell075 * @param bytes the byte[] representing the row to be compared with076 * @param offset the offset of the byte[]077 * @param length the length of the byte[]078 * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both079 * cells are equal080 */081 int compareRows(Cell cell, byte[] bytes, int offset, int length);082083 /**084 * Lexographically compares the two cells excluding the row part. It compares family, qualifier,085 * timestamp and the type086 * @param leftCell the left hand side cell087 * @param rightCell the right hand side cell088 * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both089 * cells are equal090 */091 int compareWithoutRow(Cell leftCell, Cell rightCell);092093 /**094 * Lexographically compares the families of the two cells095 * @param leftCell the left hand side cell096 * @param rightCell the right hand side cell097 * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both098 * cells are equal099 */100 int compareFamilies(Cell leftCell, Cell rightCell);101102 /**103 * Lexographically compares the qualifiers of the two cells104 * @param leftCell the left hand side cell105 * @param rightCell the right hand side cell106 * @return greater than 0 if leftCell is bigger, less than 0 if rightCell is bigger, 0 if both107 * cells are equal108 */109 int compareQualifiers(Cell leftCell, Cell rightCell);110111 /**112 * Compares cell's timestamps in DESCENDING order. The below older timestamps sorting ahead of113 * newer timestamps looks wrong but it is intentional. This way, newer timestamps are first found114 * when we iterate over a memstore and newer versions are the first we trip over when reading from115 * a store file.116 * @param leftCell the left hand side cell117 * @param rightCell the right hand side cell118 * @return 1 if left's timestamp &lt; right's timestamp -1 if left's timestamp &gt; right's119 * timestamp 0 if both timestamps are equal120 */121 int compareTimestamps(Cell leftCell, Cell rightCell);122123 /**124 * Compares cell's timestamps in DESCENDING order. The below older timestamps sorting ahead of125 * newer timestamps looks wrong but it is intentional. This way, newer timestamps are first found126 * when we iterate over a memstore and newer versions are the first we trip over when reading from127 * a store file.128 * @param leftCellts the left cell's timestamp129 * @param rightCellts the right cell's timestamp130 * @return 1 if left's timestamp &lt; right's timestamp -1 if left's timestamp &gt; right's131 * timestamp 0 if both timestamps are equal132 */133 int compareTimestamps(long leftCellts, long rightCellts);134135 /**136 * @return A dumbed-down, fast comparator for hbase2 base-type, the {@link ByteBufferKeyValue}.137 * Create an instance when you make a new memstore, when you know only BBKVs will be passed.138 * Do not pollute with types other than BBKV if can be helped; the Comparator will slow.139 */140 Comparator getSimpleComparator();141}