Java Code Examples for org.apache.hadoop.io.WritableUtils#writeVInt()

The following examples show how to use org.apache.hadoop.io.WritableUtils#writeVInt() . 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: TestRcFileDecoderUtils.java    From presto with Apache License 2.0 6 votes vote down vote up
private static Slice writeVintOld(SliceOutput output, long value)
        throws IOException
{
    output.reset();
    WritableUtils.writeVLong(output, value);
    Slice vLongOld = Slices.copyOf(output.slice());

    output.reset();
    RcFileDecoderUtils.writeVLong(output, value);
    Slice vLongNew = Slices.copyOf(output.slice());
    assertEquals(vLongNew, vLongOld);

    if (value == (int) value) {
        output.reset();
        WritableUtils.writeVInt(output, (int) value);
        Slice vIntOld = Slices.copyOf(output.slice());
        assertEquals(vIntOld, vLongOld);

        output.reset();
        RcFileDecoderUtils.writeVInt(output, (int) value);
        Slice vIntNew = Slices.copyOf(output.slice());
        assertEquals(vIntNew, vLongOld);
    }
    return vLongOld;
}
 
Example 2
Source File: IFile.java    From RDFS with Apache License 2.0 6 votes vote down vote up
public void append(byte[] kvBuffer, int offset, int keyLength,
    int valueLength)
    throws IOException {
  int realKeyLen = keyLength + WritableUtils.INT_LENGTH_BYTES;
  int realValLen = valueLength + WritableUtils.INT_LENGTH_BYTES;

  WritableUtils.writeVInt(buffer, realKeyLen);
  WritableUtils.writeVInt(buffer, realValLen);
  //this is real key: keyLength + key
  buffer.writeInt(keyLength);
  buffer.write(kvBuffer, offset, keyLength);
  //this is real value: 
  buffer.writeInt(valueLength);
  buffer.write(kvBuffer, offset + keyLength, valueLength);

  out.write(buffer.getData(), 0, buffer.getLength());
  buffer.reset();

  // Update bytes written
  decompressedBytesWritten += realKeyLen + realValLen
      + WritableUtils.getVIntSize(realKeyLen)
      + WritableUtils.getVIntSize(realValLen);
  ++numRecordsWritten;
}
 
Example 3
Source File: FSImageSerialization.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Write an array of blocks as compactly as possible. This uses
 * delta-encoding for the generation stamp and size, following
 * the principle that genstamp increases relatively slowly,
 * and size is equal for all but the last block of a file.
 */
public static void writeCompactBlockArray(
    Block[] blocks, DataOutputStream out) throws IOException {
  WritableUtils.writeVInt(out, blocks.length);
  Block prev = null;
  for (Block b : blocks) {
    long szDelta = b.getNumBytes() -
        (prev != null ? prev.getNumBytes() : 0);
    long gsDelta = b.getGenerationStamp() -
        (prev != null ? prev.getGenerationStamp() : 0);
    out.writeLong(b.getBlockId()); // blockid is random
    WritableUtils.writeVLong(out, szDelta);
    WritableUtils.writeVLong(out, gsDelta);
    prev = b;
  }
}
 
Example 4
Source File: AbstractCounterGroup.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * GenericGroup ::= displayName #counter counter*
 */
@Override
public synchronized void write(DataOutput out) throws IOException {
  Text.writeString(out, displayName);
  WritableUtils.writeVInt(out, counters.size());
  for(Counter counter: counters.values()) {
    counter.write(out);
  }
}
 
Example 5
Source File: ValueSchema.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    WritableUtils.writeVInt(output, (type.ordinal() + 1) * (this.isNullable ? -1 : 1));
    WritableUtils.writeVInt(output, count * (columnModifier == null ? 1 : -1));
    if (type.isFixedWidth() && type.getByteSize() == null) {
        WritableUtils.writeVInt(output, byteSize);
    }
}
 
Example 6
Source File: DelegationKey.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 */
@Override
public void write(DataOutput out) throws IOException {
  WritableUtils.writeVInt(out, keyId);
  WritableUtils.writeVLong(out, expiryDate);
  if (keyBytes == null) {
    WritableUtils.writeVInt(out, -1);
  } else {
    WritableUtils.writeVInt(out, keyBytes.length);
    out.write(keyBytes);
  }
}
 
Example 7
Source File: AbstractCounterGroup.java    From incubator-tez with Apache License 2.0 5 votes vote down vote up
/**
 * GenericGroup ::= displayName #counter counter*
 */
@Override
public synchronized void write(DataOutput out) throws IOException {
  Text.writeString(out, displayName);
  WritableUtils.writeVInt(out, counters.size());
  for(TezCounter counter: counters.values()) {
    counter.write(out);
  }
}
 
Example 8
Source File: SequenceFile.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/** Append a key/value pair. */
@Override
@SuppressWarnings("unchecked")
public synchronized void append(Object key, Object val)
  throws IOException {
  if (key.getClass() != keyClass)
    throw new IOException("wrong key class: "+key+" is not "+keyClass);
  if (val.getClass() != valClass)
    throw new IOException("wrong value class: "+val+" is not "+valClass);

  // Save key/value into respective buffers 
  int oldKeyLength = keyBuffer.getLength();
  keySerializer.serialize(key);
  int keyLength = keyBuffer.getLength() - oldKeyLength;
  if (keyLength < 0)
    throw new IOException("negative length keys not allowed: " + key);
  WritableUtils.writeVInt(keyLenBuffer, keyLength);

  int oldValLength = valBuffer.getLength();
  uncompressedValSerializer.serialize(val);
  int valLength = valBuffer.getLength() - oldValLength;
  WritableUtils.writeVInt(valLenBuffer, valLength);
  
  // Added another key/value pair
  ++noBufferedRecords;
  
  // Compress and flush?
  int currentBlockSize = keyBuffer.getLength() + valBuffer.getLength();
  if (currentBlockSize >= compressionBlockSize) {
    sync();
  }
}
 
