Example usage for org.apache.hadoop.io WritableUtils writeVInt

List of usage examples for org.apache.hadoop.io WritableUtils writeVInt

Introduction

In this page you can find the example usage for org.apache.hadoop.io WritableUtils writeVInt.

Prototype

public static void writeVInt(DataOutput stream, int i) throws IOException 

Source Link

Document

Serializes an integer to a binary stream with zero-compressed encoding.

Usage

From source file:org.apache.phoenix.expression.aggregator.ServerAggregators.java

License:Apache License

/**
 * Serialize an Aggregator into a byte array
 * @param aggFuncs list of aggregator to serialize
 * @return serialized byte array respresentation of aggregator
 */// w w  w. j  a va2 s  . com
public static byte[] serialize(List<SingleAggregateFunction> aggFuncs, int minNullableIndex) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    try {
        DataOutputStream output = new DataOutputStream(stream);
        WritableUtils.writeVInt(output, minNullableIndex);
        WritableUtils.writeVInt(output, aggFuncs.size());
        for (int i = 0; i < aggFuncs.size(); i++) {
            SingleAggregateFunction aggFunc = aggFuncs.get(i);
            WritableUtils.writeVInt(output, ExpressionType.valueOf(aggFunc).ordinal());
            aggFunc.write(output);
        }
        return stream.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:org.apache.phoenix.expression.ArrayConstructorExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    if (rowKeyOrderOptimizable) {
        WritableUtils.writeVInt(output, -(baseType.ordinal() + 1));
    } else {//  www .j a  v  a 2  s. c  o m
        WritableUtils.writeVInt(output, baseType.ordinal());
    }
}

From source file:org.apache.phoenix.expression.BaseCompoundExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    WritableUtils.writeVInt(output, children.size());
    for (int i = 0; i < children.size(); i++) {
        Expression child = children.get(i);
        WritableUtils.writeVInt(output, ExpressionType.valueOf(child).ordinal());
        child.write(output);// w w w .j  a  va2 s  . c  om
    }
}

From source file:org.apache.phoenix.expression.BaseSingleExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    WritableUtils.writeVInt(output, ExpressionType.valueOf(children.get(0)).ordinal());
    children.get(0).write(output);/*from  w w  w .j av  a  2 s  .  co  m*/
}

From source file:org.apache.phoenix.expression.CaseExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    WritableUtils.writeVInt(output, this.returnType.ordinal());
}

From source file:org.apache.phoenix.expression.CoerceExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    if (rowKeyOrderOptimizable) {
        WritableUtils.writeVInt(output, -(toType.ordinal() + 1));
    } else {//from w ww .  ja v  a 2 s. co  m
        WritableUtils.writeVInt(output, toType.ordinal());
    }
    WritableUtils.writeVInt(output, toSortOrder.getSystemValue());
    WritableUtils.writeVInt(output, maxLength == null ? -1 : maxLength);
}

From source file:org.apache.phoenix.expression.ColumnExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    // read/write type ordinal, maxLength presence, scale presence and isNullable bit together to save space
    int typeAndFlag = (isNullable ? 1 : 0) | ((scale != null ? 1 : 0) << 1) | ((maxLength != null ? 1 : 0) << 2)
            | (type.ordinal() << 3);
    WritableUtils.writeVInt(output, typeAndFlag);
    if (scale != null) {
        WritableUtils.writeVInt(output, scale);
    }//from   ww w.j  a v  a  2s .c o  m
    if (maxLength != null) {
        WritableUtils.writeVInt(output, maxLength);
    }
    WritableUtils.writeVInt(output, sortOrder.getSystemValue());
}

From source file:org.apache.phoenix.expression.ComparisonExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    WritableUtils.writeVInt(output, op.ordinal());
    super.write(output);
}

From source file:org.apache.phoenix.expression.function.RoundDecimalExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    WritableUtils.writeVInt(output, scale);
}

From source file:org.apache.phoenix.expression.InListExpression.java

License:Apache License

@Override
public void write(DataOutput output) throws IOException {
    super.write(output);
    output.writeBoolean(false); // Unused, but left for b/w compat. TODO: remove in next major release
    WritableUtils.writeVInt(output, fixedWidth);
    WritableUtils.writeVInt(output, valuesByteLength);
    for (ImmutableBytesPtr ptr : values) {
        output.write(ptr.get(), ptr.getOffset(), ptr.getLength());
    }/*from w ww.j  av a  2 s. co m*/
    if (fixedWidth == -1) {
        WritableUtils.writeVInt(output, values.size());
        for (ImmutableBytesPtr ptr : values) {
            WritableUtils.writeVInt(output, ptr.getLength());
        }
    }
}