com.bigdata.rdf.spo
Class SPOKeyOrder

java.lang.Object
  extended by com.bigdata.rdf.spo.SPOKeyOrder
All Implemented Interfaces:
IKeyOrder<ISPO>, Serializable

public class SPOKeyOrder
extends Object
implements IKeyOrder<ISPO>, Serializable

Represents the key order used by an index for a triple relation.

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

Field Summary
static int _CSPO
           
static int _OCSP
           
static int _OSP
           
static int _PCSO
           
static int _POCS
           
static int _POS
           
static int _SOPC
           
static int _SPO
           
static int _SPOC
           
static SPOKeyOrder CSPO
           
static int FIRST_QUAD_INDEX
           
static int FIRST_TRIPLE_INDEX
           
static int LAST_QUAD_INDEX
           
static int LAST_TRIPLE_INDEX
           
static int MAX_INDEX_COUNT
           
static SPOKeyOrder OCSP
           
static SPOKeyOrder OSP
           
static SPOKeyOrder PCSO
           
static SPOKeyOrder POCS
           
static SPOKeyOrder POS
           
static SPOKeyOrder SOPC
           
static SPOKeyOrder SPO
           
static SPOKeyOrder SPOC
           
 
Method Summary
 SPO decodeKey(byte[] key)
          Decode the key into an SPO.
 byte[] encodeKey(IKeyBuilder keyBuilder, ISPO spo)
           
 Comparator<ISPO> getComparator()
          Return the comparator that places ISPOs into the natural order for the associated index.
 byte[] getFromKey(IKeyBuilder keyBuilder, IPredicate<ISPO> predicate)
          Return the inclusive lower bound which would be used for a query against this IKeyOrder for the given IPredicate.
 String getIndexName()
          The base name for the index.
 int getKeyArity()
          Return either 3 or 4 depending on the #of components in the key for this natural key ordering.
 int getKeyOrder(int keyPos)
          Return the index of the slot in the ISPO tuple which appears at the specified position in the key.
static SPOKeyOrder getKeyOrder(IPredicate<ISPO> predicate, int keyArity)
          Return the SPOKeyOrder for the given predicate.
 byte[] getToKey(IKeyBuilder keyBuilder, IPredicate<ISPO> predicate)
          Return the exclusive upper bound which would be used for a query against this IKeyOrder for the given IPredicate.
 int index()
          The integer used to represent the SPOKeyOrder.
 boolean isPrimaryIndex()
          Return true if this is the primary index for the relation.
static Iterator<SPOKeyOrder> quadStoreKeyOrderIterator()
          Return an iterator which visits the quad store indices (SPOC, POCS, OCSP, CSPO, PCSO, SOPC ).
static Iterator<SPOKeyOrder> spocOnlyKeyOrderIterator()
          Return an iterator which visits only SPOC.
static Iterator<SPOKeyOrder> spoOnlyKeyOrderIterator()
          Return an iterator which visits only SPO.
 String toString()
          Return getIndexName()'s value.
static Iterator<SPOKeyOrder> tripleStoreKeyOrderIterator()
          Return an iterator which visits the triple store indices (SPO, POS, OSP).
static SPOKeyOrder valueOf(int index)
          Returns the singleton corresponding to the index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_SPO

public static final transient int _SPO
See Also:
Constant Field Values

_OSP

public static final transient int _OSP
See Also:
Constant Field Values

_POS

public static final transient int _POS
See Also:
Constant Field Values

_SPOC

public static final transient int _SPOC
See Also:
Constant Field Values

_POCS

public static final transient int _POCS
See Also:
Constant Field Values

_OCSP

public static final transient int _OCSP
See Also:
Constant Field Values

_CSPO

public static final transient int _CSPO
See Also:
Constant Field Values

_PCSO

public static final transient int _PCSO
See Also:
Constant Field Values

_SOPC

public static final transient int _SOPC
See Also:
Constant Field Values

FIRST_TRIPLE_INDEX

public static final transient int FIRST_TRIPLE_INDEX
See Also:
Constant Field Values

LAST_TRIPLE_INDEX

public static final transient int LAST_TRIPLE_INDEX
See Also:
Constant Field Values

FIRST_QUAD_INDEX

public static final transient int FIRST_QUAD_INDEX
See Also:
Constant Field Values

LAST_QUAD_INDEX

public static final transient int LAST_QUAD_INDEX
See Also:
Constant Field Values

MAX_INDEX_COUNT

public static final transient int MAX_INDEX_COUNT
See Also:
Constant Field Values

SPO

public static final transient SPOKeyOrder SPO

