Java 类org.apache.hadoop.hbase.KeyValue.Type 实例源码

项目:ditb    文件:ScanQueryMatcher.java   
/**
 * @param nextIndexed the key of the next entry in the block index (if any)
 * @param kv The Cell we're using to calculate the seek key
 * @return result of the compare between the indexed key and the key portion of the passed cell
 */
public int compareKeyForNextColumn(Cell nextIndexed, Cell kv) {
  ColumnCount nextColumn = columns.getColumnHint();
  if (nextColumn == null) {
    return rowComparator.compareKey(nextIndexed,
      kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(),
      kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(),
      kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(),
      HConstants.OLDEST_TIMESTAMP, Type.Minimum.getCode());
  } else {
    return rowComparator.compareKey(nextIndexed,
      kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(),
      kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(),
      nextColumn.getBuffer(), nextColumn.getOffset(), nextColumn.getLength(),
      HConstants.LATEST_TIMESTAMP, Type.Maximum.getCode());
  }
}
项目:ditb    文件:TestDataBlockEncoders.java   
/**
 * Test KeyValues with negative timestamp.
 * 
 * @throws IOException
 *           On test failure.
 */
@Test
public void testNegativeTimestamps() throws IOException {
  List<KeyValue> kvList = new ArrayList<KeyValue>();
  byte[] row = new byte[0];
  byte[] family = new byte[0];
  byte[] qualifier = new byte[0];
  byte[] value = new byte[0];
  if (includesTags) {
    byte[] metaValue1 = Bytes.toBytes("metaValue1");
    byte[] metaValue2 = Bytes.toBytes("metaValue2");
    kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new Tag((byte) 1,
        metaValue1) }));
    kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new Tag((byte) 1,
        metaValue2) }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier, -1l, Type.Put, value));
    kvList.add(new KeyValue(row, family, qualifier, -2l, Type.Put, value));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
