Java Code Examples for org.apache.hadoop.hbase.KeyValueUtil#createFirstOnRow()

The following examples show how to use org.apache.hadoop.hbase.KeyValueUtil#createFirstOnRow() . 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: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (skipCellVersion(cell)) {
    return ReturnCode.NEXT_COL;
  }

  ReturnCode code = filter.filterKeyValue(cell);
  if (code == ReturnCode.NEXT_COL || code == ReturnCode.INCLUDE_AND_NEXT_COL) {
    // only store the reference to the keyvalue if we are returning NEXT_COL or INCLUDE_AND_NEXT_COL
    skipColumn = KeyValueUtil.createFirstOnRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
                                                 cell.getFamilyArray(), cell.getFamilyOffset(),
                                                 cell.getFamilyLength(), cell.getQualifierArray(),
                                                 cell.getQualifierOffset(), cell.getQualifierLength());
  } else {
    skipColumn = null;
  }
  return code;
}
 
Example 2
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (skipCellVersion(cell)) {
    return ReturnCode.NEXT_COL;
  }

  ReturnCode code = filter.filterKeyValue(cell);
  if (code == ReturnCode.NEXT_COL || code == ReturnCode.INCLUDE_AND_NEXT_COL) {
    // only store the reference to the keyvalue if we are returning NEXT_COL or INCLUDE_AND_NEXT_COL
    skipColumn = KeyValueUtil.createFirstOnRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
                                                 cell.getFamilyArray(), cell.getFamilyOffset(),
                                                 cell.getFamilyLength(), cell.getQualifierArray(),
                                                 cell.getQualifierOffset(), cell.getQualifierLength());
  } else {
    skipColumn = null;
  }
  return code;
}
 
Example 3
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (skipCellVersion(cell)) {
    return ReturnCode.NEXT_COL;
  }

  ReturnCode code = filter.filterKeyValue(cell);
  if (code == ReturnCode.NEXT_COL || code == ReturnCode.INCLUDE_AND_NEXT_COL) {
    // only store the reference to the keyvalue if we are returning NEXT_COL or INCLUDE_AND_NEXT_COL
    skipColumn = KeyValueUtil.createFirstOnRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
                                                 cell.getFamilyArray(), cell.getFamilyOffset(),
                                                 cell.getFamilyLength(), cell.getQualifierArray(),
                                                 cell.getQualifierOffset(), cell.getQualifierLength());
  } else {
    skipColumn = null;
  }
  return code;
}
 
Example 4
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (skipCellVersion(cell)) {
    return ReturnCode.NEXT_COL;
  }

  ReturnCode code = filter.filterKeyValue(cell);
  if (code == ReturnCode.NEXT_COL || code == ReturnCode.INCLUDE_AND_NEXT_COL) {
    // only store the reference to the keyvalue if we are returning NEXT_COL or INCLUDE_AND_NEXT_COL
    skipColumn = KeyValueUtil.createFirstOnRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
                                                 cell.getFamilyArray(), cell.getFamilyOffset(),
                                                 cell.getFamilyLength(), cell.getQualifierArray(),
                                                 cell.getQualifierOffset(), cell.getQualifierLength());
  } else {
    skipColumn = null;
  }
  return code;
}
 
Example 5
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (skipCellVersion(cell)) {
    return ReturnCode.NEXT_COL;
  }

  ReturnCode code = filter.filterKeyValue(cell);
  if (code == ReturnCode.NEXT_COL || code == ReturnCode.INCLUDE_AND_NEXT_COL) {
    // only store the reference to the keyvalue if we are returning NEXT_COL or INCLUDE_AND_NEXT_COL
    skipColumn = KeyValueUtil.createFirstOnRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
                                                 cell.getFamilyArray(), cell.getFamilyOffset(),
                                                 cell.getFamilyLength(), cell.getQualifierArray(),
                                                 cell.getQualifierOffset(), cell.getQualifierLength());
  } else {
    skipColumn = null;
  }
  return code;
}
 
