com.bigdata.rdf.spo
Class SPOTupleSerializer

java.lang.Object
  extended by com.bigdata.btree.DefaultTupleSerializer<SPO,SPO>
      extended by com.bigdata.rdf.spo.SPOTupleSerializer
All Implemented Interfaces:
ITupleSerializer<SPO,SPO>, IKeyBuilderFactory, Externalizable, Serializable

public class SPOTupleSerializer
extends DefaultTupleSerializer<SPO,SPO>

(De-)serializes SPOs for statement indices.

Note: the encoded key for a statement is formed from the 64-bit long term identifier for the subject, predicate, and object positions of the statement. Each statement index uses a permutation of those term identifiers, e.g., {s,p,o}, {o,s,p}, or {p,o,s}. The SPOKeyOrder identifies the specific permutation for a given index. The keys are fully decodable and are NOT stored redundantly in the tuple's value.

The tuple value encodes the StatementEnum, indicating whether the statement is {explicit, inferred, or an axiom}, and optionally the unique statement identifier.

Note: While the static methods used to decode an existing key are safe for concurrent readers, concurrent readers also form keys using statement2Key(long, long, long) and therefore require a thread-local IKeyBuilder.

Version:
$Id: SPOTupleSerializer.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
See Also:
Serialized Form

Constructor Summary
SPOTupleSerializer()
          De-serialization constructor.
SPOTupleSerializer(SPOKeyOrder keyOrder)
          Create an ITupleSerializer for the indicated access path.
SPOTupleSerializer(SPOKeyOrder keyOrder, IRabaCoder leafKeySer, IRabaCoder leafValSer)
          Create an ITupleSerializer for the indicated access path.
 
Method Summary
 SPO deserialize(ITuple tuple)
          De-serializes an object from the value stored in the tuple (ignores the key stored in the tuple).
 SPO deserializeKey(ITuple tuple)
          This is an unsupported operation.
 SPOKeyOrder getKeyOrder()
           
 void readExternal(ObjectInput in)
           
 byte[] serializeKey(ISPO spo)
          Forms the statement key.
 byte[] serializeKey(Object obj)
          Serialize a facet of an object's state that places the object into the total sort order for the index.
 byte[] serializeVal(SPO spo)
          Encodes the StatementEnum and the optional statement identifier.
 byte[] statement2Key(long id1, long id2, long id3)
          Encodes a statement represented as three long integers as an unsigned byte[] sort key.
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class com.bigdata.btree.DefaultTupleSerializer
getDefaultKeyBuilderFactory, getDefaultLeafKeysCoder, getDefaultValuesCoder, getKeyBuilder, getLeafKeysCoder, getLeafValuesCoder, newInstance, serializeVal, setLeafKeysCoder, setLeafValuesCoder, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SPOTupleSerializer

public SPOTupleSerializer()
De-serialization constructor.


SPOTupleSerializer

public SPOTupleSerializer(SPOKeyOrder keyOrder)
Create an ITupleSerializer for the indicated access path.

Parameters:
keyOrder - The access path.

SPOTupleSerializer

public SPOTupleSerializer(SPOKeyOrder keyOrder,
                          IRabaCoder leafKeySer,
                          IRabaCoder leafValSer)
Create an ITupleSerializer for the indicated access path.

Parameters:
keyOrder - The access path.
leafKeySer -
leafValSer -
Method Detail

getKeyOrder

public SPOKeyOrder getKeyOrder()

deserialize

public SPO deserialize(ITuple tuple)
Description copied from class: DefaultTupleSerializer
De-serializes an object from the value stored in the tuple (ignores the key stored in the tuple).

Specified by:
deserialize in interface ITupleSerializer<SPO,SPO>
Overrides:
deserialize in class DefaultTupleSerializer<SPO,SPO>
Parameters:
tuple - The tuple.
Returns:
The de-serialized object.

deserializeKey

public SPO deserializeKey(ITuple tuple)
Description copied from class: DefaultTupleSerializer
This is an unsupported operation. Additional information is required to either decode the internal unsigned byte[] keys or to extract the key from the de-serialized value (if it is being stored in that value). You can either write your own ITupleSerializer or you can specialize this one so that it can de-serialize your keys using whichever approach makes the most sense for your data.

Specified by:
deserializeKey in interface ITupleSerializer<SPO,SPO>
Overrides:
deserializeKey in class DefaultTupleSerializer<SPO,SPO>

serializeKey

public byte[] serializeKey(Object obj)
Description copied from interface: ITupleSerializer
Serialize a facet of an object's state that places the object into the total sort order for the index. This method is automatically applied by IAutoboxBTree.insert(Object, Object) and friends to convert the key object into an unsigned variable length byte[].

Note: This handles the conversion between an object and the unsigned variable length byte[] representation of that object which determines its place within the total index order. Since this transform imposes the total order of the index, different techniques are applied here than are applied to the serialization of the index values.

Specified by:
serializeKey in interface ITupleSerializer<SPO,SPO>
Overrides:
serializeKey in class DefaultTupleSerializer<SPO,SPO>
Parameters:
obj - A object (MAY NOT be null).
Returns:
An unsigned byte[] which places the object into the total sort order for the index and never null ( null keys are not allowed into an index).

serializeKey

public byte[] serializeKey(ISPO spo)
Forms the statement key.

Parameters:
spo - The statement.
Returns:
The key.

statement2Key

public byte[] statement2Key(long id1,
                            long id2,
                            long id3)
Encodes a statement represented as three long integers as an unsigned byte[] sort key.

Note: while the conversion of long integers into the byte[] is non-trivial the value identifiers are mapped onto 8 bytes at a time and the contents of the array could be rearranged into alternative orders directly. For example, if you provide (s,p,o) then you could form the (p,o,s) key by copying 8 byte sections of the returned sort key around to generate the desired permutation.

Parameters:
id1 - An RDF value identifier from the term index.
id2 - An RDF value identifier from the term index.
id3 - An RDF value identifier from the term index.
Returns:
The sort key for the statement with those values.

serializeVal

public byte[] serializeVal(SPO spo)
Encodes the StatementEnum and the optional statement identifier.

Parameters:
spo - An object (MAY NOT be null).
Returns:
A byte[] containing the serialized state of the object -or- null if no value will be stored under the serialized key.

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Overrides:
readExternal in class DefaultTupleSerializer<SPO,SPO>
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Overrides:
writeExternal in class DefaultTupleSerializer<SPO,SPO>
Throws:
IOException


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.