项目:ditb    文件:TestDataBlockEncoders.java   
@Test
public void testZeroByte() throws IOException {
  List<KeyValue> kvList = new ArrayList<KeyValue>();
  byte[] row = Bytes.toBytes("abcd");
  byte[] family = new byte[] { 'f' };
  byte[] qualifier0 = new byte[] { 'b' };
  byte[] qualifier1 = new byte[] { 'c' };
  byte[] value0 = new byte[] { 'd' };
  byte[] value1 = new byte[] { 0x00 };
  if (includesTags) {
    kvList.add(new KeyValue(row, family, qualifier0, 0, value0, new Tag[] { new Tag((byte) 1,
        "value1") }));
    kvList.add(new KeyValue(row, family, qualifier1, 0, value1, new Tag[] { new Tag((byte) 1,
        "value1") }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier0, 0, Type.Put, value0));
    kvList.add(new KeyValue(row, family, qualifier1, 0, Type.Put, value1));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
项目:ditb    文件:CellUtil.java   
/**
 * @param cell
 * @return The Key portion of the passed <code>cell</code> as a String.
 */
public static String getCellKeyAsString(Cell cell) {
  StringBuilder sb = new StringBuilder(Bytes.toStringBinary(
    cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
  sb.append('/');
  sb.append(cell.getFamilyLength() == 0? "":
    Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()));
  // KeyValue only added ':' if family is non-null.  Do same.
  if (cell.getFamilyLength() > 0) sb.append(':');
  sb.append(cell.getQualifierLength() == 0? "":
    Bytes.toStringBinary(cell.getQualifierArray(), cell.getQualifierOffset(),
      cell.getQualifierLength()));
  sb.append('/');
  sb.append(KeyValue.humanReadableTimestamp(cell.getTimestamp()));
  sb.append('/');
  sb.append(Type.codeToType(cell.getTypeByte()));
  sb.append("/vlen=");
  sb.append(cell.getValueLength());
  sb.append("/seqid=");
  sb.append(cell.getSequenceId());
  return sb.toString();
}
项目:ditb    文件:TestCellUtil.java   
/**
 * Assert CellUtil makes Cell toStrings same way we do KeyValue toStrings.
 */
@Test
public void testToString() {
  byte [] row = Bytes.toBytes("row");
  long ts = 123l;
  // Make a KeyValue and a Cell and see if same toString result.
  KeyValue kv = new KeyValue(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY,
      ts, KeyValue.Type.Minimum, HConstants.EMPTY_BYTE_ARRAY);
  Cell cell = CellUtil.createCell(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY,
      ts, KeyValue.Type.Minimum.getCode(), HConstants.EMPTY_BYTE_ARRAY);
  String cellToString = CellUtil.getCellKeyAsString(cell);
  assertEquals(kv.toString(), cellToString);
  // Do another w/ non-null family.
  byte [] f = new byte [] {'f'};
  byte [] q = new byte [] {'q'};
  kv = new KeyValue(row, f, q, ts, KeyValue.Type.Minimum, HConstants.EMPTY_BYTE_ARRAY);
  cell = CellUtil.createCell(row, f, q, ts, KeyValue.Type.Minimum.getCode(),
      HConstants.EMPTY_BYTE_ARRAY);
  cellToString = CellUtil.getCellKeyAsString(cell);
  assertEquals(kv.toString(), cellToString);

}
项目:ditb    文件:TestKeyValue.java   
public void testColumnCompare() throws Exception {
  final byte [] a = Bytes.toBytes("aaa");
  byte [] family1 = Bytes.toBytes("abc");
  byte [] qualifier1 = Bytes.toBytes("def");
  byte [] family2 = Bytes.toBytes("abcd");
  byte [] qualifier2 = Bytes.toBytes("ef");

  KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, Type.Put, a);
  assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2));
  assertTrue(CellUtil.matchingColumn(aaa, family1, qualifier1));
  aaa = new KeyValue(a, family2, qualifier2, 0L, Type.Put, a);
  assertFalse(CellUtil.matchingColumn(aaa, family1, qualifier1));
  assertTrue(CellUtil.matchingColumn(aaa, family2,qualifier2));
  byte [] nullQualifier = new byte[0];
  aaa = new KeyValue(a, family1, nullQualifier, 0L, Type.Put, a);
  assertTrue(CellUtil.matchingColumn(aaa, family1,null));
  assertFalse(CellUtil.matchingColumn(aaa, family2,qualifier2));
}
项目:ditb    文件:TestKeyValue.java   
public void testPlainCompare() throws Exception {
  final byte [] a = Bytes.toBytes("aaa");
  final byte [] b = Bytes.toBytes("bbb");
  final byte [] fam = Bytes.toBytes("col");
  final byte [] qf = Bytes.toBytes("umn");
  KeyValue aaa = new KeyValue(a, fam, qf, a);
  KeyValue bbb = new KeyValue(b, fam, qf, b);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) > 0);
  // Compare breaks if passed same ByteBuffer as both left and right arguments.
  assertTrue(KeyValue.COMPARATOR.compare(bbb, bbb) == 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
  // Do compare with different timestamps.
  aaa = new KeyValue(a, fam, qf, 1, a);
  bbb = new KeyValue(a, fam, qf, 2, a);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) > 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
  // Do compare with different types.  Higher numbered types -- Delete
  // should sort ahead of lower numbers; i.e. Put
  aaa = new KeyValue(a, fam, qf, 1, KeyValue.Type.Delete, a);
  bbb = new KeyValue(a, fam, qf, 1, a);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) > 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
}
项目:LCIndex-HBase-0.94.16    文件:TestKeyValue.java   
public void testColumnCompare() throws Exception {
  final byte [] a = Bytes.toBytes("aaa");
  byte [] family1 = Bytes.toBytes("abc");
  byte [] qualifier1 = Bytes.toBytes("def");
  byte [] family2 = Bytes.toBytes("abcd");
  byte [] qualifier2 = Bytes.toBytes("ef");

  KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, Type.Put, a);
  assertFalse(aaa.matchingColumn(family2, qualifier2));
  assertTrue(aaa.matchingColumn(family1, qualifier1));
  aaa = new KeyValue(a, family2, qualifier2, 0L, Type.Put, a);
  assertFalse(aaa.matchingColumn(family1, qualifier1));
  assertTrue(aaa.matchingColumn(family2,qualifier2));
  byte [] nullQualifier = new byte[0];
  aaa = new KeyValue(a, family1, nullQualifier, 0L, Type.Put, a);
  assertTrue(aaa.matchingColumn(family1,null));
  assertFalse(aaa.matchingColumn(family2,qualifier2));
}
项目:pbase    文件:TestQueryMatcher.java   
private void testDropDeletes(
    byte[] from, byte[] to, byte[][] rows, MatchCode... expected) throws IOException {
  long now = EnvironmentEdgeManager.currentTime();
  // Set time to purge deletes to negative value to avoid it ever happening.
  ScanInfo scanInfo = new ScanInfo(fam2, 0, 1, ttl, KeepDeletedCells.FALSE, -1L, rowComparator);
  NavigableSet<byte[]> cols = get.getFamilyMap().get(fam2);

  ScanQueryMatcher qm = new ScanQueryMatcher(scan, scanInfo, cols, Long.MAX_VALUE,
      HConstants.OLDEST_TIMESTAMP, HConstants.OLDEST_TIMESTAMP, now, from, to, null);
  List<ScanQueryMatcher.MatchCode> actual =
      new ArrayList<ScanQueryMatcher.MatchCode>(rows.length);
  byte[] prevRow = null;
  for (byte[] row : rows) {
    if (prevRow == null || !Bytes.equals(prevRow, row)) {
      qm.setRow(row, 0, (short)row.length);
      prevRow = row;
    }
    actual.add(qm.match(new KeyValue(row, fam2, null, now, Type.Delete)));
  }

  assertEquals(expected.length, actual.size());
  for (int i = 0; i < expected.length; i++) {
    if (PRINT) System.out.println("expected " + expected[i] + ", actual " + actual.get(i));
    assertEquals(expected[i], actual.get(i));
  }
}
项目:pbase    文件:TestDataBlockEncoders.java   
/**
 * Test KeyValues with negative timestamp.
 * 
 * @throws IOException
 *           On test failure.
 */
@Test
public void testNegativeTimestamps() throws IOException {
  List<KeyValue> kvList = new ArrayList<KeyValue>();
  byte[] row = new byte[0];
  byte[] family = new byte[0];
  byte[] qualifier = new byte[0];
  byte[] value = new byte[0];
  if (includesTags) {
    byte[] metaValue1 = Bytes.toBytes("metaValue1");
    byte[] metaValue2 = Bytes.toBytes("metaValue2");
    kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new Tag((byte) 1,
        metaValue1) }));
    kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new Tag((byte) 1,
        metaValue2) }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier, -1l, Type.Put, value));
    kvList.add(new KeyValue(row, family, qualifier, -2l, Type.Put, value));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