Example 9
Source File: IFile.java    From tez with Apache License 2.0 5 votes vote down vote up
protected void writeValue(byte[] data, int offset, int length) throws IOException {
  writeRLE(out);
  WritableUtils.writeVInt(out, length); // value length
  out.write(data, offset, length);
  // Update bytes written
  decompressedBytesWritten +=
      length + WritableUtils.getVIntSize(length);
  if (serializedUncompressedBytes != null) {
    serializedUncompressedBytes.increment(length);
  }
  totalKeySaving++;
}
 
Example 10
Source File: Attributes.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutput out, boolean reducedResponse) throws IOException {
    WritableUtils.writeVInt(out, _count);
    out.writeBoolean(trackSizes);
    // Write out the number of Attributes we're going to store
    WritableUtils.writeVInt(out, this.attributes.size());
    
    for (Attribute<? extends Comparable<?>> attr : this.attributes) {
        // Write out the concrete Attribute class
        WritableUtils.writeString(out, attr.getClass().getName());
        
        // Defer to the concrete instance to write() itself
        attr.write(out, reducedResponse);
    }
}
 
Example 11
Source File: InMemoryWriter.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public void close() throws IOException {
  // Write EOF_MARKER for key/value length
  WritableUtils.writeVInt(out, IFile.EOF_MARKER);
  WritableUtils.writeVInt(out, IFile.EOF_MARKER);
  
  // Close the stream 
  out.close();
  out = null;
}
 
Example 12
Source File: OrderByExpression.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    output.writeBoolean(isNullsLast);
    output.writeBoolean(isAscending);
    WritableUtils.writeVInt(output, ExpressionType.valueOf(expression).ordinal());
    expression.write(output);
}
 
Example 13
Source File: Configuration.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
  Properties props = getProps();
  WritableUtils.writeVInt(out, props.size());
  for(Entry<Object, Object> item: props.entrySet()) {
    org.apache.hadoop.io.Text.writeString(out, (String) item.getKey());
    org.apache.hadoop.io.Text.writeString(out, (String) item.getValue());
    WritableUtils.writeCompressedStringArray(out,
        updatingResource.get(item.getKey()));
  }
}
 
Example 14
Source File: BaseSingleExpression.java    From phoenix with Apache License 2.0 4 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    WritableUtils.writeVInt(output, ExpressionType.valueOf(children.get(0)).ordinal());
    children.get(0).write(output);
}
 
Example 15
Source File: PipeReducerStub.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public void binaryProtocolStub() {
  try {

    initSoket();

    //should be 5
    //RUN_REDUCE boolean 
    WritableUtils.readVInt(dataInput);
    WritableUtils.readVInt(dataInput);
    int intValue = WritableUtils.readVInt(dataInput);
    System.out.println("getIsJavaRecordWriter:" + intValue);

    // reduce key
    WritableUtils.readVInt(dataInput);
    // value of reduce key
    BooleanWritable value = new BooleanWritable();
    readObject(value, dataInput);
    System.out.println("reducer key :" + value);
    // reduce value code:

    // reduce values
    while ((intValue = WritableUtils.readVInt(dataInput)) == 7) {
      Text txt = new Text();
      // value
      readObject(txt, dataInput);
      System.out.println("reduce value  :" + txt);
    }


    // done
    WritableUtils.writeVInt(dataOut, 54);

    dataOut.flush();
    dataOut.close();

  } catch (Exception x) {
    x.printStackTrace();
  } finally {
    closeSoket();

  }
}
 
Example 16
Source File: LogGenericWritable.java    From 163-bigdate-note with GNU General Public License v3.0 4 votes vote down vote up
public void write(DataOutput out) throws IOException {
    WritableUtils.writeVInt(out, name.length);
    for (int i = 0; i < name.length; i++) {
        datum[i].write(out);
    }
}
 
Example 17
Source File: BaseSingleExpression.java    From phoenix with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void write(DataOutput output) throws IOException {
    WritableUtils.writeVInt(output, ExpressionType.valueOf(children.get(0)).ordinal());
    children.get(0).write(output);
}
 
Example 18
Source File: ShuffleHeader.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public void write(DataOutput out) throws IOException {
  Text.writeString(out, mapId);
  WritableUtils.writeVLong(out, compressedLength);
  WritableUtils.writeVLong(out, uncompressedLength);
  WritableUtils.writeVInt(out, forReduce);
}
 
Example 19
Source File: TestMiniMRLocalFS.java    From RDFS with Apache License 2.0 4 votes vote down vote up
public void write(DataOutput out) throws IOException {
  WritableUtils.writeVInt(out, first);
  WritableUtils.writeVInt(out, length);
}
 
Example 20
Source File: BinaryProtocol.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public void abort() throws IOException {
  WritableUtils.writeVInt(stream, MessageType.ABORT.code);
  LOG.debug("Sent abort command");
}