Package org.apache.hadoop.hbase.KeyValue

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


    }

    @Override
    public int compare(final Cell l, final Cell ignored) {
      assert ignored == null;
      KVComparator comparator = kvBuilder.getKeyValueComparator();
      // row
      int val = comparator.compareRows(l.getRowArray(), l.getRowOffset(),
        l.getRowLength(), row, rowOff, rowLen);
      if (val != 0) {
        return val;
      }
      // family
View Full Code Here


  private static StripeStoreFileManager createManager(
      ArrayList<StoreFile> sfs, Configuration conf) throws Exception {
    StripeStoreConfig config = new StripeStoreConfig(
        conf, Mockito.mock(StoreConfigInformation.class));
    StripeStoreFileManager result = new StripeStoreFileManager(new KVComparator(), conf, config);
    result.loadFiles(sfs);
    return result;
  }
View Full Code Here

    Configuration conf = HBaseConfiguration.create();
    final Scanner scanner = new Scanner(input);

    // Create store mock that is satisfactory for compactor.
    HColumnDescriptor col = new HColumnDescriptor(NAME_OF_THINGS);
    ScanInfo si = new ScanInfo(col, Long.MAX_VALUE, 0, new KVComparator());
    Store store = mock(Store.class);
    when(store.getFamily()).thenReturn(col);
    when(store.getScanInfo()).thenReturn(si);
    when(store.areWritesEnabled()).thenReturn(true);
    when(store.getFileSystem()).thenReturn(mock(FileSystem.class));
    when(store.getRegionInfo()).thenReturn(new HRegionInfo(TABLE_NAME));
    when(store.createWriterInTmp(anyLong(), any(Compression.Algorithm.class),
        anyBoolean(), anyBoolean(), anyBoolean())).thenAnswer(writers);
    when(store.getComparator()).thenReturn(new KVComparator());

    return new StripeCompactor(conf, store) {
      @Override
      protected InternalScanner createScanner(Store store, List<StoreFileScanner> scanners,
          long smallestReadPoint, long earliestPutTs, byte[] dropDeletesFromRow,
View Full Code Here

  }

  public void setComparatorClass(Class<? extends KVComparator> klass) {
    // Is the comparator instantiable?
    try {
      KVComparator comp = klass.newInstance();

      // HFile V2 legacy comparator class names.
      if (KeyValue.COMPARATOR.getClass().equals(klass)) {
        comparatorClassName = KeyValue.COMPARATOR.getLegacyKeyComparatorName();
      } else if (KeyValue.META_COMPARATOR.getClass().equals(klass)) {
View Full Code Here

    return sf;
  }

  private static TestStoreEngine createEngine(Configuration conf) throws Exception {
    Store store = mock(Store.class);
    KVComparator kvComparator = mock(KVComparator.class);
    return (TestStoreEngine)StoreEngine.create(store, conf, kvComparator);
  }
View Full Code Here

    conf.set(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY,
        DummyCompactionPolicy.class.getName());
    conf.set(DefaultStoreEngine.DEFAULT_STORE_FLUSHER_CLASS_KEY,
        DummyStoreFlusher.class.getName());
    Store mockStore = Mockito.mock(Store.class);
    StoreEngine<?, ?, ?, ?> se = StoreEngine.create(mockStore, conf, new KVComparator());
    Assert.assertTrue(se instanceof DefaultStoreEngine);
    Assert.assertTrue(se.getCompactionPolicy() instanceof DummyCompactionPolicy);
    Assert.assertTrue(se.getStoreFlusher() instanceof DummyStoreFlusher);
    Assert.assertTrue(se.getCompactor() instanceof DummyCompactor);
  }
View Full Code Here

    // Meta compares
    KeyValue aaa = new KeyValue(
        Bytes.toBytes("TestScanMultipleVersions,row_0500,1236020145502"), now);
    KeyValue bbb = new KeyValue(
        Bytes.toBytes("TestScanMultipleVersions,,99999999999999"), now);
    KVComparator c = new KeyValue.MetaComparator();
    assertTrue(c.compare(bbb, aaa) < 0);

    KeyValue aaaa = new KeyValue(Bytes.toBytes("TestScanMultipleVersions,,1236023996656"),
        Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1236024396271L,
        (byte[])null);
    assertTrue(c.compare(aaaa, bbb) < 0);

    KeyValue x = new KeyValue(Bytes.toBytes("TestScanMultipleVersions,row_0500,1236034574162"),
        Bytes.toBytes("info"), Bytes.toBytes(""), 9223372036854775807L,
        (byte[])null);
    KeyValue y = new KeyValue(Bytes.toBytes("TestScanMultipleVersions,row_0500,1236034574162"),
        Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1236034574912L,
        (byte[])null);
    assertTrue(c.compare(x, y) < 0);
    comparisons(new KeyValue.MetaComparator());
    comparisons(new KeyValue.KVComparator());
    metacomparisons(new KeyValue.MetaComparator());
  }
View Full Code Here

    // 'fami:qf1' < 'fami:qf2'. They have commonPrefix + 6 same prefix bytes.
    assertKVLessWithoutRow(c, commonLength + 6, kv0_1, kv0_2);
  }

  public void testFirstLastOnRow() {
    final KVComparator c = KeyValue.COMPARATOR;
    long ts = 1;
    byte[] bufferA = new byte[128];
    int offsetA = 0;
    byte[] bufferB = new byte[128];
    int offsetB = 7;
View Full Code Here

  /**
   * See HBASE-7845
   */
  public void testGetShortMidpointKey() {
    final KVComparator keyComparator = KeyValue.COMPARATOR;
    //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.compareFlatKey(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compareFlatKey(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.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compareFlatKey(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.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compareFlatKey(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.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
    newKey = keyComparator.getShortMidpointKey(kv1.getKey(), kv2.getKey());
    assertTrue(keyComparator.compareFlatKey(kv1.getKey(), newKey) < 0);
    assertTrue(keyComparator.compareFlatKey(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.getTypeByte() == Type.Maximum.getCode());

    //verify metaKeyComparator's getShortMidpointKey output
    final KVComparator metaKeyComparator = KeyValue.META_COMPARATOR;
    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.compareFlatKey(kv1.getKey(), newKey) < 0);
    assertTrue(metaKeyComparator.compareFlatKey(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.compareFlatKey(kv1.getKey(), kv2.getKey()) < 0);
View Full Code Here

  public void testMoreComparisons() throws Exception {
    // Root compares
    long now = System.currentTimeMillis();
    KeyValue a = new KeyValue(Bytes.toBytes(".META.,,99999999999999"), now);
    KeyValue b = new KeyValue(Bytes.toBytes(".META.,,1"), now);
    KVComparator c = new KeyValue.RootComparator();
    assertTrue(c.compare(b, a) < 0);
    KeyValue aa = new KeyValue(Bytes.toBytes(".META.,,1"), now);
    KeyValue bb = new KeyValue(Bytes.toBytes(".META.,,1"),
        Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1235943454602L,
        (byte[])null);
    assertTrue(c.compare(aa, bb) < 0);

    // Meta compares
    KeyValue aaa = new KeyValue(
        Bytes.toBytes("TestScanMultipleVersions,row_0500,1236020145502"), now);
    KeyValue bbb = new KeyValue(
        Bytes.toBytes("TestScanMultipleVersions,,99999999999999"), now);
    c = new KeyValue.MetaComparator();
    assertTrue(c.compare(bbb, aaa) < 0);

    KeyValue aaaa = new KeyValue(Bytes.toBytes("TestScanMultipleVersions,,1236023996656"),
        Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1236024396271L,
        (byte[])null);
    assertTrue(c.compare(aaaa, bbb) < 0);

    KeyValue x = new KeyValue(Bytes.toBytes("TestScanMultipleVersions,row_0500,1236034574162"),
        Bytes.toBytes("info"), Bytes.toBytes(""), 9223372036854775807L,
        (byte[])null);
    KeyValue y = new KeyValue(Bytes.toBytes("TestScanMultipleVersions,row_0500,1236034574162"),
        Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1236034574912L,
        (byte[])null);
    assertTrue(c.compare(x, y) < 0);
    comparisons(new KeyValue.MetaComparator());
    comparisons(new KeyValue.KVComparator());
    metacomparisons(new KeyValue.RootComparator());
    metacomparisons(new KeyValue.MetaComparator());
  }
View Full Code Here

TOP

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

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.