Example 6
Source File: CellSkipFilter.java    From phoenix-tephra with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
  if (skipCellVersion(cell)) {
    return ReturnCode.NEXT_COL;
  }

  ReturnCode code = filter.filterKeyValue(cell);
  if (code == ReturnCode.NEXT_COL || code == ReturnCode.INCLUDE_AND_NEXT_COL) {
    // only store the reference to the keyvalue if we are returning NEXT_COL or INCLUDE_AND_NEXT_COL
    skipColumn = KeyValueUtil.createFirstOnRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
                                                 cell.getFamilyArray(), cell.getFamilyOffset(),
                                                 cell.getFamilyLength(), cell.getQualifierArray(),
                                                 cell.getQualifierOffset(), cell.getQualifierLength());
  } else {
    skipColumn = null;
  }
  return code;
}
 
Example 7
Source File: CellSkipFilterBase.java    From phoenix-omid with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnCode filterKeyValue(Cell cell) throws IOException {
    if (skipCellVersion(cell)) {
        return ReturnCode.NEXT_COL;
    }

    ReturnCode code = filter.filterKeyValue(cell);
    if (code == ReturnCode.NEXT_COL || code == ReturnCode.INCLUDE_AND_NEXT_COL) {
        // only store the reference to the keyvalue if we are returning NEXT_COL or INCLUDE_AND_NEXT_COL
        skipColumn = KeyValueUtil.createFirstOnRow(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
                cell.getFamilyArray(), cell.getFamilyOffset(),
                cell.getFamilyLength(), cell.getQualifierArray(),
                cell.getQualifierOffset(), cell.getQualifierLength());
    } else {
        skipColumn = null;
    }
    return code;
}
 
Example 8
Source File: Import.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void setup(Context context) throws IOException {
  cfRenameMap = createCfRenameMap(context.getConfiguration());
  filter = instantiateFilter(context.getConfiguration());
  int reduceNum = context.getNumReduceTasks();
  Configuration conf = context.getConfiguration();
  TableName tableName = TableName.valueOf(context.getConfiguration().get(TABLE_NAME));
  try (Connection conn = ConnectionFactory.createConnection(conf);
      RegionLocator regionLocator = conn.getRegionLocator(tableName)) {
    byte[][] startKeys = regionLocator.getStartKeys();
    if (startKeys.length != reduceNum) {
      throw new IOException("Region split after job initialization");
    }
    CellWritableComparable[] startKeyWraps =
        new CellWritableComparable[startKeys.length - 1];
    for (int i = 1; i < startKeys.length; ++i) {
      startKeyWraps[i - 1] =
          new CellWritableComparable(KeyValueUtil.createFirstOnRow(startKeys[i]));
    }
    CellWritableComparablePartitioner.START_KEYS = startKeyWraps;
  }
}
 
Example 9
Source File: SkipScanFilterTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override public void examine(SkipScanFilter skipper) throws IOException {
    KeyValue kv = KeyValueUtil.createFirstOnRow(rowkey);
    skipper.reset();
    assertFalse(skipper.filterAllRemaining());
    assertFalse(skipper.filterRowKey(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength()));

    assertEquals(ReturnCode.SEEK_NEXT_USING_HINT, skipper.filterKeyValue(kv));
    assertEquals(KeyValueUtil.createFirstOnRow(hint), skipper.getNextCellHint(kv));
}
 
Example 10
Source File: TestApplyAndFilterDeletesFilter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * Hinting with this filter is a little convoluted as we binary search the list of families to
 * attempt to find the right one to seek.
 */
@Test
public void testHintCorrectlyToNextFamily() {
  // start with doing a family delete, so we will seek to the next column
  KeyValue kv = createKvForType(Type.DeleteFamily);
  ApplyAndFilterDeletesFilter filter = new ApplyAndFilterDeletesFilter(EMPTY_SET);
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  KeyValue next = createKvForType(Type.Put);
  // make sure the hint is our attempt at the end key, because we have no more families to seek
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get END_KEY with no families to match", KeyValue.LOWESTKEY,
    filter.getNextCellHint(next));

  // check for a family that comes before our family, so we always seek to the end as well
  filter = new ApplyAndFilterDeletesFilter(asSet(Bytes.toBytes("afamily")));
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  // make sure the hint is our attempt at the end key, because we have no more families to seek
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get END_KEY with no families to match", KeyValue.LOWESTKEY,
    filter.getNextCellHint(next));

  // check that we seek to the correct family that comes after our family
  byte[] laterFamily = Bytes.toBytes("zfamily");
  filter = new ApplyAndFilterDeletesFilter(asSet(laterFamily));
  assertEquals(ReturnCode.SKIP, filter.filterKeyValue(kv));
  KeyValue expected = KeyValueUtil.createFirstOnRow(CellUtil.cloneRow(kv), laterFamily, new byte[0]);
  assertEquals("Didn't get a hint from a family delete", ReturnCode.SEEK_NEXT_USING_HINT,
    filter.filterKeyValue(next));
  assertEquals("Didn't get correct next key with a next family", expected,
    filter.getNextCellHint(next));
}
 
