Java Code Examples for org.apache.hadoop.hbase.util.Bytes#toStringBinary()

The following examples show how to use org.apache.hadoop.hbase.util.Bytes#toStringBinary() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntegrationTestLoadAndVerify.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean filter(Context context, Cell cell) {
  // TODO: Can I do a better compare than this copying out key?
  byte [] row = new byte [cell.getRowLength()];
  System.arraycopy(cell.getRowArray(), cell.getRowOffset(), row, 0, cell.getRowLength());
  boolean b = this.keysToFind.contains(row);
  if (b) {
    String keyStr = Bytes.toStringBinary(row);
    try {
      LOG.info("Found cell=" + cell + " , walKey=" + context.getCurrentKey());
    } catch (IOException|InterruptedException e) {
      LOG.warn(e.toString(), e);
    }
    if (rows.addAndGet(1) < MISSING_ROWS_TO_LOG) {
      context.getCounter(FOUND_GROUP_KEY, keyStr).increment(1);
    }
    context.getCounter(FOUND_GROUP_KEY, "CELL_WITH_MISSING_ROW").increment(1);
  }
  return b;
}
 
Example 2
Source File: MultiTableInputFormatTestBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void makeAssertions(ImmutableBytesWritable key, Result value) throws IOException {
  if (value.size() != 1) {
    throw new IOException("There should only be one input column");
  }
  Map<byte[], NavigableMap<byte[], NavigableMap<Long, byte[]>>> cf =
      value.getMap();
  if (!cf.containsKey(INPUT_FAMILY)) {
    throw new IOException("Wrong input columns. Missing: '" +
        Bytes.toString(INPUT_FAMILY) + "'.");
  }
  String val = Bytes.toStringBinary(value.getValue(INPUT_FAMILY, null));
  LOG.debug("map: key -> " + Bytes.toStringBinary(key.get()) +
      ", value -> " + val);
}
 
Example 3
Source File: LiteralExpression.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
    if (value == null && byteValue!=null) {
        return Bytes.toStringBinary(byteValue);
    }
    else if (value == null) {
        return "null";
    }
    // TODO: move into PDataType?
    if (type.isCoercibleTo(PTimestamp.INSTANCE)) {
        return type + " " + type.toStringLiteral(value, null);
    }
    return type.toStringLiteral(value, null);
}
 
Example 4
Source File: RowMutations.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Currently only supports {@link Put} and {@link Delete} mutations.
 *
 * @param mutations The data to send.
 * @throws IOException if the row of added mutation doesn't match the original row
 */
public RowMutations add(List<? extends Mutation> mutations) throws IOException {
  for (Mutation mutation : mutations) {
    if (!Bytes.equals(row, mutation.getRow())) {
      throw new WrongRowIOException("The row in the recently added Put/Delete <" +
        Bytes.toStringBinary(mutation.getRow()) + "> doesn't match the original one <" +
        Bytes.toStringBinary(this.row) + ">");
    }
  }
  this.mutations.addAll(mutations);
  return this;
}
 
Example 5
Source File: ServerUtil.java    From phoenix with Apache License 2.0 5 votes vote down vote up
public static RowLock acquireLock(Region region, byte[] key, List<RowLock> locks)
        throws IOException {
    RowLock rowLock = region.getRowLock(key, false);
    if (rowLock == null) {
        throw new IOException("Failed to acquire lock on " + Bytes.toStringBinary(key));
    }
    if (locks != null) {
        locks.add(rowLock);
    }
    return rowLock;
}
 
Example 6
Source File: ExtractTestUtil.java    From hbase-indexer with Apache License 2.0 5 votes vote down vote up
public static void assertByteArraysEquals(Collection<byte[]> expected, Collection<byte[]> actual) {
    Function<byte[], String> byteToStringFn = new Function<byte[], String>() {

        @Override
        public String apply(@Nullable byte[] input) {
            return Bytes.toStringBinary(input);
        }
    };
    assertEquals(Lists.newArrayList(Collections2.transform(expected, byteToStringFn)),
            Lists.newArrayList(Collections2.transform(actual, byteToStringFn)));

}
 
Example 7
Source File: ExportKeys.java    From hbase-tools with Apache License 2.0 5 votes vote down vote up
private boolean export(PrintWriter writer, HRegionInfo regionInfo) throws DecoderException {
    String tableName = CommandAdapter.getTableName(regionInfo);
    String startKeyHexStr = Bytes.toStringBinary(regionInfo.getStartKey());
    String endKeyHexStr = Bytes.toStringBinary(regionInfo.getEndKey());

    if (startKeyHexStr.length() > 0 || endKeyHexStr.length() > 0) {
        writer.println(tableName + DELIMITER + " " + startKeyHexStr + DELIMITER + " " + endKeyHexStr);
        return true;
    } else {
        return false;
    }
}
 
