Search in sources :

Example 6 with ByteBufferCellImpl

use of org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl in project hbase by apache.

the class TestCellComparator method testCompareByteBufferedCell.

@Test
public void testCompareByteBufferedCell() {
    byte[] r1 = Bytes.toBytes("row1");
    byte[] r2 = Bytes.toBytes("row2");
    byte[] f1 = Bytes.toBytes("cf1");
    byte[] q1 = Bytes.toBytes("qual1");
    byte[] q2 = Bytes.toBytes("qual2");
    byte[] v = Bytes.toBytes("val1");
    KeyValue kv = new KeyValue(r1, f1, q1, v);
    ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer());
    Cell bbCell1 = new ByteBufferCellImpl(buffer, 0, buffer.remaining());
    kv = new KeyValue(r2, f1, q1, v);
    buffer = ByteBuffer.wrap(kv.getBuffer());
    Cell bbCell2 = new ByteBufferCellImpl(buffer, 0, buffer.remaining());
    assertEquals(0, CellComparator.compareColumns(bbCell1, bbCell2));
    assertEquals(0, CellComparator.compareColumns(bbCell1, kv));
    kv = new KeyValue(r2, f1, q2, v);
    buffer = ByteBuffer.wrap(kv.getBuffer());
    Cell bbCell3 = new ByteBufferCellImpl(buffer, 0, buffer.remaining());
    assertEquals(0, CellComparator.compareFamilies(bbCell2, bbCell3));
    assertTrue(CellComparator.compareQualifiers(bbCell2, bbCell3) < 0);
    assertTrue(CellComparator.compareColumns(bbCell2, bbCell3) < 0);
    assertEquals(0, CellComparator.COMPARATOR.compareRows(bbCell2, bbCell3));
    assertTrue(CellComparator.COMPARATOR.compareRows(bbCell1, bbCell2) < 0);
}
Also used : ByteBufferCellImpl(org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with ByteBufferCellImpl

use of org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl in project hbase by apache.

the class TestSingleColumnValueFilter method testLongComparator.

@Test
public void testLongComparator() throws IOException {
    Filter filter = new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER, CompareOp.GREATER, new LongComparator(100L));
    KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, Bytes.toBytes(1L));
    assertTrue("less than", filter.filterKeyValue(kv) == Filter.ReturnCode.NEXT_ROW);
    filter.reset();
    byte[] buffer = kv.getBuffer();
    Cell c = new ByteBufferCellImpl(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("less than", filter.filterKeyValue(c) == Filter.ReturnCode.NEXT_ROW);
    filter.reset();
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, Bytes.toBytes(100L));
    assertTrue("Equals 100", filter.filterKeyValue(kv) == Filter.ReturnCode.NEXT_ROW);
    filter.reset();
    buffer = kv.getBuffer();
    c = new ByteBufferCellImpl(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("Equals 100", filter.filterKeyValue(c) == Filter.ReturnCode.NEXT_ROW);
    filter.reset();
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, Bytes.toBytes(120L));
    assertTrue("include 120", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
    filter.reset();
    buffer = kv.getBuffer();
    c = new ByteBufferCellImpl(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("include 120", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ByteBufferCellImpl(org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 8 with ByteBufferCellImpl

use of org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl in project hbase by apache.

the class TestSingleColumnValueFilter method regexFilterTests.

private void regexFilterTests(Filter filter) throws Exception {
    KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, FULLSTRING_1);
    assertTrue("regexTrue", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
    byte[] buffer = kv.getBuffer();
    Cell c = new ByteBufferCellImpl(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("regexTrue", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE);
    kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, FULLSTRING_2);
    assertTrue("regexFalse", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
    buffer = kv.getBuffer();
    c = new ByteBufferCellImpl(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("regexFalse", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE);
    assertFalse("regexFilterAllRemaining", filter.filterAllRemaining());
    assertFalse("regexFilterNotNull", filter.filterRow());
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ByteBufferCellImpl(org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl) Cell(org.apache.hadoop.hbase.Cell)

Example 9 with ByteBufferCellImpl

use of org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl in project hbase by apache.

the class TestSingleColumnValueFilter method regexPatternFilterTests.

private void regexPatternFilterTests(Filter filter) throws Exception {
    KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, FULLSTRING_1);
    assertTrue("regexTrue", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
    byte[] buffer = kv.getBuffer();
    Cell c = new ByteBufferCellImpl(ByteBuffer.wrap(buffer), 0, buffer.length);
    assertTrue("regexTrue", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE);
    assertFalse("regexFilterAllRemaining", filter.filterAllRemaining());
    assertFalse("regexFilterNotNull", filter.filterRow());
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ByteBufferCellImpl(org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

ByteBufferCellImpl (org.apache.hadoop.hbase.TestCellUtil.ByteBufferCellImpl)9 KeyValue (org.apache.hadoop.hbase.KeyValue)8 Cell (org.apache.hadoop.hbase.Cell)7 Test (org.junit.Test)4 ByteBuffer (java.nio.ByteBuffer)3 KeyOnlyByteBufferCell (org.apache.hadoop.hbase.filter.KeyOnlyFilter.KeyOnlyByteBufferCell)1 KeyOnlyCell (org.apache.hadoop.hbase.filter.KeyOnlyFilter.KeyOnlyCell)1