项目:pbase    文件:TestDataBlockEncoders.java   
@Test
public void testZeroByte() throws IOException {
  List<KeyValue> kvList = new ArrayList<KeyValue>();
  byte[] row = Bytes.toBytes("abcd");
  byte[] family = new byte[] { 'f' };
  byte[] qualifier0 = new byte[] { 'b' };
  byte[] qualifier1 = new byte[] { 'c' };
  byte[] value0 = new byte[] { 'd' };
  byte[] value1 = new byte[] { 0x00 };
  if (includesTags) {
    kvList.add(new KeyValue(row, family, qualifier0, 0, value0, new Tag[] { new Tag((byte) 1,
        "value1") }));
    kvList.add(new KeyValue(row, family, qualifier1, 0, value1, new Tag[] { new Tag((byte) 1,
        "value1") }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier0, 0, Type.Put, value0));
    kvList.add(new KeyValue(row, family, qualifier1, 0, Type.Put, value1));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
项目:pbase    文件:CellUtil.java   
/**
 * @param cell
 * @return The Key portion of the passed <code>cell</code> as a String.
 */
public static String getCellKeyAsString(Cell cell) {
  StringBuilder sb = new StringBuilder(Bytes.toStringBinary(
    cell.getRowArray(), cell.getRowOffset(), cell.getRowLength()));
  sb.append('/');
  sb.append(cell.getFamilyLength() == 0? "":
    Bytes.toStringBinary(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()));
  // KeyValue only added ':' if family is non-null.  Do same.
  if (cell.getFamilyLength() > 0) sb.append(':');
  sb.append(cell.getQualifierLength() == 0? "":
    Bytes.toStringBinary(cell.getQualifierArray(), cell.getQualifierOffset(),
      cell.getQualifierLength()));
  sb.append('/');
  sb.append(KeyValue.humanReadableTimestamp(cell.getTimestamp()));
  sb.append('/');
  sb.append(Type.codeToType(cell.getTypeByte()));
  sb.append("/vlen=");
  sb.append(cell.getValueLength());
  sb.append("/seqid=");
  sb.append(cell.getSequenceId());
  return sb.toString();
}
项目:pbase    文件:TestCellUtil.java   
/**
 * Assert CellUtil makes Cell toStrings same way we do KeyValue toStrings.
 */
@Test
public void testToString() {
  byte [] row = Bytes.toBytes("row");
  long ts = 123l;
  // Make a KeyValue and a Cell and see if same toString result.
  KeyValue kv = new KeyValue(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY,
      ts, KeyValue.Type.Minimum, HConstants.EMPTY_BYTE_ARRAY);
  Cell cell = CellUtil.createCell(row, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY,
      ts, KeyValue.Type.Minimum.getCode(), HConstants.EMPTY_BYTE_ARRAY);
  String cellToString = CellUtil.getCellKeyAsString(cell);
  assertEquals(kv.toString(), cellToString);
  // Do another w/ non-null family.
  byte [] f = new byte [] {'f'};
  byte [] q = new byte [] {'q'};
  kv = new KeyValue(row, f, q, ts, KeyValue.Type.Minimum, HConstants.EMPTY_BYTE_ARRAY);
  cell = CellUtil.createCell(row, f, q, ts, KeyValue.Type.Minimum.getCode(),
      HConstants.EMPTY_BYTE_ARRAY);
  cellToString = CellUtil.getCellKeyAsString(cell);
  assertEquals(kv.toString(), cellToString);

}
项目:pbase    文件:TestKeyValue.java   
public void testColumnCompare() throws Exception {
  final byte [] a = Bytes.toBytes("aaa");
  byte [] family1 = Bytes.toBytes("abc");
  byte [] qualifier1 = Bytes.toBytes("def");
  byte [] family2 = Bytes.toBytes("abcd");
  byte [] qualifier2 = Bytes.toBytes("ef");

  KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, Type.Put, a);
  assertFalse(CellUtil.matchingColumn(aaa, family2, qualifier2));
  assertTrue(CellUtil.matchingColumn(aaa, family1, qualifier1));
  aaa = new KeyValue(a, family2, qualifier2, 0L, Type.Put, a);
  assertFalse(CellUtil.matchingColumn(aaa, family1, qualifier1));
  assertTrue(CellUtil.matchingColumn(aaa, family2,qualifier2));
  byte [] nullQualifier = new byte[0];
  aaa = new KeyValue(a, family1, nullQualifier, 0L, Type.Put, a);
  assertTrue(CellUtil.matchingColumn(aaa, family1,null));
  assertFalse(CellUtil.matchingColumn(aaa, family2,qualifier2));
}
项目:pbase    文件:TestKeyValue.java   
public void testPlainCompare() throws Exception {
  final byte [] a = Bytes.toBytes("aaa");
  final byte [] b = Bytes.toBytes("bbb");
  final byte [] fam = Bytes.toBytes("col");
  final byte [] qf = Bytes.toBytes("umn");
  KeyValue aaa = new KeyValue(a, fam, qf, a);
  KeyValue bbb = new KeyValue(b, fam, qf, b);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) > 0);
  // Compare breaks if passed same ByteBuffer as both left and right arguments.
  assertTrue(KeyValue.COMPARATOR.compare(bbb, bbb) == 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
  // Do compare with different timestamps.
  aaa = new KeyValue(a, fam, qf, 1, a);
  bbb = new KeyValue(a, fam, qf, 2, a);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) > 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
  // Do compare with different types.  Higher numbered types -- Delete
  // should sort ahead of lower numbers; i.e. Put
  aaa = new KeyValue(a, fam, qf, 1, KeyValue.Type.Delete, a);
  bbb = new KeyValue(a, fam, qf, 1, a);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) > 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
}
项目:HIndex    文件:LabelExpander.java   
/**
 * Creates a kv from the cell visibility expr specified in the ImportTSV and uses it as the
 * visibility tag in the kv
 * @param rowKeyOffset
 * @param rowKeyLength
 * @param family
 * @param familyOffset
 * @param familyLength
 * @param qualifier
 * @param qualifierOffset
 * @param qualifierLength
 * @param ts
 * @param put
 * @param lineBytes
 * @param columnOffset
 * @param columnLength
 * @param cellVisibilityExpr
 * @return KeyValue from the cell visibility expr
 * @throws IOException
 * @throws BadTsvLineException
 */
