Java Code Examples for org.apache.hadoop.hbase.KeyValue.Type#Delete

The following examples show how to use org.apache.hadoop.hbase.KeyValue.Type#Delete . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RowBasedIndexerTest.java    From hbase-indexer with Apache License 2.0 6 votes vote down vote up
@Test
public void testCalculateIndexUpdates_UpdateAndDeleteCombinedForSameCell_DeleteFirst() throws IOException {
    KeyValue toDelete = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes("_cf_"),
                                     Bytes.toBytes("_qual_"),
                                     0L,
                                     Type.Delete);
    KeyValue toAdd = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes("_cf_"),
                                  Bytes.toBytes("_qual_"),
                                  Bytes.toBytes("value"));
    RowData deleteEventRowData = createEventRowData("_row_", toDelete);
    RowData addEventRowData = createEventRowData("_row_", toAdd);

    indexer.calculateIndexUpdates(ImmutableList.of(deleteEventRowData, addEventRowData), updateCollector);

    assertTrue(updateCollector.getIdsToDelete().isEmpty());
    List<SolrInputDocument> documents = Lists.newArrayList(updateCollector.getDocumentsToAdd().values());
    assertEquals(1, documents.size());
    assertEquals("_row_", documents.get(0).getFieldValue("id"));
}
 
Example 2
Source File: RowBasedIndexerTest.java    From hbase-indexer with Apache License 2.0 6 votes vote down vote up
@Test
public void testCalculateIndexUpdates_UpdateAndDeleteCombinedForSameCell_UpdateFirst() throws IOException {
    KeyValue toAdd = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes("_cf_"),
                                  Bytes.toBytes("_qual_"),
                                  Bytes.toBytes("value"));
    KeyValue toDelete = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes("_cf_"),
                                     Bytes.toBytes("_qual_"),
                                     0L,
                                     Type.Delete);
    RowData addEventRowData = createEventRowData("_row_", toAdd);
    RowData deleteEventRowData = createEventRowData("_row_", toDelete);

    indexer.calculateIndexUpdates(Lists.newArrayList(addEventRowData, deleteEventRowData), updateCollector);

    assertEquals(Lists.newArrayList("_row_"), updateCollector.getIdsToDelete());
    assertTrue(updateCollector.getDocumentsToAdd().isEmpty());
}
 
Example 3
Source File: ColumnBasedIndexerTest.java    From hbase-indexer with Apache License 2.0 6 votes vote down vote up
@Test
public void testCalculateIndexUpdates_DeleteRow() throws IOException {
    final String ROW_FIELD = "_row_field_";
    
    doReturn(ROW_FIELD).when(indexerConf).getRowField();
    
    KeyValue toDelete = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes("_cf_"),
                                     Bytes.toBytes("_qual_"),
                                     0L, Type.Delete);
    RowData eventRowData = createEventRowData("_row_", toDelete);
    
    indexer.calculateIndexUpdates(ImmutableList.of(eventRowData), updateCollector);

    assertEquals(ImmutableList.of(ROW_FIELD + ":_row_"), updateCollector.getDeleteQueries());
    assertTrue(updateCollector.getIdsToDelete().isEmpty());
    assertTrue(updateCollector.getDocumentsToAdd().isEmpty());
}
 
Example 4
Source File: ColumnBasedIndexerTest.java    From hbase-indexer with Apache License 2.0 6 votes vote down vote up
@Test
public void testCalculateIndexUpdates_UpdateAndDeleteCombinedForSameCell_DeleteFirst() throws IOException {
    KeyValue toDelete = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes("_cf_"),
                                     Bytes.toBytes("_qual_"),
                                     0L, Type.Delete);
    KeyValue toAdd = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes("_cf_"),
                                  Bytes.toBytes("_qual_"),
                                  Bytes.toBytes("value"));
    RowData deleteEventRowData = createEventRowData("_row_", toDelete);
    RowData addEventRowData = createEventRowData("_row_", toAdd);

    indexer.calculateIndexUpdates(
            ImmutableList.of(deleteEventRowData, addEventRowData), updateCollector);

    assertTrue(updateCollector.getIdsToDelete().isEmpty());
    List<SolrInputDocument> documents = Lists.newArrayList(updateCollector.getDocumentsToAdd().values());
    assertEquals(1, documents.size());
    assertEquals("_row_-_cf_-_qual_", documents.get(0).getFieldValue("id"));
}
 
