Package org.apache.hadoop.hbase.io

Examples of org.apache.hadoop.hbase.io.HalfMapFileReader


  @SuppressWarnings("unchecked")
  public void testNextingAtOffsetinHalfMapFile() throws Exception {
    Path p = writeMapFile(getName());
    WritableComparable midkey = getMidkey(p);
    // Now test reading from the top.
    HalfMapFileReader top = new HalfMapFileReader(this.fs, p.toString(),
      this.conf, Reference.Range.top, midkey, null);
    ImmutableBytesWritable val = new ImmutableBytesWritable();
    final String startRowPrefix = "zy";
    HStoreKey key = new HStoreKey(startRowPrefix);
    WritableComparable closest = top.getClosest(key, val);
    assertTrue(closest.toString().startsWith(startRowPrefix));
    int count = 0;
    for (boolean first = true; top.next(key, val); count++) {
      if (first) {
        assertTrue(key.toString().compareTo(startRowPrefix) > 0);
      }
      LOG.info(key.toString());
    }
View Full Code Here


    String previous = null;
    try {
      // Now make two HalfMapFiles and assert they can read the full backing
      // file, one from the top and the other from the bottom.
      // Test bottom half first.
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
      boolean first = true;
      while (bottom.next(key, value)) {
        previous = key.toString();
        if (first) {
          first = false;
          LOG.info("First in bottom: " + previous);
        }
        assertTrue(key.compareTo((HStoreKey)midkey) < 0);
      }
      if (previous != null) {
        LOG.info("Last in bottom: " + previous.toString());
      }
      // Now test reading from the top.
      top = new HalfMapFileReader(this.fs, p.toString(), this.conf,
          Reference.Range.top, midkey, null);
      first = true;
      while (top.next(key, value)) {
        assertTrue(key.compareTo((HStoreKey)midkey) >= 0);
        if (first) {
          first = false;
          LOG.info("First in top: " + key.toString());
        }
      }
      LOG.info("Last in top: " + key.toString());

      // Next test using a midkey that does not exist in the file.
      // First, do a key that is < than first key. Ensure splits behave
      // properly.
      WritableComparable badkey = new HStoreKey("   ");
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, badkey, null);
      // When badkey is < than the bottom, should return no values.
      assertFalse(bottom.next(key, value));
      // Now read from the top.
      top = new HalfMapFileReader(this.fs, p.toString(), this.conf,
          Reference.Range.top, badkey, null);
      first = true;
      while (top.next(key, value)) {
        assertTrue(key.compareTo((HStoreKey)badkey) >= 0);
        if (first) {
          first = false;
          LOG.info("First top when key < bottom: " + key.toString());
          String tmp = Bytes.toString(key.getRow());
          for (int i = 0; i < tmp.length(); i++) {
            assertTrue(tmp.charAt(i) == 'a');
          }
        }
      }
      LOG.info("Last top when key < bottom: " + key.toString());
      String tmp = Bytes.toString(key.getRow());
      for (int i = 0; i < tmp.length(); i++) {
        assertTrue(tmp.charAt(i) == 'z');
      }

      // Test when badkey is > than last key in file ('||' > 'zz').
      badkey = new HStoreKey("|||");
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, badkey, null);
      first = true;
      while (bottom.next(key, value)) {
        if (first) {
          first = false;
          LOG.info("First bottom when key > top: " + key.toString());
          tmp = Bytes.toString(key.getRow());
          for (int i = 0; i < tmp.length(); i++) {
            assertTrue(tmp.charAt(i) == 'a');
          }
        }
      }
      LOG.info("Last bottom when key > top: " + key.toString());
      tmp = Bytes.toString(key.getRow());
      for (int i = 0; i < tmp.length(); i++) {
        assertTrue(tmp.charAt(i) == 'z');
      }
      // Now look at top. Should not return any values.
      top = new HalfMapFileReader(this.fs, p.toString(), this.conf,
          Reference.Range.top, badkey, null);
      assertFalse(top.next(key, value));
     
    } finally {
      if (top != null) {
View Full Code Here

      try {
        // Test using a midkey that does not exist in the file.
        // First, do a key that is < than first key.  Ensure splits behave
        // properly.
        HStoreKey midkey = new HStoreKey("   ");
        bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
        // When midkey is < than the bottom, should return no values.
        assertFalse(bottom.next(key, value));
        // Now read from the top.
        top = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.top, midkey, null);
        boolean first = true;
        while (top.next(key, value)) {
          assertTrue(key.compareTo(midkey) >= 0);
          if (first) {
            first = false;
            LOG.info("First top when key < bottom: " + key.toString());
            assertEquals("aa", Bytes.toString(key.getRow()));
          }
        }
        LOG.info("Last top when key < bottom: " + key.toString());
        assertEquals("zz", Bytes.toString(key.getRow()));
       
        // Test when midkey is > than last key in file ('||' > 'zz').
        midkey = new HStoreKey("|||");
        bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
        first = true;
        while (bottom.next(key, value)) {
          if (first) {
            first = false;
            LOG.info("First bottom when key > top: " + key.toString());
            assertEquals("aa", Bytes.toString(key.getRow()));
          }
        }
        LOG.info("Last bottom when key > top: " + key.toString());
        assertEquals("zz", Bytes.toString(key.getRow()));
        // Now look at top.  Should not return any values.
        top = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.top, midkey, null);
        assertFalse(top.next(key, value));
      } finally {
        if (top != null) {
          top.close();
View Full Code Here

   */
  public synchronized BloomFilterMapFile.Reader getReader(final FileSystem fs,
      final boolean bloomFilter, final boolean blockCacheEnabled)
  throws IOException {
    if (isReference()) {
      return new HalfMapFileReader(fs,
          getMapFilePath(reference).toString(), conf,
          reference.getFileRegion(), reference.getMidkey(), bloomFilter,
          blockCacheEnabled, this.hri);
    }
    return new BloomFilterMapFile.Reader(fs, getMapFilePath().toString(),
View Full Code Here

    String previous = null;
    try {
      // Now make two HalfMapFiles and assert they can read the full backing
      // file, one from the top and the other from the bottom.
      // Test bottom half first.
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
      boolean first = true;
      while (bottom.next(key, value)) {
        previous = key.toString();
        if (first) {
          first = false;
          LOG.info("First in bottom: " + previous);
        }
        assertTrue(key.compareTo((HStoreKey)midkey) < 0);
      }
      if (previous != null) {
        LOG.info("Last in bottom: " + previous.toString());
      }
      // Now test reading from the top.
      top = new HalfMapFileReader(this.fs, p.toString(), this.conf,
          Reference.Range.top, midkey, null);
      first = true;
      while (top.next(key, value)) {
        assertTrue(key.compareTo((HStoreKey)midkey) >= 0);
        if (first) {
          first = false;
          LOG.info("First in top: " + key.toString());
        }
      }
      LOG.info("Last in top: " + key.toString());

      // Next test using a midkey that does not exist in the file.
      // First, do a key that is < than first key. Ensure splits behave
      // properly.
      WritableComparable badkey = new HStoreKey("   ");
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, badkey, null);
      // When badkey is < than the bottom, should return no values.
      assertFalse(bottom.next(key, value));
      // Now read from the top.
      top = new HalfMapFileReader(this.fs, p.toString(), this.conf,
          Reference.Range.top, badkey, null);
      first = true;
      while (top.next(key, value)) {
        assertTrue(key.compareTo((HStoreKey)badkey) >= 0);
        if (first) {
          first = false;
          LOG.info("First top when key < bottom: " + key.toString());
          String tmp = Bytes.toString(key.getRow());
          for (int i = 0; i < tmp.length(); i++) {
            assertTrue(tmp.charAt(i) == 'a');
          }
        }
      }
      LOG.info("Last top when key < bottom: " + key.toString());
      String tmp = Bytes.toString(key.getRow());
      for (int i = 0; i < tmp.length(); i++) {
        assertTrue(tmp.charAt(i) == 'z');
      }

      // Test when badkey is > than last key in file ('||' > 'zz').
      badkey = new HStoreKey("|||");
      bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, badkey, null);
      first = true;
      while (bottom.next(key, value)) {
        if (first) {
          first = false;
          LOG.info("First bottom when key > top: " + key.toString());
          tmp = Bytes.toString(key.getRow());
          for (int i = 0; i < tmp.length(); i++) {
            assertTrue(tmp.charAt(i) == 'a');
          }
        }
      }
      LOG.info("Last bottom when key > top: " + key.toString());
      tmp = Bytes.toString(key.getRow());
      for (int i = 0; i < tmp.length(); i++) {
        assertTrue(tmp.charAt(i) == 'z');
      }
      // Now look at top. Should not return any values.
      top = new HalfMapFileReader(this.fs, p.toString(), this.conf,
          Reference.Range.top, badkey, null);
      assertFalse(top.next(key, value));
     
    } finally {
      if (top != null) {
View Full Code Here

      try {
        // Test using a midkey that does not exist in the file.
        // First, do a key that is < than first key.  Ensure splits behave
        // properly.
        HStoreKey midkey = new HStoreKey("   ");
        bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
        // When midkey is < than the bottom, should return no values.
        assertFalse(bottom.next(key, value));
        // Now read from the top.
        top = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.top, midkey, null);
        boolean first = true;
        while (top.next(key, value)) {
          assertTrue(key.compareTo(midkey) >= 0);
          if (first) {
            first = false;
            LOG.info("First top when key < bottom: " + key.toString());
            assertEquals("aa", Bytes.toString(key.getRow()));
          }
        }
        LOG.info("Last top when key < bottom: " + key.toString());
        assertEquals("zz", Bytes.toString(key.getRow()));
       
        // Test when midkey is > than last key in file ('||' > 'zz').
        midkey = new HStoreKey("|||");
        bottom = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.bottom, midkey, null);
        first = true;
        while (bottom.next(key, value)) {
          if (first) {
            first = false;
            LOG.info("First bottom when key > top: " + key.toString());
            assertEquals("aa", Bytes.toString(key.getRow()));
          }
        }
        LOG.info("Last bottom when key > top: " + key.toString());
        assertEquals("zz", Bytes.toString(key.getRow()));
        // Now look at top.  Should not return any values.
        top = new HalfMapFileReader(this.fs, p.toString(),
          this.conf, Reference.Range.top, midkey, null);
        assertFalse(top.next(key, value));
      } finally {
        if (top != null) {
          top.close();
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.io.HalfMapFileReader

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.