Example 8
Source File: MultiHfileOutputFormat.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static void writePartitions(Configuration conf, Path partitionsPath,
        Set<TableRowkeyPair> tablesStartKeys) throws IOException {
    
    LOGGER.info("Writing partition information to " + partitionsPath);
    if (tablesStartKeys.isEmpty()) {
      throw new IllegalArgumentException("No regions passed");
    }

    // We're generating a list of split points, and we don't ever
    // have keys < the first region (which has an empty start key)
    // so we need to remove it. Otherwise we would end up with an
    // empty reducer with index 0
    TreeSet<TableRowkeyPair> sorted = new TreeSet<TableRowkeyPair>(tablesStartKeys);

    TableRowkeyPair first = sorted.first();
    if (!first.getRowkey().equals(HConstants.EMPTY_BYTE_ARRAY)) {
      throw new IllegalArgumentException(
          "First region of table should have empty start key. Instead has: "
          + Bytes.toStringBinary(first.getRowkey().get()));
    }
    sorted.remove(first);

    // Write the actual file
    FileSystem fs = partitionsPath.getFileSystem(conf);
    SequenceFile.Writer writer = SequenceFile.createWriter(
      fs, conf, partitionsPath, TableRowkeyPair.class,
      NullWritable.class);

    try {
      for (TableRowkeyPair startKey : sorted) {
        writer.append(startKey, NullWritable.get());
      }
    } finally {
      writer.close();
    }
    
}
 
Example 9
Source File: RegionInfoBuilder.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given inclusive range of rows is fully contained
 * by this region. For example, if the region is foo,a,g and this is
 * passed ["b","c"] or ["a","c"] it will return true, but if this is passed
 * ["b","z"] it will return false.
 * @throws IllegalArgumentException if the range passed is invalid (ie. end &lt; start)
 */
@Override
public boolean containsRange(byte[] rangeStartKey, byte[] rangeEndKey) {
  if (Bytes.compareTo(rangeStartKey, rangeEndKey) > 0) {
    throw new IllegalArgumentException(
    "Invalid range: " + Bytes.toStringBinary(rangeStartKey) +
    " > " + Bytes.toStringBinary(rangeEndKey));
  }

  boolean firstKeyInRange = Bytes.compareTo(rangeStartKey, startKey) >= 0;
  boolean lastKeyInRange =
    Bytes.compareTo(rangeEndKey, endKey) < 0 ||
    Bytes.equals(endKey, HConstants.EMPTY_BYTE_ARRAY);
  return firstKeyInRange && lastKeyInRange;
}
 
Example 10
Source File: HbaseTableMethodInterceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
/**
 * Parse attributes string.
 *
 * @param args the args
 * @return the string
 */
protected String parseAttributes(Object[] args) {

    Object param = null;

    if (args != null && args.length == 1) { // only one
        param = args[0];
    } else if (args != null && args.length > 1) { // last param
        param = args[args.length - 1];
    } else {
        return null;
    }

    // Put/Delete/Append/Increment
    if (param instanceof Mutation) {
        Mutation mutation = (Mutation) param;
        return "rowKey: " + Bytes.toStringBinary(mutation.getRow());
    }
    if (param instanceof Get) {
        Get get = (Get) param;
        return "rowKey: " + Bytes.toStringBinary(get.getRow());
    }
    if (param instanceof Scan) {
        Scan scan = (Scan) param;
        String startRowKey = Bytes.toStringBinary(scan.getStartRow());
        String stopRowKey = Bytes.toStringBinary(scan.getStopRow());
        return "startRowKey: " + startRowKey + " stopRowKey: " + stopRowKey;
    }
    // if param instanceof List.
    if (param instanceof List) {
        List list = (List) param;
        return "size: " + list.size();
    }
    return null;
}
 
Example 11
Source File: SkipScanFilterTest.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override public String toString() {
    return "rowkey=" + Bytes.toStringBinary(rowkey)+", expected include";
}
 
Example 12
Source File: RegionMetrics.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 * @return the region name as a string
 */
default String getNameAsString() {
  return Bytes.toStringBinary(getRegionName());
}
 