POS

public static final transient SPOKeyOrder POS

OSP

public static final transient SPOKeyOrder OSP

SPOC

public static final transient SPOKeyOrder SPOC

POCS

public static final transient SPOKeyOrder POCS

OCSP

public static final transient SPOKeyOrder OCSP

CSPO

public static final transient SPOKeyOrder CSPO

PCSO

public static final transient SPOKeyOrder PCSO

SOPC

public static final transient SPOKeyOrder SOPC
Method Detail

isPrimaryIndex

public final boolean isPrimaryIndex()
Return true if this is the primary index for the relation.

Returns:
true for SPO or SPOC. Those are the natural orders corresponding to the primary index for a triple store (SPO) and a quad store (SPOC) respectively.

valueOf

public static SPOKeyOrder valueOf(int index)
Returns the singleton corresponding to the index.

Parameters:
index - The index.
Returns:
The singleton SPOKeyOrder having that index.
Throws:
IllegalArgumentException - if the index is not valid.

getIndexName

public final String getIndexName()
The base name for the index.

Specified by:
getIndexName in interface IKeyOrder<ISPO>

toString

public String toString()
Return getIndexName()'s value.

Overrides:
toString in class Object

getKeyArity

public final int getKeyArity()
Return either 3 or 4 depending on the #of components in the key for this natural key ordering.

Specified by:
getKeyArity in interface IKeyOrder<ISPO>

getKeyOrder

public final int getKeyOrder(int keyPos)
Return the index of the slot in the ISPO tuple which appears at the specified position in the key.

Specified by:
getKeyOrder in interface IKeyOrder<ISPO>
Parameters:
keyPos - The index into the key that is being generated.
Returns:
The index of the slot in the ISPO.

index

public final int index()
The integer used to represent the SPOKeyOrder. For a triple store, this is one of the constants: _SPO, POS, or OSP. For a quad store, this is one of the constants _SPOC, _POCS, _OCSP, _CSPO, _PCSO, _SOPC.


getComparator

public final Comparator<ISPO> getComparator()
Return the comparator that places ISPOs into the natural order for the associated index.

Specified by:
getComparator in interface IKeyOrder<ISPO>
TODO:
performance comparison if we get rid of the SPOComparator, POSComparator, and OSPComparator and just use the GeneralComparator. Will the hot spot compiler do better with just one class handling all of those comparisons?

getFromKey

public final byte[] getFromKey(IKeyBuilder keyBuilder,
                               IPredicate<ISPO> predicate)
Return the inclusive lower bound which would be used for a query against this IKeyOrder for the given IPredicate.

TODO:
This method should be declared by IKeyOrder.

getToKey

public final byte[] getToKey(IKeyBuilder keyBuilder,
                             IPredicate<ISPO> predicate)
Return the exclusive upper bound which would be used for a query against this IKeyOrder for the given IPredicate.

TODO:
This method should be declared by IKeyOrder.

encodeKey

public final byte[] encodeKey(IKeyBuilder keyBuilder,
                              ISPO spo)

decodeKey

public final SPO decodeKey(byte[] key)
Decode the key into an SPO. The StatementEnum and the optional SID will not be decoded, since it is carried in the B+Tree value. However, if the SPOKeyOrder is a quad order then the SPO.c() will be bound.

Parameters:
keyOrder - The natural order of the key.
key - The key.
Returns:
The decoded key.

getKeyOrder

public static SPOKeyOrder getKeyOrder(IPredicate<ISPO> predicate,
                                      int keyArity)
Return the SPOKeyOrder for the given predicate.

Parameters:
predicate - The predicate.
Returns:
The SPOKeyOrder
TODO:
A variant of this method should be raised onto IKeyOrder without the keyArity parameter. That parameter is only there because we support two distinct families of natural orders in this class: one for triples and one for quads.

tripleStoreKeyOrderIterator

public static Iterator<SPOKeyOrder> tripleStoreKeyOrderIterator()
Return an iterator which visits the triple store indices (SPO, POS, OSP).


quadStoreKeyOrderIterator

public static Iterator<SPOKeyOrder> quadStoreKeyOrderIterator()
Return an iterator which visits the quad store indices (SPOC, POCS, OCSP, CSPO, PCSO, SOPC ).


spoOnlyKeyOrderIterator

public static Iterator<SPOKeyOrder> spoOnlyKeyOrderIterator()
Return an iterator which visits only SPO.


spocOnlyKeyOrderIterator

public static Iterator<SPOKeyOrder> spocOnlyKeyOrderIterator()
Return an iterator which visits only SPOC.



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