Example 11
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 12
Source File: TestIndexMemStore.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Test
public void testCorrectOverwritting() throws Exception {
  IndexMemStore store = new IndexMemStore(new DelegateComparator(new CellComparatorImpl()){
      @Override
      public int compare(Cell leftCell, Cell rightCell) {
          return super.compare(leftCell, rightCell, true);
      }
  });
  long ts = 10;
  KeyValue kv = new KeyValue(row, family, qual, ts, Type.Put, val);
  kv.setSequenceId(2);
  KeyValue kv2 = new KeyValue(row, family, qual, ts, Type.Put, val2);
  kv2.setSequenceId(0);
  store.add(kv, true);
  // adding the exact same kv shouldn't change anything stored if not overwritting
  store.add(kv2, false);
  ReseekableScanner scanner = store.getScanner();
  KeyValue first = KeyValueUtil.createFirstOnRow(row);
  scanner.seek(first);
  assertTrue("Overwrote kv when specifically not!", kv == scanner.next());
  scanner.close();

  // now when we overwrite, we should get the newer one
  store.add(kv2, true);
  scanner = store.getScanner();
  scanner.seek(first);
  assertTrue("Didn't overwrite kv when specifically requested!", kv2 == scanner.next());
  scanner.close();
}
 
Example 13
Source File: SkipScanFilterTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override public void examine(SkipScanFilter skipper) throws IOException {
    KeyValue kv = KeyValueUtil.createFirstOnRow(rowkey);
    skipper.reset();
    assertFalse(skipper.filterAllRemaining());
    assertFalse(skipper.filterRowKey(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength()));
    assertEquals(kv.toString(), ReturnCode.INCLUDE_AND_NEXT_COL, skipper.filterKeyValue(kv));
}
 
Example 14
Source File: TestFuzzyRowFilter.java    From hbase with Apache License 2.0 5 votes vote down vote up
private static void assertNext(boolean reverse, byte[] fuzzyRow, byte[] mask, byte[] current,
    byte[] expected) {
  KeyValue kv = KeyValueUtil.createFirstOnRow(current);
  byte[] nextForFuzzyRule = FuzzyRowFilter.getNextForFuzzyRule(reverse, kv.getRowArray(),
      kv.getRowOffset(), kv.getRowLength(), fuzzyRow, mask);
  Assert.assertEquals(Bytes.toStringBinary(expected), Bytes.toStringBinary(nextForFuzzyRule));
}
 
Example 15
Source File: TestHStoreFile.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Test for HBASE-8012
 */
@Test
public void testReseek() throws Exception {
  // write the file
  Path f = new Path(ROOT_DIR, name.getMethodName());
  HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).build();
  // Make a store file and write data to it.
  StoreFileWriter writer = new StoreFileWriter.Builder(conf, cacheConf, this.fs).withFilePath(f)
    .withFileContext(meta).build();

  writeStoreFile(writer);
  writer.close();

  ReaderContext context = new ReaderContextBuilder().withFileSystemAndPath(fs, f).build();
  HFileInfo fileInfo = new HFileInfo(context, conf);
  StoreFileReader reader =
    new StoreFileReader(context, fileInfo, cacheConf, new AtomicInteger(0), conf);
  fileInfo.initMetaAndIndex(reader.getHFileReader());

  // Now do reseek with empty KV to position to the beginning of the file

  KeyValue k = KeyValueUtil.createFirstOnRow(HConstants.EMPTY_BYTE_ARRAY);
  StoreFileScanner s = getStoreFileScanner(reader, false, false);
  s.reseek(k);

  assertNotNull("Intial reseek should position at the beginning of the file", s.peek());
}
 
