Package org.apache.hadoop.hbase.KeyValue

Examples of org.apache.hadoop.hbase.KeyValue.KeyComparator


   */
  public long updateColumnValue(byte [] row, byte [] f,
      byte [] qualifier, long newValue)
  throws IOException {
    List<KeyValue> result = new ArrayList<KeyValue>();
    KeyComparator keyComparator = this.comparator.getRawComparator();

    KeyValue kv = null;
    // Setting up the QueryMatcher
    Get get = new Get(row);
    NavigableSet<byte[]> qualifiers =
View Full Code Here


  public void testComparator() throws IOException {
    if (cacheConf == null) cacheConf = new CacheConfig(conf);
    Path mFile = new Path(ROOT_DIR, "meta.tfile");
    FSDataOutputStream fout = createFSOutput(mFile);
    Writer writer = HFile.getWriterFactory(conf, cacheConf).createWriter(fout,
      minBlockSize, (Compression.Algorithm) null, new KeyComparator() {
        @Override
        public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2,
            int l2) {
          return -Bytes.compareTo(b1, s1, l1, b2, s2, l2);
View Full Code Here

  public void testComparator() throws IOException {
    if (cacheConf == null) cacheConf = new CacheConfig(conf);
    Path mFile = new Path(ROOT_DIR, "meta.tfile");
    FSDataOutputStream fout = createFSOutput(mFile);
    KeyComparator comparator = new CustomKeyComparator();
    Writer writer = HFile.getWriterFactory(conf, cacheConf)
        .withOutputStream(fout)
        .withBlockSize(minBlockSize)
        .withComparator(comparator)
        .create();
View Full Code Here

  /**
   * See HBASE-7845
   */
  public void testGetShortMidpointKey() {
    final KeyComparator keyComparator = new KeyValue.KeyComparator();
    //verify that faked shorter rowkey could be generated
    long ts = 5;
    KeyValue kv1 = new KeyValue(Bytes.toBytes("the quick brown fox"), family, qualA, ts, Type.Put);
    KeyValue kv2 = new KeyValue(Bytes.toBytes("the who test text"), family, qualA, ts, Type.Put);
    byte[] newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compare(newKey, kv2.getKey()) < 0);
    short newRowLength = Bytes.toShort(newKey, 0);
    byte[] expectedArray = Bytes.toBytes("the r");
    Bytes.equals(newKey, KeyValue.ROW_LENGTH_SIZE, newRowLength, expectedArray, 0,
      expectedArray.length);

    //verify: same with "row + family + qualifier", return rightKey directly
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 5, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 0, Type.Put);
    assertTrue(keyComparator.compare(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compare(newKey, kv2.getKey()) == 0);
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, -5, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, -10, Type.Put);
    assertTrue(keyComparator.compare(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compare(newKey, kv2.getKey()) == 0);

    // verify: same with row, different with qualifier
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 5, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualB, 5, Type.Put);
    assertTrue(keyComparator.compare(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compare(newKey, kv2.getKey()) < 0);
    KeyValue newKeyValue = KeyValue.createKeyValueFromKey(newKey);
    assertTrue(Arrays.equals(newKeyValue.getFamily(),family));
    assertTrue(Arrays.equals(newKeyValue.getQualifier(),qualB));
    assertTrue(newKeyValue.getTimestamp() == HConstants.LATEST_TIMESTAMP);
    assertTrue(newKeyValue.getType() == Type.Maximum.getCode());

    //verify metaKeyComparator's getShortMidpointKey output
    final KeyComparator metaKeyComparator = new KeyValue.MetaKeyComparator();
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase123"), family, qualA, 5, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbase234"), family, qualA, 0, Type.Put);
    newKey = metaKeyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(metaKeyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(metaKeyComparator.compare(newKey, kv2.getKey()) == 0);

    //verify common fix scenario
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, ts, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbaseandhdfs"), family, qualA, ts, Type.Put);
    assertTrue(keyComparator.compare(kv1.getKey(), kv2.getKey()) < 0);
View Full Code Here

  /**
   * See HBASE-7845
   */
  public void testGetShortMidpointKey() {
    final KeyComparator keyComparator = new KeyValue.KeyComparator();
    //verify that faked shorter rowkey could be generated
    long ts = 5;
    KeyValue kv1 = new KeyValue(Bytes.toBytes("the quick brown fox"), family, qualA, ts, Type.Put);
    KeyValue kv2 = new KeyValue(Bytes.toBytes("the who test text"), family, qualA, ts, Type.Put);
    byte[] newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compare(newKey, kv2.getKey()) < 0);
    short newRowLength = Bytes.toShort(newKey, 0);
    byte[] expectedArray = Bytes.toBytes("the r");
    Bytes.equals(newKey, KeyValue.ROW_LENGTH_SIZE, newRowLength, expectedArray, 0,
      expectedArray.length);

    //verify: same with "row + family + qualifier", return rightKey directly
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 5, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 0, Type.Put);
    assertTrue(keyComparator.compare(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compare(newKey, kv2.getKey()) == 0);
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, -5, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, -10, Type.Put);
    assertTrue(keyComparator.compare(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compare(newKey, kv2.getKey()) == 0);

    // verify: same with row, different with qualifier
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, 5, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualB, 5, Type.Put);
    assertTrue(keyComparator.compare(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compare(newKey, kv2.getKey()) < 0);
    KeyValue newKeyValue = KeyValue.createKeyValueFromKey(newKey);
    assertTrue(Arrays.equals(newKeyValue.getFamily(),family));
    assertTrue(Arrays.equals(newKeyValue.getQualifier(),qualB));
    assertTrue(newKeyValue.getTimestamp() == HConstants.LATEST_TIMESTAMP);
    assertTrue(newKeyValue.getType() == Type.Maximum.getCode());

    //verify root/metaKeyComparator's getShortMidpointKey output
    final KeyComparator rootKeyComparator = new KeyValue.RootKeyComparator();
    final KeyComparator metaKeyComparator = new KeyValue.MetaKeyComparator();
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase123"), family, qualA, 5, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbase234"), family, qualA, 0, Type.Put);
    newKey = rootKeyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(rootKeyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(rootKeyComparator.compare(newKey, kv2.getKey()) == 0);
    newKey = metaKeyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(metaKeyComparator.compare(kv1.getKey(), newKey) < 0);
    assertTrue(metaKeyComparator.compare(newKey, kv2.getKey()) == 0);

    //verify common fix scenario
    kv1 = new KeyValue(Bytes.toBytes("ilovehbase"), family, qualA, ts, Type.Put);
    kv2 = new KeyValue(Bytes.toBytes("ilovehbaseandhdfs"), family, qualA, ts, Type.Put);
    assertTrue(keyComparator.compare(kv1.getKey(), kv2.getKey()) < 0);
View Full Code Here

  public void testComparator() throws IOException {
    if (cacheConf == null) cacheConf = new CacheConfig(conf);
    Path mFile = new Path(ROOT_DIR, "meta.tfile");
    FSDataOutputStream fout = createFSOutput(mFile);
    KeyComparator comparator = new CustomKeyComparator();
    Writer writer = HFile.getWriterFactory(conf, cacheConf)
        .withOutputStream(fout)
        .withBlockSize(minBlockSize)
        .withComparator(comparator)
        .create();
View Full Code Here

   * @param result List to add results to
   * @throws IOException
   */
  public void get(Get get, NavigableSet<byte[]> columns, List<KeyValue> result)
  throws IOException {
    KeyComparator keyComparator = this.comparator.getRawComparator();

    // Column matching and version enforcement
    QueryMatcher matcher = new QueryMatcher(get, this.family.getName(), columns,
      this.ttl, keyComparator, versionsToReturn(get.getMaxVersions()));
    this.lock.readLock().lock();
View Full Code Here

   */
  public long updateColumnValue(byte [] row, byte [] f,
      byte [] qualifier, long newValue)
  throws IOException {
    List<KeyValue> result = new ArrayList<KeyValue>();
    KeyComparator keyComparator = this.comparator.getRawComparator();

    KeyValue kv = null;
    // Setting up the QueryMatcher
    Get get = new Get(row);
    NavigableSet<byte[]> qualifiers =
View Full Code Here

  public void testComparator() throws IOException {
    Path mFile = new Path(ROOT_DIR, "meta.tfile");
    FSDataOutputStream fout = createFSOutput(mFile);
    Writer writer = new Writer(fout, minBlockSize, (Compression.Algorithm) null,
      new KeyComparator() {
        @Override
        public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2,
            int l2) {
          return -Bytes.compareTo(b1, s1, l1, b2, s2, l2);
View Full Code Here

  public void testComparator() throws IOException {
    if (cacheConf == null) cacheConf = new CacheConfig(conf);
    Path mFile = new Path(ROOT_DIR, "meta.tfile");
    FSDataOutputStream fout = createFSOutput(mFile);
    KeyComparator comparator = new KeyComparator() {
      @Override
      public int compare(byte[] b1, int s1, int l1, byte[] b2, int s2,
          int l2) {
        return -Bytes.compareTo(b1, s1, l1, b2, s2, l2);
      }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.KeyValue.KeyComparator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.