Example 5
Source File: TestIndexMemStore.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * We don't expect custom KeyValue creation, so we can't get into weird situations, where a
 * {@link Type#DeleteFamily} has a column qualifier specified.
 * @throws Exception
 */
@Test
public void testExpectedOrdering() throws Exception {
  IndexMemStore store = new IndexMemStore();
  KeyValue kv = new KeyValue(row, family, qual, 12, Type.Put, val);
  store.add(kv, true);
  KeyValue kv2 = new KeyValue(row, family, qual, 10, Type.Put, val2);
  store.add(kv2, true);
  KeyValue df = new KeyValue(row, family, null, 11, Type.DeleteFamily, null);
  store.add(df, true);
  KeyValue dc = new KeyValue(row, family, qual, 11, Type.DeleteColumn, null);
  store.add(dc, true);
  KeyValue d = new KeyValue(row, family, qual, 12, Type.Delete, null);
  store.add(d, true);

  // null qualifiers should always sort before the non-null cases
  KeyValueScanner scanner = store.getScanner();
  KeyValue first = KeyValue.createFirstOnRow(row);
  assertTrue("Didn't have any data in the scanner", scanner.seek(first));
  assertTrue("Didn't get delete family first (no qualifier == sort first)", df == scanner.next());
  assertTrue("Didn't get point delete before corresponding put", d == scanner.next());
  assertTrue("Didn't get larger ts Put", kv == scanner.next());
  assertTrue("Didn't get delete column before corresponding put(delete sorts first)",
    dc == scanner.next());
  assertTrue("Didn't get smaller ts Put", kv2 == scanner.next());
  assertNull("Have more data in the scanner", scanner.next());
}
 
Example 6
Source File: TestIndexMemStore.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * We don't expect custom KeyValue creation, so we can't get into weird situations, where a
 * {@link Type#DeleteFamily} has a column qualifier specified.
 * @throws Exception
 */
@Test
public void testExpectedOrdering() throws Exception {
  IndexMemStore store = new IndexMemStore();
  KeyValue kv = new KeyValue(row, family, qual, 12, Type.Put, val);
  store.add(kv, true);
  KeyValue kv2 = new KeyValue(row, family, qual, 10, Type.Put, val2);
  store.add(kv2, true);
  KeyValue df = new KeyValue(row, family, null, 11, Type.DeleteFamily, null);
  store.add(df, true);
  KeyValue dc = new KeyValue(row, family, qual, 11, Type.DeleteColumn, null);
  store.add(dc, true);
  KeyValue d = new KeyValue(row, family, qual, 12, Type.Delete, null);
  store.add(d, true);

  // null qualifiers should always sort before the non-null cases
  ReseekableScanner scanner = store.getScanner();
  KeyValue first = KeyValueUtil.createFirstOnRow(row);
  assertTrue("Didn't have any data in the scanner", scanner.seek(first));
  assertTrue("Didn't get delete family first (no qualifier == sort first)", df == scanner.next());
  assertTrue("Didn't get point delete before corresponding put", d == scanner.next());
  assertTrue("Didn't get larger ts Put", kv == scanner.next());
  assertTrue("Didn't get delete column before corresponding put(delete sorts first)",
    dc == scanner.next());
  assertTrue("Didn't get smaller ts Put", kv2 == scanner.next());
  assertNull("Have more data in the scanner", scanner.next());
}
 
Example 7
Source File: TestIndexMemStore.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * We don't expect custom KeyValue creation, so we can't get into weird situations, where a
 * {@link Type#DeleteFamily} has a column qualifier specified.
 * @throws Exception
 */
@Test
public void testExpectedOrdering() throws Exception {
  IndexMemStore store = new IndexMemStore();
  KeyValue kv = new KeyValue(row, family, qual, 12, Type.Put, val);
  store.add(kv, true);
  KeyValue kv2 = new KeyValue(row, family, qual, 10, Type.Put, val2);
  store.add(kv2, true);
  KeyValue df = new KeyValue(row, family, null, 11, Type.DeleteFamily, null);
  store.add(df, true);
  KeyValue dc = new KeyValue(row, family, qual, 11, Type.DeleteColumn, null);
  store.add(dc, true);
  KeyValue d = new KeyValue(row, family, qual, 12, Type.Delete, null);
  store.add(d, true);

  // null qualifiers should always sort before the non-null cases
  KeyValueScanner scanner = store.getScanner();
  KeyValue first = KeyValue.createFirstOnRow(row);
  assertTrue("Didn't have any data in the scanner", scanner.seek(first));
  assertTrue("Didn't get delete family first (no qualifier == sort first)", df == scanner.next());
  assertTrue("Didn't get point delete before corresponding put", d == scanner.next());
  assertTrue("Didn't get larger ts Put", kv == scanner.next());
  assertTrue("Didn't get delete column before corresponding put(delete sorts first)",
    dc == scanner.next());
  assertTrue("Didn't get smaller ts Put", kv2 == scanner.next());
  assertNull("Have more data in the scanner", scanner.next());
}
 
Example 8
Source File: TestClientKeyValueLocal.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testReadWrite() throws IOException {
  byte[] row = Bytes.toBytes("row");
  byte[] family = Bytes.toBytes("family");
  byte[] qualifier = Bytes.toBytes("qualifier");
  byte[] value = Bytes.toBytes("value");
  long ts = 10;
  Type type = KeyValue.Type.Put;
  ClientKeyValue kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type,
      wrap(value));
  validate(kv, row, family, qualifier, ts, type, value);

  type = Type.Delete;
  kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value));
  validate(kv, row, family, qualifier, ts, type, value);

  type = Type.DeleteColumn;
  kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value));
  validate(kv, row, family, qualifier, ts, type, value);

  type = Type.DeleteFamily;
  kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value));
  validate(kv, row, family, qualifier, ts, type, value);

  type = Type.Maximum;
  kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value));
  validate(kv, row, family, qualifier, ts, type, value);

  // test a couple different variables, to make sure we aren't faking it
  row = Bytes.toBytes("row-never-seen-before1234");
  family = Bytes.toBytes("family-to-test-more");
  qualifier = Bytes.toBytes("untested-qualifier");
  value = Bytes.toBytes("value-that-we-haven't_tested");
  ts = System.currentTimeMillis();
  kv = new ClientKeyValue(wrap(row), wrap(family), wrap(qualifier), ts, type, wrap(value));
  validate(kv, row, family, qualifier, ts, type, value);
}
 
