Search in sources :

Example 11 with MultiMutation

use of org.apache.phoenix.hbase.index.MultiMutation in project phoenix by apache.

the class TestNonTxIndexBuilder method testGetMutableIndexUpdate.

/**
     * Tests that updating an indexed column results in a DeleteFamily (prior index cell) and a Put
     * (new index cell)
     */
@Test
public void testGetMutableIndexUpdate() throws IOException {
    setCurrentRowState(FAM, INDEXED_QUALIFIER, 1, VALUE_1);
    // update ts and value
    Put put = new Put(ROW);
    put.addImmutable(FAM, INDEXED_QUALIFIER, 2, VALUE_2);
    MultiMutation mutation = new MultiMutation(new ImmutableBytesPtr(ROW));
    mutation.addAll(put);
    Collection<Pair<Mutation, byte[]>> indexUpdates = indexBuilder.getIndexUpdate(mutation, mockIndexMetaData);
    assertEquals(2, indexUpdates.size());
    assertContains(indexUpdates, 2, ROW, KeyValue.Type.DeleteFamily, FAM, new byte[0], /* qual not needed */
    2);
    assertContains(indexUpdates, ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP, ROW, KeyValue.Type.Put, FAM, QueryConstants.EMPTY_COLUMN_BYTES, 2);
}
Also used : MultiMutation(org.apache.phoenix.hbase.index.MultiMutation) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Put(org.apache.hadoop.hbase.client.Put) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 12 with MultiMutation

use of org.apache.phoenix.hbase.index.MultiMutation in project phoenix by apache.

the class PhoenixTransactionalIndexer method addMutation.

public static void addMutation(Map<ImmutableBytesPtr, MultiMutation> mutations, ImmutableBytesPtr row, Mutation m) {
    MultiMutation stored = mutations.get(row);
    // we haven't seen this row before, so add it
    if (stored == null) {
        stored = new MultiMutation(row);
        mutations.put(row, stored);
    }
    stored.addAll(m);
}
Also used : MultiMutation(org.apache.phoenix.hbase.index.MultiMutation)

Example 13 with MultiMutation

use of org.apache.phoenix.hbase.index.MultiMutation in project phoenix by apache.

the class TestNonTxIndexBuilder method testManyVersions.

/**
     * Tests getting an index update for a mutation with 200 versions Before, the issue PHOENIX-3807
     * was causing this test to take >90 seconds, so here we set a timeout of 5 seconds
     */
@Test(timeout = 5000)
public void testManyVersions() throws IOException {
    // when doing a rebuild, we are replaying mutations so we want to ignore newer mutations
    // see LocalTable#getCurrentRowState()
    Mockito.when(mockIndexMetaData.ignoreNewerMutations()).thenReturn(true);
    MultiMutation mutation = getMultipleVersionMutation(200);
    currentRowCells = mutation.getFamilyCellMap().get(FAM);
    Collection<Pair<Mutation, byte[]>> indexUpdates = indexBuilder.getIndexUpdate(mutation, mockIndexMetaData);
    assertNotEquals(0, indexUpdates.size());
}
Also used : MultiMutation(org.apache.phoenix.hbase.index.MultiMutation) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 14 with MultiMutation

use of org.apache.phoenix.hbase.index.MultiMutation in project phoenix by apache.

the class NonTxIndexBuilderTest method testGetMutableIndexUpdate.

/**
 * Tests that updating an indexed column results in a DeleteFamily (prior index cell) and a Put
 * (new index cell)
 */
@Test
public void testGetMutableIndexUpdate() throws IOException {
    setCurrentRowState(FAM, INDEXED_QUALIFIER, 1, VALUE_1);
    // update ts and value
    Put put = new Put(ROW);
    put.addImmutable(FAM, INDEXED_QUALIFIER, 2, VALUE_2);
    MultiMutation mutation = new MultiMutation(new ImmutableBytesPtr(ROW));
    mutation.addAll(put);
    Collection<Pair<Mutation, byte[]>> indexUpdates = indexBuilder.getIndexUpdate(mutation, mockIndexMetaData);
    assertEquals(2, indexUpdates.size());
    assertContains(indexUpdates, 2, ROW, KeyValue.Type.DeleteFamily, FAM, new byte[0], /* qual not needed */
    2);
    assertContains(indexUpdates, ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP, ROW, KeyValue.Type.Put, FAM, QueryConstants.EMPTY_COLUMN_BYTES, 2);
}
Also used : MultiMutation(org.apache.phoenix.hbase.index.MultiMutation) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Put(org.apache.hadoop.hbase.client.Put) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 15 with MultiMutation

use of org.apache.phoenix.hbase.index.MultiMutation in project phoenix by apache.

the class NonTxIndexBuilderTest method testRebuildMultipleVersionRow.