public KeyValue createKVFromCellVisibilityExpr(int rowKeyOffset, int rowKeyLength, byte[] family,
    int familyOffset, int familyLength, byte[] qualifier, int qualifierOffset,
    int qualifierLength, long ts, Type put, byte[] lineBytes, int columnOffset, int columnLength,
    String cellVisibilityExpr) throws IOException, BadTsvLineException {
  if(this.labels == null  && cellVisibilityExpr != null) {
    createLabels();
  }
  KeyValue kv = null;
  if (cellVisibilityExpr != null) {
    // Apply the expansion and parsing here
    List<Tag> visibilityTags = createVisibilityTags(cellVisibilityExpr);
    kv = new KeyValue(lineBytes, rowKeyOffset, rowKeyLength, family, familyOffset, familyLength,
        qualifier, qualifierOffset, qualifierLength, ts, KeyValue.Type.Put, lineBytes, columnOffset,
        columnLength, visibilityTags);
  } else {
    kv = new KeyValue(lineBytes, rowKeyOffset, rowKeyLength, family, familyOffset, familyLength,
        qualifier, qualifierOffset, qualifierLength, ts, KeyValue.Type.Put, lineBytes, columnOffset,
        columnLength);
  }
  return kv;
}
项目:HIndex    文件:TestQueryMatcher.java   
private void testDropDeletes(
    byte[] from, byte[] to, byte[][] rows, MatchCode... expected) throws IOException {
  long now = EnvironmentEdgeManager.currentTimeMillis();
  // Set time to purge deletes to negative value to avoid it ever happening.
  ScanInfo scanInfo = new ScanInfo(fam2, 0, 1, ttl, false, -1L, rowComparator);
  NavigableSet<byte[]> cols = get.getFamilyMap().get(fam2);

  ScanQueryMatcher qm = new ScanQueryMatcher(scan, scanInfo, cols, Long.MAX_VALUE,
      HConstants.OLDEST_TIMESTAMP, HConstants.OLDEST_TIMESTAMP, from, to, null);
  List<ScanQueryMatcher.MatchCode> actual =
      new ArrayList<ScanQueryMatcher.MatchCode>(rows.length);
  byte[] prevRow = null;
  for (byte[] row : rows) {
    if (prevRow == null || !Bytes.equals(prevRow, row)) {
      qm.setRow(row, 0, (short)row.length);
      prevRow = row;
    }
    actual.add(qm.match(new KeyValue(row, fam2, null, now, Type.Delete)));
  }

  assertEquals(expected.length, actual.size());
  for (int i = 0; i < expected.length; i++) {
    if (PRINT) System.out.println("expected " + expected[i] + ", actual " + actual.get(i));
    assertEquals(expected[i], actual.get(i));
  }
}
项目:HIndex    文件:TestDataBlockEncoders.java   
/**
 * Test KeyValues with negative timestamp.
 * 
 * @throws IOException
 *           On test failure.
 */