Example 16
Source File: TestKeyValueScanFixture.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void testKeyValueScanFixture() throws IOException {
  KeyValue kvs[] = new KeyValue[]{
      KeyValueTestUtil.create("RowA", "family", "qf1",
          1, KeyValue.Type.Put, "value-1"),
      KeyValueTestUtil.create("RowA", "family", "qf2",
          1, KeyValue.Type.Put, "value-2"),
      KeyValueTestUtil.create("RowB", "family", "qf1",
          10, KeyValue.Type.Put, "value-10")
  };
  KeyValueScanner scan = new KeyValueScanFixture(CellComparator.getInstance(), kvs);

  KeyValue kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowA"));
  // should seek to this:
  assertTrue(scan.seek(kv));
  Cell res = scan.peek();
  assertEquals(kvs[0], res);

  kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowB"));
  assertTrue(scan.seek(kv));
  res = scan.peek();
  assertEquals(kvs[2], res);

  // ensure we pull things out properly:
  kv = KeyValueUtil.createFirstOnRow(Bytes.toBytes("RowA"));
  assertTrue(scan.seek(kv));
  assertEquals(kvs[0], scan.peek());
  assertEquals(kvs[0], scan.next());
  assertEquals(kvs[1], scan.peek());
  assertEquals(kvs[1], scan.next());
  assertEquals(kvs[2], scan.peek());
  assertEquals(kvs[2], scan.next());
  assertEquals(null, scan.peek());
  assertEquals(null, scan.next());
}
 
Example 17
Source File: TestStoreFileScannerWithTagCompression.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testReseek() throws Exception {
  // write the file
  Path f = new Path(ROOT_DIR, "testReseek");
  HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).withIncludesTags(true)
      .withCompressTags(true).withDataBlockEncoding(DataBlockEncoding.PREFIX).build();
  // Make a store file and write data to it.
  StoreFileWriter writer = new StoreFileWriter.Builder(conf, cacheConf, fs).withFilePath(f)
      .withFileContext(meta).build();

  writeStoreFile(writer);
  writer.close();

  ReaderContext context = new ReaderContextBuilder().withFileSystemAndPath(fs, f).build();
  HFileInfo fileInfo = new HFileInfo(context, conf);
  StoreFileReader reader =
      new StoreFileReader(context, fileInfo, cacheConf, new AtomicInteger(0), conf);
  fileInfo.initMetaAndIndex(reader.getHFileReader());
  StoreFileScanner s = reader.getStoreFileScanner(false, false, false, 0, 0, false);
  try {
    // Now do reseek with empty KV to position to the beginning of the file
    KeyValue k = KeyValueUtil.createFirstOnRow(Bytes.toBytes("k2"));
    s.reseek(k);
    Cell kv = s.next();
    kv = s.next();
    kv = s.next();
    byte[] key5 = Bytes.toBytes("k5");
    assertTrue(Bytes.equals(key5, 0, key5.length, kv.getRowArray(), kv.getRowOffset(),
        kv.getRowLength()));
    List<Tag> tags = PrivateCellUtil.getTags(kv);
    assertEquals(1, tags.size());
    assertEquals("tag3", Bytes.toString(Tag.cloneValue(tags.get(0))));
  } finally {
    s.close();
  }
}
 
Example 18
Source File: ScanQueryMatcher.java    From hbase with Apache License 2.0 5 votes vote down vote up
static MatchCode checkColumn(ColumnTracker columnTracker, byte[] bytes, int offset, int length,
    long ttl, byte type, boolean ignoreCount) throws IOException {
  KeyValue kv = KeyValueUtil.createFirstOnRow(HConstants.EMPTY_BYTE_ARRAY, 0, 0,
    HConstants.EMPTY_BYTE_ARRAY, 0, 0, bytes, offset, length);
  MatchCode matchCode = columnTracker.checkColumn(kv, type);
  if (matchCode == MatchCode.INCLUDE) {
    return columnTracker.checkVersions(kv, ttl, type, ignoreCount);
  }
  return matchCode;
}
 
Example 19
Source File: SkipScanFilterTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override public void examine(SkipScanFilter skipper) throws IOException {
    KeyValue kv = KeyValueUtil.createFirstOnRow(rowkey);
    skipper.reset();
    assertEquals(ReturnCode.NEXT_ROW,skipper.filterKeyValue(kv));
    skipper.reset();
    assertTrue(skipper.filterAllRemaining());
}
 
Example 20
Source File: ColumnReference.java    From phoenix with Apache License 2.0 4 votes vote down vote up
public KeyValue getFirstKeyValueForRow(byte[] row) {
    return KeyValueUtil.createFirstOnRow(row, getFamily(), getQualifier() == ALL_QUALIFIERS ? null
            : getQualifier());
}