/**
 * Tests a partial rebuild of a row with multiple versions. 3 versions of the row in data table,
 * and we rebuild the index starting from time t=2
 *
 * There should be one index row version per data row version.
 */
@Test
public void testRebuildMultipleVersionRow() throws IOException {
    // when doing a rebuild, we are replaying mutations so we want to ignore newer mutations
    // see LocalTable#getCurrentRowState()
    Mockito.when(mockIndexMetaData.getReplayWrite()).thenReturn(ReplayWrite.INDEX_ONLY);
    // the current row state has 3 versions, but if we rebuild as of t=2, scanner in LocalTable
    // should only return first
    Cell currentCell1 = CellUtil.createCell(ROW, FAM, INDEXED_QUALIFIER, 1, PUT_TYPE, VALUE_1);
    Cell currentCell2 = CellUtil.createCell(ROW, FAM, INDEXED_QUALIFIER, 2, PUT_TYPE, VALUE_2);
    Cell currentCell3 = CellUtil.createCell(ROW, FAM, INDEXED_QUALIFIER, 3, PUT_TYPE, VALUE_3);
    Cell currentCell4 = CellUtil.createCell(ROW, FAM, INDEXED_QUALIFIER, 4, PUT_TYPE, VALUE_4);
    setCurrentRowState(Arrays.asList(currentCell4, currentCell3, currentCell2, currentCell1));
    // rebuilder replays mutations starting from t=2
    MultiMutation mutation = new MultiMutation(new ImmutableBytesPtr(ROW));
    Put put = new Put(ROW);
    put.addImmutable(FAM, INDEXED_QUALIFIER, 4, VALUE_4);
    mutation.addAll(put);
    put = new Put(ROW);
    put.addImmutable(FAM, INDEXED_QUALIFIER, 3, VALUE_3);
    mutation.addAll(put);
    put = new Put(ROW);
    put.addImmutable(FAM, INDEXED_QUALIFIER, 2, VALUE_2);
    mutation.addAll(put);
    Collection<Pair<Mutation, byte[]>> indexUpdates = Lists.newArrayList();
    for (Mutation m : IndexManagementUtil.flattenMutationsByTimestamp(Collections.singletonList(mutation))) {
        indexUpdates.addAll(indexBuilder.getIndexUpdate(m, mockIndexMetaData));
    }
    // 3 puts and 3 deletes (one to hide existing index row for VALUE_1, and two to hide index
    // rows for VALUE_2, VALUE_3)
    assertEquals(6, indexUpdates.size());
    assertContains(indexUpdates, 2, ROW, KeyValue.Type.DeleteFamily, FAM, new byte[0], /* qual not needed */
    2);
    assertContains(indexUpdates, ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP, ROW, KeyValue.Type.Put, FAM, QueryConstants.EMPTY_COLUMN_BYTES, 2);
    assertContains(indexUpdates, 3, ROW, KeyValue.Type.DeleteFamily, FAM, new byte[0], /* qual not needed */
    3);
    assertContains(indexUpdates, ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP, ROW, KeyValue.Type.Put, FAM, QueryConstants.EMPTY_COLUMN_BYTES, 3);
    assertContains(indexUpdates, 4, ROW, KeyValue.Type.DeleteFamily, FAM, new byte[0], /* qual not needed */
    4);
    assertContains(indexUpdates, ColumnTracker.NO_NEWER_PRIMARY_TABLE_ENTRY_TIMESTAMP, ROW, KeyValue.Type.Put, FAM, QueryConstants.EMPTY_COLUMN_BYTES, 4);
}
Also used : MultiMutation(org.apache.phoenix.hbase.index.MultiMutation) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Mutation(org.apache.hadoop.hbase.client.Mutation) MultiMutation(org.apache.phoenix.hbase.index.MultiMutation) Cell(org.apache.hadoop.hbase.Cell) Put(org.apache.hadoop.hbase.client.Put) Pair(org.apache.hadoop.hbase.util.Pair) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

MultiMutation (org.apache.phoenix.hbase.index.MultiMutation)16 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)12 Mutation (org.apache.hadoop.hbase.client.Mutation)8 Pair (org.apache.hadoop.hbase.util.Pair)8 Put (org.apache.hadoop.hbase.client.Put)6 ColumnReference (org.apache.phoenix.hbase.index.covered.update.ColumnReference)6 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)6 Test (org.junit.Test)6 Cell (org.apache.hadoop.hbase.Cell)4 Result (org.apache.hadoop.hbase.client.Result)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 Scan (org.apache.hadoop.hbase.client.Scan)2 ScanRanges (org.apache.phoenix.compile.ScanRanges)2 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)2 IndexMaintainer (org.apache.phoenix.index.IndexMaintainer)2 KeyRange (org.apache.phoenix.query.KeyRange)2 TableName (org.apache.hadoop.hbase.TableName)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1