@Test
public void testNegativeTimestamps() throws IOException {
  List<KeyValue> kvList = new ArrayList<KeyValue>();
  byte[] row = new byte[0];
  byte[] family = new byte[0];
  byte[] qualifier = new byte[0];
  byte[] value = new byte[0];
  if (includesTags) {
    byte[] metaValue1 = Bytes.toBytes("metaValue1");
    byte[] metaValue2 = Bytes.toBytes("metaValue2");
    kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new Tag((byte) 1,
        metaValue1) }));
    kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new Tag((byte) 1,
        metaValue2) }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier, -1l, Type.Put, value));
    kvList.add(new KeyValue(row, family, qualifier, -2l, Type.Put, value));
  }
  testEncodersOnDataset(RedundantKVGenerator.convertKvToByteBuffer(kvList, includesMemstoreTS),
      kvList);
}
项目:HIndex    文件:TestDataBlockEncoders.java   
@Test
public void testZeroByte() throws IOException {
  List<KeyValue> kvList = new ArrayList<KeyValue>();
  byte[] row = Bytes.toBytes("abcd");
  byte[] family = new byte[] { 'f' };
  byte[] qualifier0 = new byte[] { 'b' };
  byte[] qualifier1 = new byte[] { 'c' };
  byte[] value0 = new byte[] { 'd' };
  byte[] value1 = new byte[] { 0x00 };
  if (includesTags) {
    kvList.add(new KeyValue(row, family, qualifier0, 0, value0, new Tag[] { new Tag((byte) 1,
        "value1") }));
    kvList.add(new KeyValue(row, family, qualifier1, 0, value1, new Tag[] { new Tag((byte) 1,
        "value1") }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier0, 0, Type.Put, value0));
    kvList.add(new KeyValue(row, family, qualifier1, 0, Type.Put, value1));
  }
  testEncodersOnDataset(RedundantKVGenerator.convertKvToByteBuffer(kvList, includesMemstoreTS),
      kvList);
}
项目:HIndex    文件:TestKeyValue.java   
public void testColumnCompare() throws Exception {
  final byte [] a = Bytes.toBytes("aaa");
  byte [] family1 = Bytes.toBytes("abc");
  byte [] qualifier1 = Bytes.toBytes("def");
  byte [] family2 = Bytes.toBytes("abcd");
  byte [] qualifier2 = Bytes.toBytes("ef");

  KeyValue aaa = new KeyValue(a, family1, qualifier1, 0L, Type.Put, a);
  assertFalse(aaa.matchingColumn(family2, qualifier2));
  assertTrue(aaa.matchingColumn(family1, qualifier1));
  aaa = new KeyValue(a, family2, qualifier2, 0L, Type.Put, a);
  assertFalse(aaa.matchingColumn(family1, qualifier1));
  assertTrue(aaa.matchingColumn(family2,qualifier2));
  byte [] nullQualifier = new byte[0];
  aaa = new KeyValue(a, family1, nullQualifier, 0L, Type.Put, a);
  assertTrue(aaa.matchingColumn(family1,null));
  assertFalse(aaa.matchingColumn(family2,qualifier2));
}
项目:HIndex    文件:TestKeyValue.java   
public void testPlainCompare() throws Exception {
  final byte [] a = Bytes.toBytes("aaa");
  final byte [] b = Bytes.toBytes("bbb");
  final byte [] fam = Bytes.toBytes("col");
  final byte [] qf = Bytes.toBytes("umn");
  KeyValue aaa = new KeyValue(a, fam, qf, a);
  KeyValue bbb = new KeyValue(b, fam, qf, b);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) > 0);
  // Compare breaks if passed same ByteBuffer as both left and right arguments.
  assertTrue(KeyValue.COMPARATOR.compare(bbb, bbb) == 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
  // Do compare with different timestamps.
  aaa = new KeyValue(a, fam, qf, 1, a);
  bbb = new KeyValue(a, fam, qf, 2, a);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) > 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
  // Do compare with different types.  Higher numbered types -- Delete
  // should sort ahead of lower numbers; i.e. Put
  aaa = new KeyValue(a, fam, qf, 1, KeyValue.Type.Delete, a);
  bbb = new KeyValue(a, fam, qf, 1, a);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, bbb) < 0);
  assertTrue(KeyValue.COMPARATOR.compare(bbb, aaa) > 0);
  assertTrue(KeyValue.COMPARATOR.compare(aaa, aaa) == 0);
}
项目:themis    文件:DefaultIndexer.java   
@Override
public void addIndexMutations(ColumnMutationCache mutationCache) throws IOException {
  for (Entry<byte[], Map<byte[], RowMutation>> tableMutation : mutationCache.getMutations()) {
    byte[] tableName = tableMutation.getKey();
    for (Entry<byte[], RowMutation> rowMutation : tableMutation.getValue().entrySet()) {
      byte[] row = rowMutation.getKey();
      for (ColumnMutation columnMuation : rowMutation.getValue().mutationList()) {
        if (columnMuation.getType().equals(Type.Put)) {
          IndexColumn indexColumn = new IndexColumn(tableName, columnMuation.getFamily(),
              columnMuation.getQualifier());
          if (columnIndexes.containsKey(indexColumn)) {
            String indexTableName = columnIndexes.get(indexColumn);
            KeyValue indexKv = constructIndexKv(row, columnMuation.getValue());
            mutationCache.addMutation(Bytes.toBytes(indexTableName), indexKv);
          }
        }
      }
    }
  }
}
项目:PyroDB    文件:TestDataBlockEncoders.java   
/**
 * Test KeyValues with negative timestamp.
 * 
 * @throws IOException
 *           On test failure.
 */
@Test
public void testNegativeTimestamps() throws IOException {
  List<KeyValue> kvList = new ArrayList<KeyValue>();
  byte[] row = new byte[0];
  byte[] family = new byte[0];
  byte[] qualifier = new byte[0];
  byte[] value = new byte[0];
  if (includesTags) {
    byte[] metaValue1 = Bytes.toBytes("metaValue1");
    byte[] metaValue2 = Bytes.toBytes("metaValue2");
    kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new Tag((byte) 1,
        metaValue1) }));
    kvList.add(new KeyValue(row, family, qualifier, 0l, value, new Tag[] { new Tag((byte) 1,
        metaValue2) }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier, -1l, Type.Put, value));
    kvList.add(new KeyValue(row, family, qualifier, -2l, Type.Put, value));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
