Java Code Examples for org.apache.accumulo.core.data.Value#getSize()

The following examples show how to use org.apache.accumulo.core.data.Value#getSize() . 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: PrintUtility.java    From datawave with Apache License 2.0 6 votes vote down vote up
public static String getPrintableValue(final Value value) {
    if ((value != null) && (value.getSize() > 0)) {
        try {
            final Uid.List uidList = Uid.List.parseFrom(value.get());
            
            return (uidList.getUIDList().toString());
        } catch (final InvalidProtocolBufferException e1) {
            try {
                return (ReflectionToStringBuilder.toString(EdgeValue.decode(value), ToStringStyle.SHORT_PREFIX_STYLE));
            } catch (final Exception e2) {
                try {
                    final ExtendedHyperLogLogPlus ehllp = new ExtendedHyperLogLogPlus(value);
                    
                    return (String.valueOf(ehllp.getCardinality()));
                } catch (final Exception e3) {
                    logger.error("Could not deserialize protobuff" + e2);
                }
            }
        }
    }
    
    return ("");
}
 
Example 2
Source File: ChunkCombiner.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
private String diffInfo(Value v1, Value v2) {
  if (v1.getSize() != v2.getSize()) {
    return "val len not equal " + v1.getSize() + "!=" + v2.getSize();
  }

  byte[] vb1 = v1.get();
  byte[] vb2 = v2.get();

  for (int i = 0; i < vb1.length; i++) {
    if (vb1[i] != vb2[i]) {
      return String.format("first diff at offset %,d 0x%02x != 0x%02x", i, 0xff & vb1[i],
          0xff & vb2[i]);
    }
  }

  return null;
}
 
Example 3
Source File: ShardUidMappingIterator.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Add an entry in the cache, appending values if needed
 * 
 * @param key
 * @param value
 */
protected void cacheAdd(Key key, Value value) {
    if (cache.containsKey(key)) {
        ByteArrayOutputStream orgValue = cache.get(key);
        orgValue.write(0);
        orgValue.write(value.get(), 0, value.getSize());
    } else {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        if (value != null && value.getSize() > 0) {
            bytes.write(value.get(), 0, value.getSize());
        }
        cache.put(new Key(key), bytes);
    }
}
 
Example 4
Source File: FormatUtil.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Format and return the specified table entry as a human-readable String suitable for logging.
 * <br/>
 * If {@code includeTimestamp} is true, the entry will be formatted as: <br/>
 * {@literal <row> <columnFamily>:<columnQualifier> <columnVisibility> <timestamp>\t<value>} <br/>
 * If false, the entry will be formatted as: <br/>
 * {@literal <row> <columnFamily>:<columnQualifier> <columnVisibility>\t<value>} <br/>
 * Examples: <br/>
 * {@literal a ~chunk:\x00\x00\x00d\x00\x00\x00\x00 [A&B] 9223372036854775807 asdfjkl;}
 * {@literal a ~chunk:\x00\x00\x00d\x00\x00\x00\x00 [A&B] asdfjkl;}
 * 
 * @param entry
 *          the table entry to format
 * @param includeTimestamp
 *          if true, include the timestamp in the returned result
 * @return the specified entry as a formatted String, or null if the entry is null
 */
public static String formatTableEntry(final Map.Entry<Key,Value> entry,
    final boolean includeTimestamp) {
  if (entry == null) {
    return null;
  }

  Key key = entry.getKey();
  StringBuilder sb = new StringBuilder();
  Text buffer = new Text();

  // Append row.
  appendBytes(sb, key.getRow(buffer).getBytes()).append(" ");

  // Append column family.
  appendBytes(sb, key.getColumnFamily().getBytes()).append(":");

  // Append column qualifier.
  appendBytes(sb, key.getColumnQualifier().getBytes()).append(" ");

  // Append visibility and timestamp.
  sb.append(new ColumnVisibility(key.getColumnVisibility(buffer)));

  if (includeTimestamp) {
    sb.append(" ").append(entry.getKey().getTimestamp());
  }

  // Append value.
  Value value = entry.getValue();
  if (value != null && value.getSize() > 0) {
    sb.append("\t");
    appendBytes(sb, value.get());
  }
  return sb.toString();
}
 
Example 5
Source File: MultiRFileOutputFormatter.java    From datawave with Apache License 2.0 4 votes vote down vote up
public void append(Key key, Value value) throws IOException {
    entries++;
    size += key.getLength() + (value == null ? 0 : value.getSize());
    delegate.append(key, value);
}
 
Example 6
Source File: PersistentDataFormatter.java    From geowave with Apache License 2.0 4 votes vote down vote up
public String formatEntry(final Entry<Key, Value> entry, final DateFormat timestampFormat) {
  final StringBuilder sb = new StringBuilder();
  final StringBuilder sbInsertion = new StringBuilder();

  final Key key = entry.getKey();

  final GeoWaveKey rowId = new GeoWaveKeyImpl(key.getRow().copyBytes(), 0);

  byte[] insertionIdBytes;
  insertionIdBytes = rowId.getSortKey();

  for (final byte b : insertionIdBytes) {
    sbInsertion.append(String.format("%02x", b));
  }

  final Text insertionIdText = new Text(sbInsertion.toString());
  final Text adapterIdText = new Text((Short.toString(rowId.getAdapterId())));
  final Text dataIdText = new Text(StringUtils.stringFromBinary(rowId.getDataId()));
  final Text duplicatesText = new Text(Integer.toString(rowId.getNumberOfDuplicates()));

  // append insertion Id
  appendText(sb, insertionIdText).append(" ");

  // append adapterId
  appendText(sb, adapterIdText).append(" ");

  // append dataId
  appendText(sb, dataIdText).append(" ");

  // append numberOfDuplicates
  appendText(sb, duplicatesText).append(" ");

  // append column family
  appendText(sb, key.getColumnFamily()).append(":");

  // append column qualifier
  appendText(sb, key.getColumnQualifier()).append(" ");

  // append visibility expression
  sb.append(new ColumnVisibility(key.getColumnVisibility()));

  // append timestamp
  if (timestampFormat != null) {
    tmpDate.get().setTime(entry.getKey().getTimestamp());
    sb.append(" ").append(timestampFormat.format(tmpDate.get()));
  }

  final Value value = entry.getValue();

  // append value
  if ((value != null) && (value.getSize() > 0)) {
    sb.append("\t");
    appendValue(sb, value);
  }

  return sb.toString();
}