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: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);//from   w w w  . ja v a 2s  .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();
            }
        }
    }
}

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

License:Apache License

public void writeRawVLong(VLongWritable vlw) throws IOException {
    out.writeRawLong(vlw.get());
}

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

License:Apache License

public void writeVLong(VLongWritable vlw) throws IOException {
    out.writeLong(vlw.get());
}

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:/*w w w .j  a v 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:cosmos.accumulo.GroupByRowSuffixIteratorTest.java

License:Apache License

@Test
public void testSingleRow() throws Exception {
    ZooKeeperInstance zk = new ZooKeeperInstance(mac.getInstanceName(), mac.getZooKeepers());
    Connector c = zk.getConnector("root", new PasswordToken("root"));

    final String tableName = "foo";

    if (c.tableOperations().exists(tableName)) {
        c.tableOperations().delete(tableName);
    }//from w w  w .  ja  va2 s. c  o  m

    c.tableOperations().create(tableName);

    BatchWriter bw = null;
    try {
        bw = c.createBatchWriter(tableName, new BatchWriterConfig());

        Mutation m = new Mutation("1_a");
        m.put("a", "a", 0, "");
        m.put("a", "b", 0, "");

        bw.addMutation(m);

        m = new Mutation("1_b");
        m.put("a", "a", 0, "");

        bw.addMutation(m);

        m = new Mutation("1_c");
        m.put("a", "a", 0, "");
        m.put("b", "a", 0, "");
        m.put("c", "a", 0, "");

        bw.addMutation(m);
    } finally {
        if (null != bw) {
            bw.close();
        }
    }

    Map<Key, Long> results = ImmutableMap.<Key, Long>builder().put(new Key("1_a", "a", "b", 0), 2l)
            .put(new Key("1_b", "a", "a", 0), 1l).put(new Key("1_c", "c", "a", 0), 3l).build();

    BatchScanner bs = c.createBatchScanner(tableName, new Authorizations(), 1);
    bs.setRanges(Collections.singleton(new Range()));

    try {
        IteratorSetting cfg = new IteratorSetting(30, GroupByRowSuffixIterator.class);

        bs.addScanIterator(cfg);

        long count = 0;
        for (Entry<Key, Value> entry : bs) {
            VLongWritable writable = GroupByRowSuffixIterator.getWritable(entry.getValue());

            Assert.assertTrue("Results did not contain: " + entry.getKey(),
                    results.containsKey(entry.getKey()));
            Assert.assertEquals(results.get(entry.getKey()).longValue(), writable.get());

            count++;
        }

        Assert.assertEquals(results.size(), count);
    } finally {
        if (null != bs) {
            bs.close();
        }
    }
}

From source file:cosmos.accumulo.GroupByRowSuffixIteratorTest.java

License:Apache License

@Test
public void testMultipleRows() throws Exception {
    ZooKeeperInstance zk = new ZooKeeperInstance(mac.getInstanceName(), mac.getZooKeepers());
    Connector c = zk.getConnector("root", new PasswordToken("root"));

    final String tableName = "foo";

    if (c.tableOperations().exists(tableName)) {
        c.tableOperations().delete(tableName);
    }//from  w  ww  . j a  v  a  2  s  .  c  o  m

    c.tableOperations().create(tableName);

    BatchWriter bw = null;
    try {
        bw = c.createBatchWriter(tableName, new BatchWriterConfig());

        for (int i = 1; i < 6; i++) {
            Mutation m = new Mutation(i + "_a");
            m.put("a", "a", 0, "");
            m.put("a", "b", 0, "");

            bw.addMutation(m);

            m = new Mutation(i + "_b");
            m.put("a", "a", 0, "");

            bw.addMutation(m);

            m = new Mutation(i + "_c");
            m.put("a", "a", 0, "");
            m.put("b", "a", 0, "");
            m.put("c", "a", 0, "");

            bw.addMutation(m);
        }
    } finally {
        if (null != bw) {
            bw.close();
        }
    }

    for (int i = 1; i < 6; i++) {
        Map<Key, Long> results = ImmutableMap.<Key, Long>builder().put(new Key(i + "_a", "a", "b", 0), 2l)
                .put(new Key(i + "_b", "a", "a", 0), 1l).put(new Key(i + "_c", "c", "a", 0), 3l).build();

        BatchScanner bs = c.createBatchScanner(tableName, new Authorizations(), 1);
        bs.setRanges(Collections.singleton(Range.prefix(Integer.toString(i))));

        try {
            IteratorSetting cfg = new IteratorSetting(30, GroupByRowSuffixIterator.class);

            bs.addScanIterator(cfg);

            long count = 0;
            for (Entry<Key, Value> entry : bs) {
                VLongWritable writable = GroupByRowSuffixIterator.getWritable(entry.getValue());

                Assert.assertTrue("Results did not contain: " + entry.getKey(),
                        results.containsKey(entry.getKey()));
                Assert.assertEquals(results.get(entry.getKey()).longValue(), writable.get());

                count++;
            }

            Assert.assertEquals(results.size(), count);
        } finally {
            if (null != bs) {
                bs.close();
            }
        }
    }
}

From source file:cosmos.accumulo.GroupByRowSuffixIteratorTest.java

License:Apache License

@Test
public void testSingleRowSingleColumn() throws Exception {
    ZooKeeperInstance zk = new ZooKeeperInstance(mac.getInstanceName(), mac.getZooKeepers());
    Connector c = zk.getConnector("root", new PasswordToken("root"));

    final String tableName = "foo";

    if (c.tableOperations().exists(tableName)) {
        c.tableOperations().delete(tableName);
    }/*ww w.  ja  va2 s.c  o m*/

    c.tableOperations().create(tableName);

    BatchWriter bw = null;
    try {
        bw = c.createBatchWriter(tableName, new BatchWriterConfig());

        Mutation m = new Mutation("1_a");
        m.put("col1", "1", 0, "");
        m.put("col1", "2", 0, "");

        bw.addMutation(m);

        m = new Mutation("1_b");
        m.put("col1", "1", 0, "");

        bw.addMutation(m);

        m = new Mutation("1_c");
        m.put("col1", "1", 0, "");
        m.put("col2", "2", 0, "");
        m.put("col3", "1", 0, "");

        bw.addMutation(m);
    } finally {
        if (null != bw) {
            bw.close();
        }
    }

    Map<Key, Long> results = ImmutableMap.<Key, Long>builder().put(new Key("1_a", "col1", "2", 0), 2l)
            .put(new Key("1_b", "col1", "1", 0), 1l).put(new Key("1_c", "col1", "1", 0), 1l).build();

    BatchScanner bs = c.createBatchScanner(tableName, new Authorizations(), 1);
    bs.setRanges(Collections.singleton(new Range()));
    bs.fetchColumnFamily(new Text("col1"));

    try {
        IteratorSetting cfg = new IteratorSetting(30, GroupByRowSuffixIterator.class);

        bs.addScanIterator(cfg);

        long count = 0;
        for (Entry<Key, Value> entry : bs) {
            VLongWritable writable = GroupByRowSuffixIterator.getWritable(entry.getValue());

            Assert.assertTrue("Results did not contain: " + entry.getKey(),
                    results.containsKey(entry.getKey()));
            Assert.assertEquals(results.get(entry.getKey()).longValue(), writable.get());

            count++;
        }

        Assert.assertEquals(results.size(), count);
    } finally {
        if (null != bs) {
            bs.close();
        }
    }
}

