Example usage for org.apache.hadoop.io VLongWritable get

List of usage examples for org.apache.hadoop.io VLongWritable get

Introduction

In this page you can find the example usage for org.apache.hadoop.io VLongWritable get.

Prototype

public long get() 

Source Link

Document

Return the value of this LongWritable.

Usage

From source file:edu.uci.ics.pregelix.example.trianglecounting.TriangleCountingAggregator.java

License:Apache License

@Override
public void step(VLongWritable partialResult) {
    state.set(state.get() + partialResult.get());
}

From source file:io.apigee.lembos.mapreduce.converters.input.VLongWritableConverter.java

License:Apache License

/**
 * Takes in a {@link VLongWritable} and returns a {@link Long}.
 *
 * @param scope the JavaScript scope//  w ww  .  j  av  a  2  s. c  o  m
 * @param writable the value to convert
 *
 * @return the {@link Long} equivalent
 */
@Override
public Object toJavaScript(final Scriptable scope, final VLongWritable writable) {
    return writable.get();
}

From source file:org.apache.hcatalog.data.ReaderWriter.java

License:Apache License

public static Object readDatum(DataInput in) throws IOException {

    byte type = in.readByte();
    switch (type) {

    case DataType.STRING:
        byte[] buffer = new byte[in.readInt()];
        in.readFully(buffer);/* w  w  w .  j a va  2  s.  c  o m*/
        return new String(buffer, UTF8);

    case DataType.INTEGER:
        VIntWritable vint = new VIntWritable();
        vint.readFields(in);
        return vint.get();

    case DataType.LONG:
        VLongWritable vlong = new VLongWritable();
        vlong.readFields(in);
        return vlong.get();

    case DataType.FLOAT:
        return in.readFloat();

    case DataType.DOUBLE:
        return in.readDouble();

    case DataType.BOOLEAN:
        return in.readBoolean();

    case DataType.BYTE:
        return in.readByte();

    case DataType.SHORT:
        return in.readShort();

    case DataType.NULL:
        return null;

    case DataType.BINARY:
        int len = in.readInt();
        byte[] ba = new byte[len];
        in.readFully(ba);
        return ba;

    case DataType.MAP:
        int size = in.readInt();
        Map<Object, Object> m = new HashMap<Object, Object>(size);
        for (int i = 0; i < size; i++) {
            m.put(readDatum(in), readDatum(in));
        }
        return m;

    case DataType.LIST:
        int sz = in.readInt();
        List<Object> list = new ArrayList<Object>(sz);
        for (int i = 0; i < sz; i++) {
            list.add(readDatum(in));
        }
        return list;

    default:
        throw new IOException("Unexpected data type " + type + " found in stream.");
    }
}

From source file:org.apache.hive.hcatalog.data.ReaderWriter.java

License:Apache License

public static Object readDatum(DataInput in) throws IOException {

    byte type = in.readByte();
    switch (type) {

    case DataType.STRING:
        byte[] buffer = new byte[in.readInt()];
        in.readFully(buffer);/*from w  ww.ja v a 2s.c om*/
        return new String(buffer, UTF8);

    case DataType.INTEGER:
        VIntWritable vint = new VIntWritable();
        vint.readFields(in);
        return vint.get();

    case DataType.LONG:
        VLongWritable vlong = new VLongWritable();
        vlong.readFields(in);
        return vlong.get();

    case DataType.FLOAT:
        return in.readFloat();

    case DataType.DOUBLE:
        return in.readDouble();

    case DataType.BOOLEAN:
        return in.readBoolean();

    case DataType.BYTE:
        return in.readByte();

    case DataType.SHORT:
        return in.readShort();

    case DataType.NULL:
        return null;

    case DataType.BINARY:
        int len = in.readInt();
        byte[] ba = new byte[len];
        in.readFully(ba);
        return ba;

    case DataType.MAP:
        int size = in.readInt();
        Map<Object, Object> m = new HashMap<Object, Object>(size);
        for (int i = 0; i < size; i++) {
            m.put(readDatum(in), readDatum(in));
        }
        return m;

    case DataType.LIST:
        int sz = in.readInt();
        List<Object> list = new ArrayList<Object>(sz);
        for (int i = 0; i < sz; i++) {
            list.add(readDatum(in));
        }
        return list;
    case DataType.CHAR:
        HiveCharWritable hcw = new HiveCharWritable();
        hcw.readFields(in);
        return hcw.getHiveChar();
    case DataType.VARCHAR:
        HiveVarcharWritable hvw = new HiveVarcharWritable();
        hvw.readFields(in);
        return hvw.getHiveVarchar();
    case DataType.DECIMAL:
        HiveDecimalWritable hdw = new HiveDecimalWritable();
        hdw.readFields(in);
        return hdw.getHiveDecimal();
    case DataType.DATE:
        DateWritable dw = new DateWritable();
        dw.readFields(in);
        return dw.get();
    case DataType.TIMESTAMP:
        TimestampWritable tw = new TimestampWritable();
        tw.readFields(in);
        return tw.getTimestamp();
    default:
        throw new IOException("Unexpected data type " + type + " found in stream.");
    }
}

