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.util; 019 020import java.io.IOException; 021import java.io.OutputStream; 022import java.nio.ByteBuffer; 023import org.apache.hadoop.hbase.ByteBufferExtendedCell; 024import org.apache.hadoop.hbase.CellUtil; 025import org.apache.hadoop.hbase.ExtendedCell; 026import org.apache.hadoop.hbase.PrivateCellUtil; 027import org.apache.yetus.audience.InterfaceAudience; 028 029/** 030 * A wrapper for a cell to be used with mapreduce, as the output value class for mappers/reducers. 031 */ 032@InterfaceAudience.Private 033public class MapReduceExtendedCell extends ByteBufferExtendedCell { 034 035 private final ExtendedCell cell; 036 037 public MapReduceExtendedCell(ExtendedCell cell) { 038 this.cell = cell; 039 } 040 041 @Override 042 public byte[] getRowArray() { 043 return this.cell.getRowArray(); 044 } 045 046 @Override 047 public int getRowOffset() { 048 return this.cell.getRowOffset(); 049 } 050 051 @Override 052 public short getRowLength() { 053 return this.cell.getRowLength(); 054 } 055 056 @Override 057 public byte[] getFamilyArray() { 058 return this.cell.getFamilyArray(); 059 } 060 061 @Override 062 public int getFamilyOffset() { 063 return this.cell.getFamilyOffset(); 064 } 065 066 @Override 067 public byte getFamilyLength() { 068 return this.cell.getFamilyLength(); 069 } 070 071 @Override 072 public byte[] getQualifierArray() { 073 return this.cell.getQualifierArray(); 074 } 075 076 @Override 077 public int getQualifierOffset() { 078 return this.cell.getQualifierOffset(); 079 } 080 081 @Override 082 public int getQualifierLength() { 083 return this.cell.getQualifierLength(); 084 } 085 086 @Override 087 public long getTimestamp() { 088 return this.cell.getTimestamp(); 089 } 090 091 @Override 092 public byte getTypeByte() { 093 return this.cell.getTypeByte(); 094 } 095 096 @Override 097 public long getSequenceId() { 098 return this.cell.getSequenceId(); 099 } 100 101 @Override 102 public byte[] getValueArray() { 103 return this.cell.getValueArray(); 104 } 105 106 @Override 107 public int getValueOffset() { 108 return this.cell.getValueOffset(); 109 } 110 111 @Override 112 public int getValueLength() { 113 return this.cell.getValueLength(); 114 } 115 116 @Override 117 public byte[] getTagsArray() { 118 return this.cell.getTagsArray(); 119 } 120 121 @Override 122 public int getTagsOffset() { 123 return this.cell.getTagsOffset(); 124 } 125 126 @Override 127 public int getTagsLength() { 128 return this.cell.getTagsLength(); 129 } 130 131 @Override 132 public ByteBuffer getRowByteBuffer() { 133 if (cell instanceof ByteBufferExtendedCell) { 134 return ((ByteBufferExtendedCell) this.cell).getRowByteBuffer(); 135 } else { 136 return ByteBuffer.wrap(CellUtil.cloneRow(this.cell)); 137 } 138 } 139 140 @Override 141 public int getRowPosition() { 142 if (cell instanceof ByteBufferExtendedCell) { 143 return ((ByteBufferExtendedCell) this.cell).getRowPosition(); 144 } else { 145 return 0; 146 } 147 } 148 149 @Override 150 public ByteBuffer getFamilyByteBuffer() { 151 if (cell instanceof ByteBufferExtendedCell) { 152 return ((ByteBufferExtendedCell) this.cell).getFamilyByteBuffer(); 153 } else { 154 return ByteBuffer.wrap(CellUtil.cloneFamily(this.cell)); 155 } 156 } 157 158 @Override 159 public int getFamilyPosition() { 160 if (cell instanceof ByteBufferExtendedCell) { 161 return ((ByteBufferExtendedCell) this.cell).getFamilyPosition(); 162 } else { 163 return 0; 164 } 165 } 166 167 @Override 168 public ByteBuffer getQualifierByteBuffer() { 169 if (cell instanceof ByteBufferExtendedCell) { 170 return ((ByteBufferExtendedCell) this.cell).getQualifierByteBuffer(); 171 } else { 172 return ByteBuffer.wrap(CellUtil.cloneQualifier(this.cell)); 173 } 174 } 175 176 @Override 177 public int getQualifierPosition() { 178 if (cell instanceof ByteBufferExtendedCell) { 179 return ((ByteBufferExtendedCell) this.cell).getQualifierPosition(); 180 } else { 181 return 0; 182 } 183 } 184 185 @Override 186 public ByteBuffer getValueByteBuffer() { 187 if (cell instanceof ByteBufferExtendedCell) { 188 return ((ByteBufferExtendedCell) this.cell).getValueByteBuffer(); 189 } else { 190 return ByteBuffer.wrap(CellUtil.cloneValue(this.cell)); 191 } 192 } 193 194 @Override 195 public int getValuePosition() { 196 if (cell instanceof ByteBufferExtendedCell) { 197 return ((ByteBufferExtendedCell) this.cell).getValuePosition(); 198 } else { 199 return 0; 200 } 201 } 202 203 @Override 204 public ByteBuffer getTagsByteBuffer() { 205 if (cell instanceof ByteBufferExtendedCell) { 206 return ((ByteBufferExtendedCell) this.cell).getTagsByteBuffer(); 207 } else { 208 return ByteBuffer.wrap(PrivateCellUtil.cloneTags(this.cell)); 209 } 210 } 211 212 @Override 213 public int getTagsPosition() { 214 if (cell instanceof ByteBufferExtendedCell) { 215 return ((ByteBufferExtendedCell) this.cell).getTagsPosition(); 216 } else { 217 return 0; 218 } 219 } 220 221 @Override 222 public String toString() { 223 return this.cell.toString(); 224 } 225 226 @Override 227 public void setSequenceId(long seqId) throws IOException { 228 cell.setSequenceId(seqId); 229 } 230 231 @Override 232 public void setTimestamp(long ts) throws IOException { 233 cell.setTimestamp(ts); 234 } 235 236 @Override 237 public void setTimestamp(byte[] ts) throws IOException { 238 cell.setTimestamp(ts); 239 } 240 241 @Override 242 public long heapSize() { 243 return cell.heapSize(); 244 } 245 246 @Override 247 public int write(OutputStream out, boolean withTags) throws IOException { 248 return cell.write(out, withTags); 249 } 250 251 @Override 252 public int getSerializedSize(boolean withTags) { 253 return PrivateCellUtil.estimatedSerializedSizeOf(cell) - Bytes.SIZEOF_INT; 254 } 255 256 @Override 257 public void write(ByteBuffer buf, int offset) { 258 cell.write(buf, offset); 259 } 260 261 @Override 262 public ExtendedCell deepClone() { 263 return cell.deepClone(); 264 } 265}