HBASE-19746 Add default impl to Cell#getType
This commit is contained in:
parent
1a11fc92b1
commit
3e6f80dcd5
|
@ -152,10 +152,6 @@ public class ByteBufferKeyOnlyKeyValue extends ByteBufferExtendedCell {
|
||||||
return ByteBufferUtils.toByte(this.buf, this.offset + this.length - 1);
|
return ByteBufferUtils.toByte(this.buf, this.offset + this.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
|
||||||
return PrivateCellUtil.toType(getTypeByte());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSequenceId(long seqId) throws IOException {
|
public void setSequenceId(long seqId) throws IOException {
|
||||||
throw new IllegalArgumentException("This is a key only Cell");
|
throw new IllegalArgumentException("This is a key only Cell");
|
||||||
|
|
|
@ -201,10 +201,19 @@ public interface Cell {
|
||||||
int getTagsLength();
|
int getTagsLength();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the type of cell in a human readable format using {@link Type}
|
* Returns the type of cell in a human readable format using {@link Type}.
|
||||||
|
* Note : This does not expose the internal types of Cells like {@link KeyValue.Type#Maximum} and
|
||||||
|
* {@link KeyValue.Type#Minimum}
|
||||||
* @return The data type this cell: one of Put, Delete, etc
|
* @return The data type this cell: one of Put, Delete, etc
|
||||||
*/
|
*/
|
||||||
Type getType();
|
default Type getType() {
|
||||||
|
byte byteType = getTypeByte();
|
||||||
|
Type t = Type.CODE_ARRAY[byteType & 0xff];
|
||||||
|
if (t != null) {
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
throw new UnsupportedOperationException("Invalid type of cell " + byteType);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The valid types for user to build the cell. Currently, This is subset of {@link KeyValue.Type}.
|
* The valid types for user to build the cell. Currently, This is subset of {@link KeyValue.Type}.
|
||||||
|
@ -229,5 +238,13 @@ public interface Cell {
|
||||||
public byte getCode() {
|
public byte getCode() {
|
||||||
return this.code;
|
return this.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Type[] CODE_ARRAY = new Type[256];
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (Type t : Type.values()) {
|
||||||
|
CODE_ARRAY[t.code & 0xff] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,17 +162,6 @@ public interface ExtendedCell extends RawCell, HeapSize, Cloneable {
|
||||||
*/
|
*/
|
||||||
int getTagsLength();
|
int getTagsLength();
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
* <p>
|
|
||||||
* Note : This does not expose the internal types of Cells like {@link KeyValue.Type#Maximum} and
|
|
||||||
* {@link KeyValue.Type#Minimum}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
default Type getType() {
|
|
||||||
return PrivateCellUtil.toType(getTypeByte());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The byte representation of the KeyValue.TYPE of this cell: one of Put, Delete, etc
|
* @return The byte representation of the KeyValue.TYPE of this cell: one of Put, Delete, etc
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.hadoop.hbase;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -36,6 +37,7 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.experimental.categories.Category;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
@Category({MiscTests.class, SmallTests.class})
|
@Category({MiscTests.class, SmallTests.class})
|
||||||
public class TestCellUtil {
|
public class TestCellUtil {
|
||||||
|
@ -195,11 +197,6 @@ public class TestCellUtil {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type getType() {
|
|
||||||
return PrivateCellUtil.toType(getTypeByte());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -382,7 +379,7 @@ public class TestCellUtil {
|
||||||
HConstants.EMPTY_BYTE_ARRAY);
|
HConstants.EMPTY_BYTE_ARRAY);
|
||||||
cellToString = CellUtil.getCellKeyAsString(cell);
|
cellToString = CellUtil.getCellKeyAsString(cell);
|
||||||
assertEquals(kv.toString(), cellToString);
|
assertEquals(kv.toString(), cellToString);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -522,6 +519,30 @@ public class TestCellUtil {
|
||||||
assertTrue(CellUtil.equals(kv, res));
|
assertTrue(CellUtil.equals(kv, res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetType() throws IOException {
|
||||||
|
Cell c = Mockito.mock(Cell.class);
|
||||||
|
Mockito.when(c.getType()).thenCallRealMethod();
|
||||||
|
for (Cell.Type type : Cell.Type.values()) {
|
||||||
|
Mockito.when(c.getTypeByte()).thenReturn(type.getCode());
|
||||||
|
assertEquals(type, c.getType());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Mockito.when(c.getTypeByte()).thenReturn(KeyValue.Type.Maximum.getCode());
|
||||||
|
c.getType();
|
||||||
|
fail("The code of Maximum can't be handled by Cell.Type");
|
||||||
|
} catch(UnsupportedOperationException e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Mockito.when(c.getTypeByte()).thenReturn(KeyValue.Type.Minimum.getCode());
|
||||||
|
c.getType();
|
||||||
|
fail("The code of Maximum can't be handled by Cell.Type");
|
||||||
|
} catch(UnsupportedOperationException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class NonExtendedCell implements Cell {
|
private static class NonExtendedCell implements Cell {
|
||||||
private KeyValue kv;
|
private KeyValue kv;
|
||||||
|
|
||||||
|
@ -618,10 +639,5 @@ public class TestCellUtil {
|
||||||
public int getTagsLength() {
|
public int getTagsLength() {
|
||||||
return this.kv.getTagsLength();
|
return this.kv.getTagsLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type getType() {
|
|
||||||
return PrivateCellUtil.toType(getTypeByte());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -737,10 +737,5 @@ public class TestKeyValue extends TestCase {
|
||||||
public byte[] getTagsArray() {
|
public byte[] getTagsArray() {
|
||||||
return this.kv.getTagsArray();
|
return this.kv.getTagsArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Type getType() {
|
|
||||||
return PrivateCellUtil.toType(getTypeByte());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class HFileSystem extends FilterFileSystem {
|
||||||
this.useHBaseChecksum = useHBaseChecksum;
|
this.useHBaseChecksum = useHBaseChecksum;
|
||||||
|
|
||||||
fs.initialize(getDefaultUri(conf), conf);
|
fs.initialize(getDefaultUri(conf), conf);
|
||||||
|
|
||||||
// disable checksum verification for local fileSystem, see HBASE-11218
|
// disable checksum verification for local fileSystem, see HBASE-11218
|
||||||
if (fs instanceof LocalFileSystem) {
|
if (fs instanceof LocalFileSystem) {
|
||||||
fs.setWriteChecksum(false);
|
fs.setWriteChecksum(false);
|
||||||
|
|
Loading…
Reference in New Issue