Example 13
Source File: RowIndexSeekerV1.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public int seekToKeyInBlock(Cell seekCell, boolean seekBefore) {
  previous.invalidate();
  int index = binarySearch(seekCell, seekBefore);
  if (index < 0) {
    return HConstants.INDEX_KEY_MAGIC; // using optimized index key
  } else {
    int offset = rowOffsets.getIntAfterPosition(index * Bytes.SIZEOF_INT);
    if (offset != 0) {
      decodeAtPosition(offset);
    }
  }
  do {
    int comp =
      PrivateCellUtil.compareKeyIgnoresMvcc(this.cellComparator, seekCell, current.currentKey);
    if (comp == 0) { // exact match
      if (seekBefore) {
        if (!previous.isValid()) {
          // The caller (seekBefore) has to ensure that we are not at the
          // first key in the block.
          throw new IllegalStateException("Cannot seekBefore if "
              + "positioned at the first key in the block: key="
              + Bytes.toStringBinary(seekCell.getRowArray()));
        }
        moveToPrevious();
        return 1;
      }
      return 0;
    }

    if (comp < 0) { // already too large, check previous
      if (previous.isValid()) {
        moveToPrevious();
      } else {
        return HConstants.INDEX_KEY_MAGIC; // using optimized index key
      }
      return 1;
    }

    // move to next, if more data is available
    if (currentBuffer.hasRemaining()) {
      previous.copyFromNext(current);
      decodeNext();
    } else {
      break;
    }
  } while (true);

  // we hit the end of the block, not an exact match
  return 1;
}
 
Example 14
Source File: SkipScanFilterTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override public String toString() {
    return "rowkey=" + Bytes.toStringBinary(rowkey)+", expected include";
}
 
Example 15
Source File: ColumnPrefixFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return this.getClass().getSimpleName() + " " + Bytes.toStringBinary(this.prefix);
}
 
Example 16
Source File: ArrayBackedTag.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return "[Tag type : " + this.type + ", value : "
      + Bytes.toStringBinary(bytes, getValueOffset(), getValueLength()) + "]";
}
 
Example 17
Source File: MetaDataEndpointImpl.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private PTable doGetTable(byte[] key, long clientTimeStamp, RowLock rowLock) throws IOException, SQLException {
    ImmutableBytesPtr cacheKey = new ImmutableBytesPtr(key);
    Cache<ImmutableBytesPtr, PTable> metaDataCache =
            GlobalCache.getInstance(this.env).getMetaDataCache();
    PTable table = metaDataCache.getIfPresent(cacheKey);
    // We only cache the latest, so we'll end up building the table with every call if the
    // client connection has specified an SCN.
    // TODO: If we indicate to the client that we're returning an older version, but there's a
    // newer version available, the client
    // can safely not call this, since we only allow modifications to the latest.
    if (table != null && table.getTimeStamp() < clientTimeStamp) {
        // Table on client is up-to-date with table on server, so just return
        if (isTableDeleted(table)) {
            return null;
        }
        return table;
    }
    // Ask Lars about the expense of this call - if we don't take the lock, we still won't get
    // partial results
    // get the co-processor environment
    // TODO: check that key is within region.getStartKey() and region.getEndKey()
    // and return special code to force client to lookup region from meta.
    HRegion region = env.getRegion();
    /*
     * Lock directly on key, though it may be an index table. This will just prevent a table
     * from getting rebuilt too often.
     */
    final boolean wasLocked = (rowLock != null);
    if (!wasLocked) {
        rowLock = region.getRowLock(key);
        if (rowLock == null) {
            throw new IOException("Failed to acquire lock on " + Bytes.toStringBinary(key));
        }
    }
    try {
        // Try cache again in case we were waiting on a lock
        table = metaDataCache.getIfPresent(cacheKey);
        // We only cache the latest, so we'll end up building the table with every call if the
        // client connection has specified an SCN.
        // TODO: If we indicate to the client that we're returning an older version, but there's
        // a newer version available, the client
        // can safely not call this, since we only allow modifications to the latest.
        if (table != null && table.getTimeStamp() < clientTimeStamp) {
            // Table on client is up-to-date with table on server, so just return
            if (isTableDeleted(table)) {
                return null;
            }
            return table;
        }
        // Query for the latest table first, since it's not cached
        table = buildTable(key, cacheKey, region, HConstants.LATEST_TIMESTAMP);
        if (table != null && table.getTimeStamp() < clientTimeStamp) {
            return table;
        }
        // Otherwise, query for an older version of the table - it won't be cached
        return buildTable(key, cacheKey, region, clientTimeStamp);
    } finally {
        if (!wasLocked) rowLock.release();
    }
}
 
Example 18
Source File: MaxAggregator.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return "MAX [value=" + Bytes.toStringBinary(value.get(),value.getOffset(),value.getLength()) + "]";
}
 
Example 19
Source File: GuidePostsKey.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return "GuidePostsKey[physicalName=" + Bytes.toStringBinary(physicalName) 
            + ",columnFamily=" + Bytes.toStringBinary(columnFamily) + "]";
}
 
Example 20
Source File: MockHTable.java    From foxtrot with Apache License 2.0 4 votes vote down vote up
public static String toEString(float val) {
    return Bytes.toStringBinary(Bytes.toBytes(val));
}