Example usage for org.apache.hadoop.io VIntWritable VIntWritable

List of usage examples for org.apache.hadoop.io VIntWritable VIntWritable

Introduction

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

Prototype

public VIntWritable() 

Source Link

Usage

From source file:com.cg.mapreduce.fpgrowth.mahout.fpm.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 = Lists.newArrayList();
        vInt.readFields(in);/*w  w w  . j  a va2 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();

            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();
            }
        }
    }
}

From source file:com.cg.mapreduce.fpgrowth.mahout.fpm.TransactionTree.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    out.writeBoolean(representedAsList);
    VIntWritable vInt = new VIntWritable();
    VLongWritable vLong = new VLongWritable();
    if (representedAsList) {
        int transactionSetSize = transactionSet.size();
        vInt.set(transactionSetSize);//from  ww  w  .  j  a v a  2 s.co  m
        vInt.write(out);
        for (Pair<IntArrayList, Long> transaction : transactionSet) {
            vLong.set(transaction.getSecond());
            vLong.write(out);

            vInt.set(transaction.getFirst().size());
            vInt.write(out);

            IntArrayList items = transaction.getFirst();
            for (int idx = 0; idx < items.size(); idx++) {
                int item = items.get(idx);
                vInt.set(item);
                vInt.write(out);
            }
        }
    } else {
        vInt.set(nodes);
        vInt.write(out);
        for (int i = 0; i < nodes; i++) {
            vInt.set(attribute[i]);
            vInt.write(out);
            vLong.set(nodeCount[i]);
            vLong.write(out);
            vInt.set(childCount[i]);
            vInt.write(out);
            int max = childCount[i];
            for (int j = 0; j < max; j++) {
                vInt.set(nodeChildren[i][j]);
                vInt.write(out);
            }
        }
    }
}

From source file:com.jfolson.hive.serde.RTypedBytesWritableInput.java

License:Apache License

public VIntWritable readVInt(VIntWritable iw) throws IOException {
    if (iw == null) {
        iw = new VIntWritable();
    }/*from   w  w w .  ja v  a 2  s.c  o m*/
    iw.set(in.readInt());
    return iw;
}

From source file:com.toshiba.mwcloud.gs.hadoop.io.GSRowWritable.java

License:Apache License

private void readColumn(DataInput in, int i) throws IOException {
    byte type = in.readByte();
    switch (type) {
    case BLOB:/*from  w w w  .j av  a 2 s .  c  o  m*/
        types_[i] = GSType.BLOB;
        values_[i] = readBlob(in);
        break;
    case BOOL:
        types_[i] = GSType.BOOL;
        values_[i] = in.readBoolean();
        break;
    case BYTE:
        types_[i] = GSType.BYTE;
        values_[i] = in.readByte();
        break;
    case DOUBLE:
        types_[i] = GSType.DOUBLE;
        values_[i] = in.readDouble();
        break;
    case FLOAT:
        types_[i] = GSType.FLOAT;
        values_[i] = in.readFloat();
        break;
    case INTEGER:
        types_[i] = GSType.INTEGER;
        VIntWritable vint = new VIntWritable();
        vint.readFields(in);
        values_[i] = vint.get();
        break;
    case LONG:
        types_[i] = GSType.LONG;
        VLongWritable vlong = new VLongWritable();
        vlong.readFields(in);
        values_[i] = vlong.get();
        break;
    case SHORT:
        types_[i] = GSType.SHORT;
        values_[i] = in.readShort();
        break;
    case STRING:
        types_[i] = GSType.STRING;
        values_[i] = readString(in);
        break;
    case TIMESTAMP:
        types_[i] = GSType.TIMESTAMP;
        values_[i] = new Date(in.readLong());
        break;
    case BOOL_ARRAY:
        types_[i] = GSType.BOOL_ARRAY;
        values_[i] = readBoolArray(in);
        break;
    case BYTE_ARRAY:
        types_[i] = GSType.BYTE_ARRAY;
        values_[i] = readByteArray(in);
        break;
    case DOUBLE_ARRAY:
        types_[i] = GSType.DOUBLE_ARRAY;
        values_[i] = readDoubleArray(in);
        break;
    case FLOAT_ARRAY:
        types_[i] = GSType.FLOAT_ARRAY;
        values_[i] = readFloatArray(in);
        break;
    case INTEGER_ARRAY:
        types_[i] = GSType.INTEGER_ARRAY;
        values_[i] = readIntegerArray(in);
        break;
    case LONG_ARRAY:
        types_[i] = GSType.LONG_ARRAY;
        values_[i] = readLongArray(in);
        break;
    case SHORT_ARRAY:
        types_[i] = GSType.SHORT_ARRAY;
        values_[i] = readShortArray(in);
        break;
    case STRING_ARRAY:
        types_[i] = GSType.STRING_ARRAY;
        values_[i] = readStringArray(in);
        break;
    case TIMESTAMP_ARRAY:
        types_[i] = GSType.TIMESTAMP_ARRAY;
        values_[i] = readTimestampArray(in);
        break;
    default:
        throw new IOException();
    }
}

From source file:edu.umd.cloud9.io.pair.PairOfVInts.java

License:Apache License

/**
 * Creates a pair.
 */
public PairOfVInts() {
    leftElement = new VIntWritable();
    rightElement = new VIntWritable();
}

From source file:edu.umd.cloud9.io.pair.PairOfVInts.java

License:Apache License

/**
 * Creates a pair./* w ww.ja  v a2 s  . co m*/
 *
 * @param left the left element
 * @param right the right element
 */
public PairOfVInts(int left, int right) {
    leftElement = new VIntWritable();
    rightElement = new VIntWritable();
    set(left, right);
}

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 ww.  j av a 2s  .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 .  j a v a  2s .co 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;
    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 w w . j  a v  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:org.apache.mahout.fpm.pfpgrowth.TransactionTree.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    out.writeBoolean(representedAsList);
    VIntWritable vInt = new VIntWritable();
    VLongWritable vLong = new VLongWritable();
    if (representedAsList) {
        int transactionSetSize = transactionSet.size();
        vInt.set(transactionSetSize);//from   ww w.ja  v a 2s.  c  om
        vInt.write(out);
        for (int i = 0; i < transactionSetSize; i++) {
            Pair<List<Integer>, Long> transaction = transactionSet.get(i);

            vLong.set(transaction.getSecond());
            vLong.write(out);

            vInt.set(transaction.getFirst().size());
            vInt.write(out);

            for (Integer item : transaction.getFirst()) {
                vInt.set(item);
                vInt.write(out);
            }
        }
    } else {
        vInt.set(nodes);
        vInt.write(out);
        for (int i = 0; i < nodes; i++) {
            vInt.set(attribute[i]);
            vInt.write(out);
            vLong.set(nodeCount[i]);
            vLong.write(out);
            vInt.set(childCount[i]);
            vInt.write(out);
            for (int j = 0, k = childCount[i]; j < k; j++) {
                vInt.set(nodeChildren[i][j]);
                vInt.write(out);
            }
        }
    }
}