Search in sources :

Example 31 with BytesInput

use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.

the class BytesId method asObject.

@Override
public Object asObject() {
    switch(this.idType) {
        case LONG:
            BytesInput input = IOFactory.createBytesInput(this.bytes, 0, this.length);
            try {
                return input.readLong();
            } catch (IOException e) {
                throw new ComputerException("Failed to read BytesId to " + "Long object");
            }
        case UTF8:
            return CoderUtil.decode(this.bytes, 0, this.length);
        case UUID:
            input = IOFactory.createBytesInput(this.bytes, 0, this.length);
            try {
                long high = input.readLong();
                long low = input.readLong();
                return new UUID(high, low);
            } catch (IOException e) {
                throw new ComputerException("Failed to read BytesId to " + "UUID object");
            }
        default:
            throw new ComputerException("Unexpected IdType %s", this.idType);
    }
}
Also used : BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) IOException(java.io.IOException) UUID(java.util.UUID) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Example 32 with BytesInput

use of com.baidu.hugegraph.computer.core.io.BytesInput in project hugegraph-computer by hugegraph.

the class EntriesUtil method kvEntryWithFirstSubKv.

public static KvEntryWithFirstSubKv kvEntryWithFirstSubKv(KvEntry entry) {
    try {
        BytesInput input = IOFactory.createBytesInput(entry.value().bytes());
        // Read sub-entry size
        long subKvNum = input.readFixedInt();
        KvEntry firstSubKv = EntriesUtil.subKvEntryFromInput(input, true);
        return new KvEntryWithFirstSubKv(entry.key(), entry.value(), firstSubKv, subKvNum);
    } catch (IOException e) {
        throw new ComputerException(e.getMessage(), e);
    }
}
Also used : BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) IOException(java.io.IOException) ComputerException(com.baidu.hugegraph.computer.core.common.exception.ComputerException)

Aggregations

BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)32 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)16 Test (org.junit.Test)16 KvEntriesInput (com.baidu.hugegraph.computer.core.store.buffer.KvEntriesInput)10 KvEntry (com.baidu.hugegraph.computer.core.store.entry.KvEntry)8 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)7 Config (com.baidu.hugegraph.computer.core.config.Config)5 Id (com.baidu.hugegraph.computer.core.graph.id.Id)5 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)4 ComputerException (com.baidu.hugegraph.computer.core.common.exception.ComputerException)4 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)4 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 CombineKvInnerSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvInnerSortFlusher)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)3 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)3 EntryOutput (com.baidu.hugegraph.computer.core.store.entry.EntryOutput)3 EntryOutputImpl (com.baidu.hugegraph.computer.core.store.entry.EntryOutputImpl)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3