From source file:cosmos.accumulo.GroupByRowSuffixIteratorTest.java

License:Apache License

@Test
public void testManyRowsSingleColumn() throws Exception {
    ZooKeeperInstance zk = new ZooKeeperInstance(mac.getInstanceName(), mac.getZooKeepers());
    Connector c = zk.getConnector("root", new PasswordToken("root"));

    final String tableName = "foo";

    if (c.tableOperations().exists(tableName)) {
        c.tableOperations().delete(tableName);
    }/*from   w  w w . j a va 2 s .  com*/

    c.tableOperations().create(tableName);

    BatchWriter bw = null;
    try {
        bw = c.createBatchWriter(tableName, new BatchWriterConfig());

        for (int i = 1; i < 6; i++) {
            Mutation m = new Mutation(i + "_a");
            m.put("col1", "1", 0, "");
            m.put("col1", "2", 0, "");

            bw.addMutation(m);

            m = new Mutation(i + "_b");
            m.put("col1", "1", 0, "");

            bw.addMutation(m);

            m = new Mutation(i + "_c");
            m.put("col1", "1", 0, "");
            m.put("col2", "2", 0, "");
            m.put("col3", "1", 0, "");

            bw.addMutation(m);
        }
    } finally {
        if (null != bw) {
            bw.close();
        }
    }

    for (int i = 1; i < 6; i++) {
        Map<Key, Long> results = ImmutableMap.<Key, Long>builder().put(new Key(i + "_a", "col1", "2", 0), 2l)
                .put(new Key(i + "_b", "col1", "1", 0), 1l).put(new Key(i + "_c", "col1", "1", 0), 1l).build();

        BatchScanner bs = c.createBatchScanner(tableName, new Authorizations(), 1);
        bs.setRanges(Collections.singleton(Range.prefix(Integer.toString(i))));
        bs.fetchColumnFamily(new Text("col1"));

        try {
            IteratorSetting cfg = new IteratorSetting(30, GroupByRowSuffixIterator.class);

            bs.addScanIterator(cfg);

            long count = 0;
            for (Entry<Key, Value> entry : bs) {
                VLongWritable writable = GroupByRowSuffixIterator.getWritable(entry.getValue());

                Assert.assertTrue("Results did not contain: " + entry.getKey(),
                        results.containsKey(entry.getKey()));
                Assert.assertEquals(results.get(entry.getKey()).longValue(), writable.get());

                count++;
            }

            Assert.assertEquals(results.size(), count);
        } finally {
            if (null != bs) {
                bs.close();
            }
        }
    }
}