项目:c5    文件:TestQueryMatcher.java   
private void testDropDeletes(
    byte[] from, byte[] to, byte[][] rows, MatchCode... expected) throws IOException {
  long now = EnvironmentEdgeManager.currentTimeMillis();
  // Set time to purge deletes to negative value to avoid it ever happening.
  ScanInfo scanInfo = new ScanInfo(fam2, 0, 1, ttl, false, -1L, rowComparator);
  NavigableSet<byte[]> cols = get.getFamilyMap().get(fam2);

  ScanQueryMatcher qm = new ScanQueryMatcher(scan, scanInfo, cols, Long.MAX_VALUE,
      HConstants.OLDEST_TIMESTAMP, HConstants.OLDEST_TIMESTAMP, from, to);
  List<ScanQueryMatcher.MatchCode> actual =
      new ArrayList<ScanQueryMatcher.MatchCode>(rows.length);
  byte[] prevRow = null;
  for (byte[] row : rows) {
    if (prevRow == null || !Bytes.equals(prevRow, row)) {
      qm.setRow(row, 0, (short)row.length);
      prevRow = row;
    }
    actual.add(qm.match(new KeyValue(row, fam2, null, now, Type.Delete)));
  }

  assertEquals(expected.length, actual.size());
  for (int i = 0; i < expected.length; i++) {
    if (PRINT) System.out.println("expected " + expected[i] + ", actual " + actual.get(i));
    assertEquals(expected[i], actual.get(i));
  }
}
项目:themis    文件:PrimaryLock.java   
@Override
public boolean equals(Object object) {
  if (!(object instanceof PrimaryLock)) {
    return false;
  }
  PrimaryLock lock = (PrimaryLock)object;
  if (!super.equals((ThemisLock)lock)) {
    return false;
  }
  if (!lock.isPrimary()) {
    return false;
  }
  if (this.secondaryColumns.size() != lock.secondaryColumns.size()) {
    return false;
  }
  for (Entry<ColumnCoordinate, Type> columnAndType : secondaryColumns.entrySet()) {
    Type type = lock.secondaryColumns.get(columnAndType.getKey());
    if (type == null || !columnAndType.getValue().equals(type)) {
      return false;
    }
  }
  return true;
}
项目:themis    文件:TestThemisCoprocessorWrite.java   
@Test
public void testWriteNonThemisFamily() throws IOException {
  HBaseAdmin admin = new HBaseAdmin(conf);
  byte[] testTable = Bytes.toBytes("test_table");
  byte[] testFamily = Bytes.toBytes("test_family");

  // create table without setting THEMIS_ENABLE
  deleteTable(admin, testTable);
  HTableDescriptor tableDesc = new HTableDescriptor(testTable);
  HColumnDescriptor columnDesc = new HColumnDescriptor(testFamily);
  tableDesc.addFamily(columnDesc);
  admin.createTable(tableDesc);
  try {
    ColumnMutation mutation = new ColumnMutation(new Column(testFamily, COLUMN.getQualifier()),
        Type.Put, VALUE);
    cpClient.prewriteRow(testTable, PRIMARY_ROW.getRow(), Lists.newArrayList(mutation), prewriteTs,
      ThemisLock.toByte(getLock(COLUMN)), getSecondaryLockBytes(), 2);
  } catch (IOException e) {
    e.printStackTrace();
    Assert.assertTrue(e.getMessage().indexOf("can not access family") >= 0);
  }
  admin.close();
}
项目:themis    文件:TestThemisCpUtil.java   
@Test
public void testRemoveNotRequiredLockColumns() {
  Get get = new Get(ROW);
  get.addFamily(FAMILY);
  get.addColumn(ANOTHER_FAMILY, ANOTHER_QUALIFIER);
  List<KeyValue> sourceKvs = new ArrayList<KeyValue>();
  sourceKvs.add(KEYVALUE);
  Column lockColumn = ColumnUtil.getLockColumn(FAMILY, QUALIFIER);
  KeyValue lockKv = new KeyValue(ROW, lockColumn.getFamily(), lockColumn.getQualifier(), PREWRITE_TS,
    Type.Put, VALUE);
  sourceKvs.add(lockKv);
  lockColumn = ColumnUtil.getLockColumn(ANOTHER_FAMILY, QUALIFIER);
  sourceKvs.add(new KeyValue(ROW, lockColumn.getFamily(), lockColumn.getQualifier(), PREWRITE_TS,
      Type.Put, VALUE));
  Result result = ThemisCpUtil.removeNotRequiredLockColumns(get.getFamilyMap(), new Result(
      sourceKvs));
  Assert.assertEquals(2, result.size());
  Assert.assertTrue(KEYVALUE.equals(result.list().get(0)));
  Assert.assertTrue(lockKv.equals(result.list().get(1)));
}
项目:themis    文件:TestThemisCpUtil.java   
@Test
public void testSeperateLockAndWriteKvs() {
  List<KeyValue> kvs = new ArrayList<KeyValue>();
  kvs.add(KEYVALUE);
  kvs.add(getLockKv(KEYVALUE));
  kvs.add(getPutKv(KEYVALUE));
  Column column = ColumnUtil.getDeleteColumn(new Column(FAMILY, QUALIFIER));
  KeyValue deleteKv = new KeyValue(ROW, column.getFamily(), column.getQualifier(), PREWRITE_TS, Type.Put, VALUE);
  kvs.add(deleteKv);
  Pair<List<KeyValue>, List<KeyValue>> result = ThemisCpUtil.seperateLockAndWriteKvs(kvs);
  Assert.assertEquals(1, result.getFirst().size());
  Assert.assertTrue(getLockKv(KEYVALUE).equals(result.getFirst().get(0)));
  Assert.assertEquals(2, result.getSecond().size());
  Assert.assertTrue(getPutKv(KEYVALUE).equals(result.getSecond().get(0)));
  Assert.assertTrue(deleteKv.equals(result.getSecond().get(1)));

  result = ThemisCpUtil.seperateLockAndWriteKvs(null);
  Assert.assertEquals(0, result.getFirst().size());
  Assert.assertEquals(0, result.getSecond().size());
}
项目:PyroDB    文件:TestQueryMatcher.java   
private void testDropDeletes(
    byte[] from, byte[] to, byte[][] rows, MatchCode... expected) throws IOException {
  long now = EnvironmentEdgeManager.currentTimeMillis();
  // Set time to purge deletes to negative value to avoid it ever happening.
  ScanInfo scanInfo = new ScanInfo(fam2, 0, 1, ttl, false, -1L, rowComparator);
  NavigableSet<byte[]> cols = get.getFamilyMap().get(fam2);

  ScanQueryMatcher qm = new ScanQueryMatcher(scan, scanInfo, cols, Long.MAX_VALUE,
      HConstants.OLDEST_TIMESTAMP, HConstants.OLDEST_TIMESTAMP, from, to, null);
  List<ScanQueryMatcher.MatchCode> actual =
      new ArrayList<ScanQueryMatcher.MatchCode>(rows.length);
  byte[] prevRow = null;
  for (byte[] row : rows) {
    if (prevRow == null || !Bytes.equals(prevRow, row)) {
      qm.setRow(row, 0, (short)row.length);
      prevRow = row;
    }
    actual.add(qm.match(new KeyValue(row, fam2, null, now, Type.Delete)));
  }

  assertEquals(expected.length, actual.size());
  for (int i = 0; i < expected.length; i++) {
    if (PRINT) System.out.println("expected " + expected[i] + ", actual " + actual.get(i));
    assertEquals(expected[i], actual.get(i));
  }
}
项目:hbase    文件:NewVersionBehaviorTracker.java   
@Override
public void add(Cell cell) {
  prepare(cell);
  byte type = cell.getTypeByte();
  switch (Type.codeToType(type)) {
  // By the order of seen. We put null cq at first.
  case DeleteFamily: // Delete all versions of all columns of the specified family
    delFamMap.put(cell.getSequenceId(),
        new DeleteVersionsNode(cell.getTimestamp(), cell.getSequenceId()));
    break;
  case DeleteFamilyVersion: // Delete all columns of the specified family and specified version
    delFamMap.ceilingEntry(cell.getSequenceId()).getValue().addVersionDelete(cell);
    break;

  // These two kinds of markers are mix with Puts.
  case DeleteColumn: // Delete all versions of the specified column
    delColMap.put(cell.getSequenceId(),
        new DeleteVersionsNode(cell.getTimestamp(), cell.getSequenceId()));
    break;
  case Delete: // Delete the specified version of the specified column.
    delColMap.ceilingEntry(cell.getSequenceId()).getValue().addVersionDelete(cell);
    break;
  default:
    throw new AssertionError("Unknown delete marker type for " + cell);
  }
}
项目:PyroDB    文件:TestDataBlockEncoders.java   
@Test
public void testZeroByte() throws IOException {
  List<KeyValue> kvList = new ArrayList<KeyValue>();
  byte[] row = Bytes.toBytes("abcd");
  byte[] family = new byte[] { 'f' };
  byte[] qualifier0 = new byte[] { 'b' };
  byte[] qualifier1 = new byte[] { 'c' };
  byte[] value0 = new byte[] { 'd' };
  byte[] value1 = new byte[] { 0x00 };
  if (includesTags) {
    kvList.add(new KeyValue(row, family, qualifier0, 0, value0, new Tag[] { new Tag((byte) 1,
        "value1") }));
    kvList.add(new KeyValue(row, family, qualifier1, 0, value1, new Tag[] { new Tag((byte) 1,
        "value1") }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier0, 0, Type.Put, value0));
    kvList.add(new KeyValue(row, family, qualifier1, 0, Type.Put, value1));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
项目:hbase    文件:TestCompactionScanQueryMatcher.java   
private void testDropDeletes(byte[] from, byte[] to, byte[][] rows, MatchCode... expected)
    throws IOException {
  long now = EnvironmentEdgeManager.currentTime();
  // Set time to purge deletes to negative value to avoid it ever happening.
  ScanInfo scanInfo = new ScanInfo(this.conf, fam2, 0, 1, ttl, KeepDeletedCells.FALSE,
      HConstants.DEFAULT_BLOCKSIZE, -1L, rowComparator, false);

  CompactionScanQueryMatcher qm = CompactionScanQueryMatcher.create(scanInfo,
    ScanType.COMPACT_RETAIN_DELETES, Long.MAX_VALUE, HConstants.OLDEST_TIMESTAMP,
    HConstants.OLDEST_TIMESTAMP, now, from, to, null);
  List<ScanQueryMatcher.MatchCode> actual = new ArrayList<>(rows.length);
  byte[] prevRow = null;
  for (byte[] row : rows) {
    if (prevRow == null || !Bytes.equals(prevRow, row)) {
      qm.setToNewRow(KeyValueUtil.createFirstOnRow(row));
      prevRow = row;
    }
    actual.add(qm.match(new KeyValue(row, fam2, null, now, Type.Delete)));
  }

  assertEquals(expected.length, actual.size());
  for (int i = 0; i < expected.length; i++) {
    LOG.debug("expected " + expected[i] + ", actual " + actual.get(i));
    assertEquals(expected[i], actual.get(i));
  }
}
项目:hbase    文件:TestDataBlockEncoders.java   
/**
 * Test KeyValues with negative timestamp.
 *
 * @throws IOException
 *           On test failure.
 */
@Test
public void testNegativeTimestamps() throws IOException {
  List<KeyValue> kvList = new ArrayList<>();
  byte[] row = new byte[0];
  byte[] family = new byte[0];
  byte[] qualifier = new byte[0];
  byte[] value = new byte[0];
  if (includesTags) {
    byte[] metaValue1 = Bytes.toBytes("metaValue1");
    byte[] metaValue2 = Bytes.toBytes("metaValue2");
    kvList.add(new KeyValue(row, family, qualifier, 0L, value,
        new Tag[] { new ArrayBackedTag((byte) 1, metaValue1) }));
    kvList.add(new KeyValue(row, family, qualifier, 0L, value,
        new Tag[] { new ArrayBackedTag((byte) 1, metaValue2) }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier, -1L, Type.Put, value));
    kvList.add(new KeyValue(row, family, qualifier, -2L, Type.Put, value));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
项目:hbase    文件:TestDataBlockEncoders.java   
@Test
public void testZeroByte() throws IOException {
  List<KeyValue> kvList = new ArrayList<>();
  byte[] row = Bytes.toBytes("abcd");
  byte[] family = new byte[] { 'f' };
  byte[] qualifier0 = new byte[] { 'b' };
  byte[] qualifier1 = new byte[] { 'c' };
  byte[] value0 = new byte[] { 'd' };
  byte[] value1 = new byte[] { 0x00 };
  if (includesTags) {
    kvList.add(new KeyValue(row, family, qualifier0, 0, value0,
        new Tag[] { new ArrayBackedTag((byte) 1, "value1") }));
    kvList.add(new KeyValue(row, family, qualifier1, 0, value1,
        new Tag[] { new ArrayBackedTag((byte) 1, "value1") }));
  } else {
    kvList.add(new KeyValue(row, family, qualifier0, 0, Type.Put, value0));
    kvList.add(new KeyValue(row, family, qualifier1, 0, Type.Put, value1));
  }
  testEncodersOnDataset(kvList, includesMemstoreTS, includesTags);
}
项目:ditb    文件:ScanQueryMatcher.java   
/**
 * @param nextIndexed the key of the next entry in the block index (if any)
 * @param kv The Cell we're using to calculate the seek key
 * @return result of the compare between the indexed key and the key portion of the passed cell
 */
public int compareKeyForNextRow(Cell nextIndexed, Cell kv) {
  return rowComparator.compareKey(nextIndexed,
    kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(),
    null, 0, 0,
    null, 0, 0,
    HConstants.OLDEST_TIMESTAMP, Type.Minimum.getCode());
}
项目:ditb    文件:TestQueryMatcher.java   
private void testDropDeletes(
    byte[] from, byte[] to, byte[][] rows, MatchCode... expected) throws IOException {
  long now = EnvironmentEdgeManager.currentTime();
  // Set time to purge deletes to negative value to avoid it ever happening.
  ScanInfo scanInfo =
    new ScanInfo(this.conf, fam2, 0, 1, ttl, KeepDeletedCells.FALSE, -1L, rowComparator);
  NavigableSet<byte[]> cols = get.getFamilyMap().get(fam2);

  ScanQueryMatcher qm = new ScanQueryMatcher(scan, scanInfo, cols, Long.MAX_VALUE,
      HConstants.OLDEST_TIMESTAMP, HConstants.OLDEST_TIMESTAMP, now, from, to, null);
  List<ScanQueryMatcher.MatchCode> actual =
      new ArrayList<ScanQueryMatcher.MatchCode>(rows.length);
  byte[] prevRow = null;
  for (byte[] row : rows) {
    if (prevRow == null || !Bytes.equals(prevRow, row)) {
      qm.setRow(row, 0, (short)row.length);
      prevRow = row;
    }
    actual.add(qm.match(new KeyValue(row, fam2, null, now, Type.Delete)));
  }

  assertEquals(expected.length, actual.size());
  for (int i = 0; i < expected.length; i++) {
    if (PRINT) System.out.println("expected " + expected[i] + ", actual " + actual.get(i));
    assertEquals(expected[i], actual.get(i));
  }
}
项目:ditb    文件:PrefixTreeSeeker.java   
@Override
public String toString() {
  String row = Bytes.toStringBinary(getRowArray(), getRowOffset(), getRowLength());
  String family = Bytes.toStringBinary(getFamilyArray(), getFamilyOffset(), getFamilyLength());
  String qualifier = Bytes.toStringBinary(getQualifierArray(), getQualifierOffset(),
      getQualifierLength());
  String timestamp = String.valueOf((getTimestamp()));
  return row + "/" + family + (family != null && family.length() > 0 ? ":" : "") + qualifier
      + "/" + timestamp + "/" + Type.codeToType(type);
}
项目:ditb    文件:KeyValueUtil.java   
/**
 * Creates the first KV with the row/family/qualifier of this KV and the
 * given timestamp. Uses the "maximum" KV type that guarantees that the new
 * KV is the lowest possible for this combination of row, family, qualifier,
 * and timestamp. This KV's own timestamp is ignored. While this function
 * copies the value from this KV, it is normally used on key-only KVs.
 */
public static KeyValue createFirstOnRowColTS(KeyValue kv, long ts) {
  return new KeyValue(
      kv.getRowArray(), kv.getRowOffset(), kv.getRowLength(),
      kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(),
      kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(),
      ts, Type.Maximum, kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
}
项目:ditb    文件:CellUtil.java   
public static Cell createCell(final byte [] row, final byte [] family, final byte [] qualifier,
    final long timestamp, final byte type, final byte [] value) {
  // I need a Cell Factory here.  Using KeyValue for now. TODO.
  // TODO: Make a new Cell implementation that just carries these
  // byte arrays.
  // TODO: Call factory to create Cell
  return new KeyValue(row, family, qualifier, timestamp, KeyValue.Type.codeToType(type), value);
}
项目:ditb    文件:CellUtil.java   
public static Cell createCell(final byte [] rowArray, final int rowOffset, final int rowLength,
    final byte [] familyArray, final int familyOffset, final int familyLength,
    final byte [] qualifierArray, final int qualifierOffset, final int qualifierLength) {
  // See createCell(final byte [] row, final byte [] value) for why we default Maximum type.
  return new KeyValue(rowArray, rowOffset, rowLength,
      familyArray, familyOffset, familyLength,
      qualifierArray, qualifierOffset, qualifierLength,
      HConstants.LATEST_TIMESTAMP,
      KeyValue.Type.Maximum,
      HConstants.EMPTY_BYTE_ARRAY, 0, HConstants.EMPTY_BYTE_ARRAY.length);
}