From source file:org.apache.mahout.fpm.pfpgrowth.TransactionTree.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    representedAsList = in.readBoolean();

    VIntWritable vInt = new VIntWritable();
    VLongWritable vLong = new VLongWritable();

    if (representedAsList) {
        transactionSet = new ArrayList<Pair<List<Integer>, Long>>();
        vInt.readFields(in);//from w ww . jav a2  s .  c  o m
        int numTransactions = vInt.get();
        for (int i = 0; i < numTransactions; i++) {
            vLong.readFields(in);
            Long support = vLong.get();

            vInt.readFields(in);
            int length = vInt.get();

            Integer[] items = new Integer[length];
            for (int j = 0; j < length; j++) {
                vInt.readFields(in);
                items[j] = vInt.get();
            }
            Pair<List<Integer>, Long> transaction = new Pair<List<Integer>, Long>(Arrays.asList(items),
                    support);
            transactionSet.add(transaction);
        }
    } else {
        vInt.readFields(in);
        nodes = vInt.get();
        attribute = new int[nodes];
        nodeCount = new long[nodes];
        childCount = new int[nodes];
        nodeChildren = new int[nodes][];
        for (int i = 0; i < nodes; i++) {
            vInt.readFields(in);
            attribute[i] = vInt.get();
            vLong.readFields(in);
            nodeCount[i] = vLong.get();
            vInt.readFields(in);
            int childCountI = vInt.get();
            childCount[i] = childCountI;
            nodeChildren[i] = new int[childCountI];
            for (int j = 0; j < childCountI; j++) {
                vInt.readFields(in);
                nodeChildren[i][j] = vInt.get();
            }
        }
    }
}

From source file:PFPGrowth_in_SPARK.TransactionTree.java

License:Apache License

public void readFields(DataInput in) throws IOException {
    representedAsList = in.readBoolean();

    VIntWritable vInt = new VIntWritable();
    VLongWritable vLong = new VLongWritable();

    if (representedAsList) {
        transactionSet = Lists.newArrayList();
        vInt.readFields(in);/*from w  ww  . ja  v a  2 s . c  om*/
        int numTransactions = vInt.get();
        for (int i = 0; i < numTransactions; i++) {
            vLong.readFields(in);
            Long support = vLong.get();

            vInt.readFields(in);
            int length = vInt.get();

            int[] items = new int[length];
            for (int j = 0; j < length; j++) {
                vInt.readFields(in);
                items[j] = vInt.get();
            }
            Pair<IntArrayList, Long> transaction = new Pair<IntArrayList, Long>(new IntArrayList(items),
                    support);
            transactionSet.add(transaction);
        }
    } else {
        vInt.readFields(in);
        nodes = vInt.get();
        attribute = new int[nodes];
        nodeCount = new long[nodes];
        childCount = new int[nodes];
        nodeChildren = new int[nodes][];
        for (int i = 0; i < nodes; i++) {
            vInt.readFields(in);
            attribute[i] = vInt.get();
            vLong.readFields(in);
            nodeCount[i] = vLong.get();
            vInt.readFields(in);
            int childCountI = vInt.get();
            childCount[i] = childCountI;
            nodeChildren[i] = new int[childCountI];
            for (int j = 0; j < childCountI; j++) {
                vInt.readFields(in);
                nodeChildren[i][j] = vInt.get();
            }
        }
    }
}