From source file:cosmos.impl.GroupByFunction.java

License:Apache License

@Override
public Entry<RecordValue<?>, Long> apply(Entry<Key, Value> entry) {
    String value = getValueFromKey(entry.getKey());

    //TODO Add Cache for CV
    RecordValue<?> val = RecordValue.create(value, entry.getKey().getColumnVisibilityParsed());
    VLongWritable writable = GroupByRowSuffixIterator.getWritable(entry.getValue());

    return Maps.<RecordValue<?>, Long>immutableEntry(val, writable.get());
}

From source file:edu.uci.ics.pregelix.benchmark.vertex.ConnectedComponentsVertex.java

License:Apache License

/**
 * Propagates the smallest vertex id to all neighbors. Will always choose to
 * halt and only reactivate if a smaller id has been sent to it.
 * //from  w ww  . j  a v a  2 s .  c o m
 * @param messages
 *            Iterator of messages from the previous superstep.
 * @throws IOException
 */
@Override
public void compute(Iterable<VLongWritable> messages) throws IOException {
    long currentComponent = getValue().get();

    // First superstep is special, because we can simply look at the neighbors
    if (getSuperstep() == 0) {
        for (Edge<VLongWritable, NullWritable> edge : getEdges()) {
            long neighbor = edge.getTargetVertexId().get();
            if (neighbor < currentComponent) {
                currentComponent = neighbor;
            }
        }
        // Only need to send value if it is not the own id
        if (currentComponent != getValue().get()) {
            setValue(new VLongWritable(currentComponent));
            for (Edge<VLongWritable, NullWritable> edge : getEdges()) {
                VLongWritable neighbor = edge.getTargetVertexId();
                if (neighbor.get() > currentComponent) {
                    sendMessage(neighbor, getValue());
                }
            }
        }

        voteToHalt();
        return;
    }

    boolean changed = false;
    // did we get a smaller id ?
    for (VLongWritable message : messages) {
        long candidateComponent = message.get();
        if (candidateComponent < currentComponent) {
            currentComponent = candidateComponent;
            changed = true;
        }
    }

    // propagate new component id to the neighbors
    if (changed) {
        setValue(new VLongWritable(currentComponent));
        sendMessageToAllEdges(getValue());
    }
    voteToHalt();
}