Java Code Examples for org.apache.hadoop.hbase.Cell#equals()

The following examples show how to use org.apache.hadoop.hbase.Cell#equals() . 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: TestUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Does a deep comparison of two Results, down to the byte arrays.
 * @param res1 first result to compare
 * @param res2 second result to compare
 * @throws Exception Every difference is throwing an exception
 */
public static void compareTuples(Tuple res1, Tuple res2)
    throws Exception {
  if (res2 == null) {
    throw new Exception("There wasn't enough rows, we stopped at "
        + res1);
  }
  if (res1.size() != res2.size()) {
    throw new Exception("This row doesn't have the same number of KVs: "
        + res1.toString() + " compared to " + res2.toString());
  }
  for (int i = 0; i < res1.size(); i++) {
      Cell ourKV = res1.getValue(i);
      Cell replicatedKV = res2.getValue(i);
      if (!ourKV.equals(replicatedKV)) {
          throw new Exception("This result was different: "
              + res1.toString() + " compared to " + res2.toString());
    }
  }
}
 
Example 2
Source File: TestUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Does a deep comparison of two Results, down to the byte arrays.
 * @param res1 first result to compare
 * @param res2 second result to compare
 * @throws Exception Every difference is throwing an exception
 */
public static void compareTuples(Tuple res1, Tuple res2)
    throws Exception {
  if (res2 == null) {
    throw new Exception("There wasn't enough rows, we stopped at "
        + res1);
  }
  if (res1.size() != res2.size()) {
    throw new Exception("This row doesn't have the same number of KVs: "
        + res1.toString() + " compared to " + res2.toString());
  }
  for (int i = 0; i < res1.size(); i++) {
      Cell ourKV = res1.getValue(i);
      Cell replicatedKV = res2.getValue(i);
      if (!ourKV.equals(replicatedKV)) {
          throw new Exception("This result was different: "
              + res1.toString() + " compared to " + res2.toString());
    }
  }
}
 
Example 3
Source File: EncodedColumnQualiferCellsList.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean retainAll(Collection<?> collection) {
    boolean changed = false;
    // Optimize if the passed collection is an instance of EncodedColumnQualiferCellsList
    if (collection instanceof EncodedColumnQualiferCellsList) {
        EncodedColumnQualiferCellsList list = (EncodedColumnQualiferCellsList) collection;
        ListIterator<Cell> listItr = this.listIterator();
        while (listItr.hasNext()) {
            Cell cellInThis = listItr.next();
            int qualifier =
                    encodingScheme.decode(cellInThis.getQualifierArray(),
                        cellInThis.getQualifierOffset(), cellInThis.getQualifierLength());
            try {
                Cell cellInParam = list.getCellForColumnQualifier(qualifier);
                if (cellInParam != null && cellInParam.equals(cellInThis)) {
                    continue;
                }
                listItr.remove();
                changed = true;
            } catch (IndexOutOfBoundsException expected) {
                // this could happen when the qualifier of cellInParam lies out of
                // the range of this list.
                listItr.remove();
                changed = true;
            }
        }
    } else {
        throw new UnsupportedOperationException(
                "Operation only supported for collections of type EncodedColumnQualiferCellsList");
    }
    return changed;
}
 
Example 4
Source File: EncodedSeekPerformanceTest.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void runTest(Path path, DataBlockEncoding blockEncoding,
    List<Cell> seeks) throws IOException {
  // read all of the key values
  HStoreFile storeFile = new HStoreFile(testingUtility.getTestFileSystem(),
    path, configuration, cacheConf, BloomType.NONE, true);
  storeFile.initReader();
  long totalSize = 0;

  StoreFileReader reader = storeFile.getReader();
  StoreFileScanner scanner = reader.getStoreFileScanner(true, false, false, 0, 0, false);

  long startReadingTime = System.nanoTime();
  Cell current;
  scanner.seek(KeyValue.LOWESTKEY);
  while (null != (current = scanner.next())) { // just iterate it!
    if (KeyValueUtil.ensureKeyValue(current).getLength() < 0) {
      throw new IOException("Negative KV size: " + current);
    }
    totalSize += KeyValueUtil.ensureKeyValue(current).getLength();
  }
  long finishReadingTime = System.nanoTime();

  // do seeks
  long startSeeksTime = System.nanoTime();
  for (Cell keyValue : seeks) {
    scanner.seek(keyValue);
    Cell toVerify = scanner.next();
    if (!keyValue.equals(toVerify)) {
      System.out.println(String.format("KeyValue doesn't match:\n" + "Orig key: %s\n"
          + "Ret key:  %s", KeyValueUtil.ensureKeyValue(keyValue).getKeyString(), KeyValueUtil
          .ensureKeyValue(toVerify).getKeyString()));
      break;
    }
  }
  long finishSeeksTime = System.nanoTime();
  if (finishSeeksTime < startSeeksTime) {
    throw new AssertionError("Finish time " + finishSeeksTime +
        " is earlier than start time " + startSeeksTime);
  }

  // write some stats
  double readInMbPerSec = (totalSize * NANOSEC_IN_SEC) /
      (BYTES_IN_MEGABYTES * (finishReadingTime - startReadingTime));
  double seeksPerSec = (seeks.size() * NANOSEC_IN_SEC) /
      (finishSeeksTime - startSeeksTime);

  storeFile.closeStoreFile(cacheConf.shouldEvictOnClose());
  clearBlockCache();

  System.out.println(blockEncoding);
  System.out.printf("  Read speed:       %8.2f (MB/s)\n", readInMbPerSec);
  System.out.printf("  Seeks per second: %8.2f (#/s)\n", seeksPerSec);
  System.out.printf("  Total KV size:    %d\n", totalSize);
}