Examples of HScannerInterface


Examples of org.apache.hadoop.hbase.HScannerInterface

  }
 
  private int scanPrint(HTable table,
      HBaseAdmin admin) {
    int count = 0;
    HScannerInterface scan = null;
    try {
      ParsedColumns parsedColumns = getColumns(admin, true);
      Text [] cols = parsedColumns.getColumns().toArray(new Text [] {});
      if (this.timestamp == 0) {
        scan = table.obtainScanner(cols, this.rowKey);
      } else {
        scan = table.obtainScanner(cols, this.rowKey, this.timestamp);
      }
      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
      // If only one column in query, then don't print out the column.
      formatter.header((parsedColumns.isMultiple())? HEADER: HEADER_ROW_CELL);
      while (scan.next(key, results) && checkLimit(count)) {
        Text r = key.getRow();
        for (Text columnKey : results.keySet()) {
          String cellData = toString(columnKey, results.get(columnKey));
          if (parsedColumns.isMultiple()) {
            formatter.row(new String [] {r.toString(), columnKey.toString(),
              cellData});
          } else {
            // Don't print out the column since only one specified in query.
            formatter.row(new String [] {r.toString(), cellData});
          }
          count++;
          if (this.limit > 0 && count >= this.limit) {
            break;
          }
        }
      }
      formatter.footer();
      scan.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return count;
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

   
    Text[] columns = {
        TEXT_INPUT_COLUMN,
        TEXT_OUTPUT_COLUMN
    };
    HScannerInterface scanner =
      table.obtainScanner(columns, HConstants.EMPTY_START_ROW);
   
    try {
      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
     
      while(scanner.next(key, results)) {
        LOG.info("row: " + key.getRow());
       
        for(Map.Entry<Text, byte[]> e: results.entrySet()) {
          LOG.info(" column: " + e.getKey() + " value: "
              + new String(e.getValue(), HConstants.UTF8_ENCODING));
        }
      }
     
    } finally {
      scanner.close();
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

      HRegion rootRegion = new HRegion(
          new Path(rootdir, HConstants.ROOT_TABLE_NAME.toString()), log, fs, conf,
          HRegionInfo.rootRegionInfo, null, null);

      try {
        HScannerInterface rootScanner = rootRegion.getScanner(
            HConstants.COL_REGIONINFO_ARRAY, HConstants.EMPTY_START_ROW,
            HConstants.LATEST_TIMESTAMP, null);

        try {
          HStoreKey key = new HStoreKey();
          SortedMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
          while (rootScanner.next(key, results)) {
            HRegionInfo info = Writables.getHRegionInfoOrNull(
                results.get(HConstants.COL_REGIONINFO));
            if (info == null) {
              LOG.warn("region info is null for row " + key.getRow() +
                  " in table " + HConstants.ROOT_TABLE_NAME);
              continue;
            }

            // First move the meta region to where it should be and rename
            // subdirectories as necessary

            migrateRegionDir(fs, rootdir, HConstants.META_TABLE_NAME,
                new Path(rootdir, OLD_PREFIX + info.getEncodedName()));

            // Now scan and process the meta table

            scanMetaRegion(fs, rootdir, log, info);
          }

        } finally {
          rootScanner.close();
        }

      } finally {
        rootRegion.close();
      }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

    HRegion metaRegion = new HRegion(
        new Path(rootdir, info.getTableDesc().getName().toString()), log, fs,
        conf, info, null, null);

    try {
      HScannerInterface metaScanner = metaRegion.getScanner(
          HConstants.COL_REGIONINFO_ARRAY, HConstants.EMPTY_START_ROW,
          HConstants.LATEST_TIMESTAMP, null);

      try {
        HStoreKey key = new HStoreKey();
        SortedMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
        while (metaScanner.next(key, results)) {
          HRegionInfo region = Writables.getHRegionInfoOrNull(
              results.get(HConstants.COL_REGIONINFO));
          if (region == null) {
            LOG.warn("region info is null for row " + key.getRow() +
                " in table " + HConstants.META_TABLE_NAME);
            continue;
          }

          // Move the region to where it should be and rename
          // subdirectories as necessary

          migrateRegionDir(fs, rootdir, region.getTableDesc().getName(),
              new Path(rootdir, OLD_PREFIX + region.getEncodedName()));

          results.clear();
        }

      } finally {
        metaScanner.close();
      }

    } finally {
      metaRegion.close();
    }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

              columns = tables[i].families().keySet().toArray(new Text[] {});
            }
          }
        }

        HScannerInterface scan = client.obtainScanner(columns, new Text(""));
        HStoreKey key = new HStoreKey();
        TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();

        ConsoleTable.selectHead();
        int count = 0;
        while (scan.next(key, results)) {
          Text rowKey = key.getRow();

          for (Text columnKey : results.keySet()) {
            byte[] value = results.get(columnKey);
            String cellData = new String(value);

            if (columnKey.equals(HConstants.COL_REGIONINFO)) {
              DataInputBuffer inbuf = new DataInputBuffer();
              HRegionInfo info = new HRegionInfo();
              inbuf.reset(value, value.length);
              info.readFields(inbuf);

              cellData = "ID : " + String.valueOf(info.getRegionId());
            }
            ConsoleTable.printLine(count, rowKey.toString(), columnKey.toString(),
                cellData);
            count++;
          }
          results = new TreeMap<Text, byte[]>();
        }
        ConsoleTable.selectFoot();
        scan.close();

        break;

      case 1:

        count = 0;
        ConsoleTable.selectHead();
        for (Map.Entry<Text, byte[]> entry : client.getRow(new Text(getRow())).entrySet()) {

          byte[] value = entry.getValue();
          String cellData = new String(value);

          if (entry.getKey().equals(HConstants.COL_REGIONINFO)) {
            DataInputBuffer inbuf = new DataInputBuffer();
            HRegionInfo info = new HRegionInfo();
            inbuf.reset(value, value.length);
            info.readFields(inbuf);

            cellData = "ID : " + String.valueOf(info.getRegionId());
          }
          ConsoleTable.printLine(count, getRow().toString(), entry.getKey().toString(),
              cellData);
          count++;
        }
        ConsoleTable.selectFoot();

        break;

      case 2:

        Text[] column = new Text[] { new Text(getColumn()) };

        HScannerInterface scanner = client.obtainScanner(column, new Text(""));
        HStoreKey k = new HStoreKey();
        TreeMap<Text, byte[]> r = new TreeMap<Text, byte[]>();

        ConsoleTable.selectHead();
        count = 0;
        while (scanner.next(k, r)) {
          Text rowKey = k.getRow();

          for (Text columnKey : r.keySet()) {
            byte[] value = r.get(columnKey);
            String cellData = new String(value);
            ConsoleTable.printLine(count, rowKey.toString(), columnKey.toString(),
                cellData);
            count++;
          }
          results = new TreeMap<Text, byte[]>();
        }
        ConsoleTable.selectFoot();
        scanner.close();

        break;

      case 3:
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

  private void scanTable(String tableName, boolean printValues)
  throws IOException {
    HTable table = new HTable(conf, new Text(tableName));
   
    HScannerInterface scanner =
      table.obtainScanner(columns, HConstants.EMPTY_START_ROW);
   
    try {
      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
     
      while(scanner.next(key, results)) {
        if (printValues) {
          LOG.info("row: " + key.getRow());

          for(Map.Entry<Text, byte[]> e: results.entrySet()) {
            LOG.info(" column: " + e.getKey() + " value: "
                + new String(e.getValue(), HConstants.UTF8_ENCODING));
          }
        }
      }
     
    } finally {
      scanner.close();
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

   * @param table Table to scan.
   * @throws IOException
   * @throws NullPointerException if we failed to find a cell value
   */
  private void verifyAttempt(final HTable table) throws IOException, NullPointerException {
    HScannerInterface scanner =
      table.obtainScanner(columns, HConstants.EMPTY_START_ROW);
    try {
      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
     
      while(scanner.next(key, results)) {
        if (LOG.isDebugEnabled()) {
          if (results.size() > 2 ) {
            throw new IOException("Too many results, expected 2 got " +
              results.size());
          }
        }
        byte[] firstValue = null;
        byte[] secondValue = null;
        int count = 0;
        for(Map.Entry<Text, byte[]> e: results.entrySet()) {
          if (count == 0) {
            firstValue = e.getValue();
          }
          if (count == 1) {
            secondValue = e.getValue();
          }
          count++;
          if (count == 2) {
            break;
          }
        }
       
        String first = "";
        if (firstValue == null) {
          throw new NullPointerException(key.getRow().toString() +
            ": first value is null");
        }
        first = new String(firstValue, HConstants.UTF8_ENCODING);
       
        String second = "";
        if (secondValue == null) {
          throw new NullPointerException(key.getRow().toString() +
            ": second value is null");
        }
        byte[] secondReversed = new byte[secondValue.length];
        for (int i = 0, j = secondValue.length - 1; j >= 0; j--, i++) {
          secondReversed[i] = secondValue[j];
        }
        second = new String(secondReversed, HConstants.UTF8_ENCODING);

        if (first.compareTo(second) != 0) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("second key is not the reverse of first. row=" +
                key.getRow() + ", first value=" + first + ", second value=" +
                second);
          }
          fail();
        }
      }
    } finally {
      scanner.close();
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

  }

  private void scanTable(final String tableName, final boolean printValues) throws IOException {
    HTable table = new HTable(conf, new Text(tableName));

    HScannerInterface scanner = table.obtainScanner(columns, HConstants.EMPTY_START_ROW);
    int numFound = doScan(scanner, printValues);
    Assert.assertEquals(NUM_ROWS, numFound);
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

  private void scanTableWithRowFilter(final String tableName, final boolean printValues) throws IOException {
    HTable table = new HTable(conf, new Text(tableName));
    Map<Text, byte[]> columnMap = new HashMap<Text, byte[]>();
    columnMap.put(TEXT_COLUMN1, VALUE);
    RegExpRowFilter filter = new RegExpRowFilter(null, columnMap);
    HScannerInterface scanner = table.obtainScanner(columns, HConstants.EMPTY_START_ROW, filter);
    int numFound = doScan(scanner, printValues);
    Assert.assertEquals(NUM_ROWS, numFound);
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.HScannerInterface

  }

  private void scanTable(boolean printResults)
  throws IOException {
    HTable table = new HTable(conf, new Text(TABLE_NAME));
    HScannerInterface scanner = table.obtainScanner(columns,
        HConstants.EMPTY_START_ROW);
    try {
      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();
      while (scanner.next(key, results)) {
        if (printResults) {
          LOG.info("row: " + key.getRow());
        }
        for (Map.Entry<Text, byte[]> e : results.entrySet()) {
          if (printResults) {
            LOG.info(" column: " + e.getKey() + " value: "
                + new String(e.getValue(), HConstants.UTF8_ENCODING));
          }
        }
      }
    } finally {
      scanner.close();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.