Example 9
Source File: RowBasedIndexerTest.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
@Test
public void testCalculateIndexUpdates_DeleteRow() throws IOException {
    
    KeyValue keyValue = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes(""), Bytes.toBytes(""), 0L,
                                     Type.Delete);
    RowData rowData = createEventRowData("_row_", keyValue);
    indexer.calculateIndexUpdates(ImmutableList.of(rowData), updateCollector);
    
    assertEquals(Lists.newArrayList("_row_"), updateCollector.getIdsToDelete());
    assertTrue(updateCollector.getDocumentsToAdd().isEmpty());
}
 
Example 10
Source File: ColumnBasedIndexerTest.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
@Test
public void testCalculateIndexUpdates_DeleteRow_NoRowFieldDefinedForIndexer() throws IOException {
    KeyValue toDelete = new KeyValue(Bytes.toBytes("_row_"), Bytes.toBytes("_cf_"),
                                     Bytes.toBytes("_qual_"),
                                     0L, Type.Delete);
    RowData eventRowData = createEventRowData("_row_", toDelete);
    
    indexer.calculateIndexUpdates(ImmutableList.of(eventRowData), updateCollector);

    assertTrue(updateCollector.getDeleteQueries().isEmpty());
    assertTrue(updateCollector.getIdsToDelete().isEmpty());
    assertTrue(updateCollector.getDocumentsToAdd().isEmpty());
}
 
Example 11
Source File: TestCompactorScanner.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
@Test(dataProvider = "cell-retain-options", timeOut = 60_000)
public void testShouldRetainNonTransactionallyDeletedCellMethod(int optionIdx, boolean retainOption)
        throws Exception {

    // Create required mocks
    @SuppressWarnings("unchecked")
    ObserverContext<RegionCoprocessorEnvironment> ctx = mock(ObserverContext.class);
    InternalScanner internalScanner = mock(InternalScanner.class);
    CommitTable.Client ctClient = mock(CommitTable.Client.class);

    RegionCoprocessorEnvironment rce = mock(RegionCoprocessorEnvironment.class);
    HRegion hRegion = mock(HRegion.class);
    HRegionInfo hRegionInfo = mock(HRegionInfo.class);
    SettableFuture<Long> f = SettableFuture.create();

    // Wire required mock internals
    f.set(TEST_TS);
    when(ctClient.readLowWatermark()).thenReturn(f);
    when(ctx.getEnvironment()).thenReturn(rce);
    when(rce.getRegion()).thenReturn(hRegion);
    when(hRegion.getRegionInfo()).thenReturn(hRegionInfo);

    LOG.info("Testing when retain is {}", retainOption);
    try (CompactorScanner scanner = spy(new CompactorScanner(ctx,
            internalScanner,
            ctClient,
            false,
            retainOption))) {

        // Different cell types to test
        KeyValue regularKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.Put);
        KeyValue deleteKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.Delete);
        KeyValue deleteColumnKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.DeleteColumn);
        KeyValue deleteFamilyKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.DeleteFamily);
        KeyValue deleteFamilyVersionKV = new KeyValue(Bytes.toBytes("test-row"), TEST_TS, Type.DeleteFamilyVersion);

        assertFalse(scanner.shouldRetainNonTransactionallyDeletedCell(regularKV));
        assertEquals(scanner.shouldRetainNonTransactionallyDeletedCell(deleteKV), retainOption);
        assertEquals(scanner.shouldRetainNonTransactionallyDeletedCell(deleteColumnKV), retainOption);
        assertEquals(scanner.shouldRetainNonTransactionallyDeletedCell(deleteFamilyKV), retainOption);
        assertEquals(scanner.shouldRetainNonTransactionallyDeletedCell(deleteFamilyVersionKV), retainOption);

    }

}
 
Example 12
Source File: ClientKeyValueBuilder.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public KeyValue buildDeleteColumn(ImmutableBytesWritable row, ImmutableBytesWritable family,
          ImmutableBytesWritable qualifier, long ts) {
      return new ClientKeyValue(row, family, qualifier, ts, Type.Delete, null);
}