public class SPORelation extends AbstractRelation<ISPO>
SPORelation
handles all things related to the indices
representing the triples stored in the database. Statements are first
converted to term identifiers using the LexiconRelation
and then
inserted into the statement indices in parallel. There is one statement index
for each of the three possible access paths for a triple store. The key is
formed from the corresponding permutation of the subject, predicate, and
object, e.g., {s,p,o}, {p,o,s}, and {o,s,p} for triples or {s,p,o,c}, etc for
quads. The statement type (inferred, axiom, or explicit) and the optional
statement identifier are stored under the key. All state for a statement is
replicated in each of the statement indices.AbstractResource.Options
Modifier and Type | Field and Description |
---|---|
protected boolean |
bloomFilter
true iff the SPO index will maintain a bloom filter. |
boolean |
justify
This is used to conditionally enable the logic to retract justifications
when the corresponding statements is retracted.
|
protected static org.apache.log4j.Logger |
log |
static String |
NAME_HISTORY |
static String |
NAME_SPO_RELATION
Constant for the
SPORelation namespace component. |
boolean |
oneAccessPath
This is used to conditionally disable all but a single statement index
(aka access path).
|
indexManager
Constructor and Description |
---|
SPORelation(AbstractTripleStore container,
IIndexManager indexManager,
String namespace,
Long timestamp,
Properties properties) |
SPORelation(IIndexManager indexManager,
String namespace,
Long timestamp,
Properties properties) |
Modifier and Type | Method and Description |
---|---|
long |
addJustifications(IChunkedIterator<Justification> itr)
Adds justifications to the store.
|
void |
create()
Create any logically contained resources (relations, indices).
|
long |
delete(IChunkedOrderedIterator<ISPO> itr)
Deletes
SPO s, writing on the statement indices in parallel. |
long |
delete(ISPO[] stmts,
int numStmts)
Delete the
SPO s from the statement indices. |
void |
destroy()
Destroy any logically contained resources (relations, indices).
|
IChunkedIterator<IV> |
distinctMultiTermScan(IKeyOrder<ISPO> keyOrder,
IV[] knownTerms)
Efficient scan of the distinct term identifiers that appear in the first
position of the keys for the statement index corresponding to the
specified
IKeyOrder . |
IChunkedIterator<IV> |
distinctMultiTermScan(IKeyOrder<ISPO> keyOrder,
IV[] knownTerms,
ITermIVFilter termIdFilter)
Efficient scan of the distinct term identifiers that appear in the first
position of the keys for the statement index corresponding to the
specified
IKeyOrder . |
ICloseableIterator<ISPO> |
distinctSPOIterator(ICloseableIterator<ISPO> src)
Return an iterator that will visit the distinct (s,p,o) tuples in the
source iterator.
|
IChunkedIterator<IV> |
distinctTermScan(IKeyOrder<ISPO> keyOrder)
Efficient scan of the distinct term identifiers that appear in the first
position of the keys for the statement index corresponding to the
specified
IKeyOrder . |
IChunkedIterator<IV> |
distinctTermScan(IKeyOrder<ISPO> keyOrder,
byte[] fromKey,
byte[] toKey,
ITermIVFilter termIdFilter)
Efficient scan of the distinct term identifiers that appear in the first
position of the keys for the statement index corresponding to the
specified
IKeyOrder . |
IChunkedIterator<IV> |
distinctTermScan(IKeyOrder<ISPO> keyOrder,
ITermIVFilter filter)
Efficient scan of the distinct term identifiers that appear in the first
position of the keys for the statement index corresponding to the
specified
IKeyOrder . |
StringBuilder |
dump(IKeyOrder<ISPO> keyOrder)
Dumps the specified index.
|
boolean |
exists() |
IAccessPath<ISPO> |
getAccessPath(IV s,
IV p,
IV o)
Deprecated.
|
IAccessPath<ISPO> |
getAccessPath(IV s,
IV p,
IV o,
IV c)
Return the access path for a triple or quad pattern.
|
IAccessPath<ISPO> |
getAccessPath(IV s,
IV p,
IV o,
IV c,
IElementFilter<ISPO> filter)
Return the access path for a triple or quad pattern with a filter.
|
IAccessPath<ISPO> |
getAccessPath(IV s,
IV p,
IV o,
IV c,
IElementFilter<ISPO> filter,
RangeBOp range)
Return the access path for a triple or quad pattern with an optional
filter (core implementation).
|
IAccessPath<ISPO> |
getAccessPath(IV s,
IV p,
IV o,
IV c,
RangeBOp range)
Return the access path for a triple or quad pattern with a range.
|
AbstractTripleStore |
getContainer()
Strengthened return type.
|
Class<ISPO> |
getElementClass()
Return the class for the generic type of this relation.
|
protected IndexMetadata |
getHistoryIndexMetadata(SPOKeyOrder keyOrder)
Overrides for the statement indices.
|
IIndex |
getIndex(IKeyOrder<? extends ISPO> keyOrder)
Overridden to return the hard reference for the index, which is cached
the first time it is resolved.
|
Set<String> |
getIndexNames()
Return the fully qualified name of each index maintained by this
relation.
|
IIndex |
getJustificationIndex()
The optional index on which
Justification s are stored. |
protected IndexMetadata |
getJustIndexMetadata(String name)
Overrides for the
IRawTripleStore#getJustificationIndex() . |
int |
getKeyArity()
The arity of the key for the statement indices:
3 is a
triple store, with or without statement identifiers; 4 is a
quad store, which does not support statement identifiers as the 4th
position of the (s,p,o,c) is interpreted as context and located in the
B+Tree statement index key rather than the value associated with the key. |
SPOKeyOrder |
getKeyOrder(IPredicate<ISPO> predicate)
Implementation chooses a quads or triples index as appropriate.
|
Iterator<IKeyOrder<ISPO>> |
getKeyOrders()
Return the
IKeyOrder s corresponding to the registered indices for
this relation. |
IPredicate<ISPO> |
getPredicate(IV s,
IV p,
IV o,
IV c)
Return the predicate for a triple or quad pattern filter (core
implementation).
|
IPredicate<ISPO> |
getPredicate(IV s,
IV p,
IV o,
IV c,
IElementFilter<ISPO> filter,
RangeBOp range)
Return the predicate for a triple or quad pattern with an optional
filter (core implementation).
|
IIndex |
getPrimaryIndex() |
SPOKeyOrder |
getPrimaryKeyOrder()
Return the
IKeyOrder for the primary index for the relation. |
BTree |
getSPOOnlyBTree(boolean bloomFilter)
Deprecated.
Comment out when we drop the
DistinctSPOIterator . |
boolean |
getStatementIdentifiers()
When
true the database will support statement identifiers. |
protected IndexMetadata |
getStatementIndexMetadata(SPOKeyOrder keyOrder)
Overrides for the statement indices.
|
boolean |
indicesHaveDeleteMarkers()
Checks whether one of the associated triple indices uses delete markers.
|
long |
insert(IChunkedOrderedIterator<ISPO> itr)
Inserts
SPO s, writing on the statement indices in parallel. |
long |
insert(ISPO[] a,
int numStmts,
IElementFilter<ISPO> filter)
Inserts
SPO s, writing on the statement indices in parallel. |
IAccessPath<ISPO> |
newAccessPath(IIndexManager localIndexManager,
IPredicate<ISPO> predicate,
IKeyOrder<ISPO> keyOrder)
IAccessPath factory. |
SPO |
newElement(List<BOp> a,
IBindingSet bindingSet)
Create and return a new element.
|
Iterator<SPOKeyOrder> |
statementKeyOrderIterator()
Return an iterator visiting each
IKeyOrder maintained by this
relation. |
getAccessPath, getAccessPath, getAccessPath, getFQN, getFQN, getFQN, getIndex, getIndex, newIndexMetadata
acquireExclusiveLock, assertWritable, getBareProperties, getChunkCapacity, getChunkOfChunksCapacity, getChunkTimeout, getCommitTime, getContainerNamespace, getExecutorService, getFullyBufferedReadThreshold, getIndexManager, getMaxParallelSubqueries, getNamespace, getProperties, getProperty, getProperty, getTimestamp, init, isForceSerialExecution, isReadOnly, toString, unlock
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getExecutorService, getIndexManager
getContainerNamespace, getNamespace, getTimestamp, init
protected static final transient org.apache.log4j.Logger log
public static final String NAME_SPO_RELATION
SPORelation
namespace component.
Note: To obtain the fully qualified name of an index in the
SPORelation
you need to append a "." to the relation's namespace,
then this constant, then a "." and then the local name of the index.
public final boolean justify
public final boolean oneAccessPath
protected final boolean bloomFilter
true
iff the SPO index will maintain a bloom filter.Options#BLOOM_FILTER
public static final transient String NAME_HISTORY
public SPORelation(IIndexManager indexManager, String namespace, Long timestamp, Properties properties)
public SPORelation(AbstractTripleStore container, IIndexManager indexManager, String namespace, Long timestamp, Properties properties)
public int getKeyArity()
3
is a
triple store, with or without statement identifiers; 4
is a
quad store, which does not support statement identifiers as the 4th
position of the (s,p,o,c) is interpreted as context and located in the
B+Tree statement index key rather than the value associated with the key.public boolean getStatementIdentifiers()
true
the database will support statement identifiers.
A statement identifier is a unique 64-bit integer taken from the same space as the term identifiers and which uniquely identifiers a statement in the database regardless of the graph in which that statement appears. The purpose of statement identifiers is to allow statements about statements without recourse to RDF style reification.
Only explicit statements will have a statement identifier. Statements made about statements using their statement identifiers will automatically be retracted if a statement they describe is retracted (a micro form of truth maintenance that is always enabled when statement identifiers are enabled).
public AbstractTripleStore getContainer()
getContainer
in class AbstractResource<IRelation<ISPO>>
null
if there is no container.public boolean exists()
public void create()
IMutableResource
ILocatableResource.init()
is suitable for invocation from
IMutableResource.create()
. Instead, you are responsible for invoking ILocatableResource.init()
from this method IFF it is appropriate to reuse its initialization logic.create
in interface IMutableResource<IRelation<ISPO>>
create
in class AbstractResource<IRelation<ISPO>>
public void destroy()
IMutableResource
destroy
in interface IMutableResource<IRelation<ISPO>>
destroy
in class AbstractResource<IRelation<ISPO>>
public IIndex getIndex(IKeyOrder<? extends ISPO> keyOrder)
ITx.UNISOLATED
AbstractTask
where the index was not
declared and hence can not be materialized.getIndex
in interface IRelation<ISPO>
getIndex
in class AbstractRelation<ISPO>
keyOrder
- The natural index order.null
iff the index does not exist as
of the timestamp for this view of the relation.AbstractRelation.getIndex(String)
public final SPOKeyOrder getPrimaryKeyOrder()
IRelation
IKeyOrder
for the primary index for the relation.public final IIndex getPrimaryIndex()
public final IIndex getJustificationIndex()
Justification
s are stored.public ICloseableIterator<ISPO> distinctSPOIterator(ICloseableIterator<ISPO> src)
ISPO
s. The iterator will be backed by a
BTree
on a TemporaryStore
and will use a bloom filter for
fast point tests. The BTree
and the source iterator will be
closed when the returned iterator is closed.src
- The source iterator.public BTree getSPOOnlyBTree(boolean bloomFilter)
DistinctSPOIterator
.BTree
instance for the
SPOKeyOrder.SPO
key order backed by a TemporaryStore
. The
index will only store (s,p,o) triples (not quads) and will not store
either the SID or StatementEnum
. This is a good choice when you
need to impose a "distinct" filter on (s,p,o) triples.bloomFilter
- When true
, a bloom filter is enabled for the
index. The bloom filter provides fast correct rejection tests
for point lookups up to ~2M triples and then shuts off
automatically. See BloomFilterFactory.DEFAULT
for more
details.protected IndexMetadata getStatementIndexMetadata(SPOKeyOrder keyOrder)
protected IndexMetadata getHistoryIndexMetadata(SPOKeyOrder keyOrder)
protected IndexMetadata getJustIndexMetadata(String name)
IRawTripleStore#getJustificationIndex()
.public Set<String> getIndexNames()
IRelation
public Iterator<IKeyOrder<ISPO>> getKeyOrders()
IRelation
IKeyOrder
s corresponding to the registered indices for
this relation. [rather than getIndexNames?]public Iterator<SPOKeyOrder> statementKeyOrderIterator()
IKeyOrder
maintained by this
relation.public IAccessPath<ISPO> getAccessPath(IV s, IV p, IV o)
getAccessPath(IV, IV, IV, IV)
s
- p
- o
- UnsupportedOperationException
- unless the getKeyArity()
is 3
.public IAccessPath<ISPO> getAccessPath(IV s, IV p, IV o, IV c)
public IAccessPath<ISPO> getAccessPath(IV s, IV p, IV o, IV c, RangeBOp range)
public IAccessPath<ISPO> getAccessPath(IV s, IV p, IV o, IV c, IElementFilter<ISPO> filter)
public IAccessPath<ISPO> getAccessPath(IV s, IV p, IV o, IV c, IElementFilter<ISPO> filter, RangeBOp range)
s
- The subject position (optional).p
- The predicate position (optional).o
- The object position (optional).c
- The context position (optional and ignored for a triple
store).filter
- The filter (optional).range
- The range (optional).UnsupportedOperationException
- for a triple store without statement identifiers if the
c is non-#NULL
.public IPredicate<ISPO> getPredicate(IV s, IV p, IV o, IV c)
s
- The subject position (optional).p
- The predicate position (optional).o
- The object position (optional).c
- The context position (optional and ignored for a triple
store).UnsupportedOperationException
- for a triple store without statement identifiers if the
c is non-#NULL
.public IPredicate<ISPO> getPredicate(IV s, IV p, IV o, IV c, IElementFilter<ISPO> filter, RangeBOp range)
s
- The subject position (optional).p
- The predicate position (optional).o
- The object position (optional).c
- The context position (optional and ignored for a triple
store).filter
- The filter (optional).range
- The range (optional).UnsupportedOperationException
- for a triple store without statement identifiers if the
c is non-#NULL
.public SPOKeyOrder getKeyOrder(IPredicate<ISPO> predicate)
Return the IKeyOrder
for the predicate corresponding to the
perfect access path. A perfect access path is one where the bound values
in the predicate form a prefix in the key space of the corresponding
index.
IKeyOrder
for the perfect access path -or-
null
if there is no index which provides a perfect
access path for that predicate.public IAccessPath<ISPO> newAccessPath(IIndexManager localIndexManager, IPredicate<ISPO> predicate, IKeyOrder<ISPO> keyOrder)
AbstractRelation
IAccessPath
factory.newAccessPath
in class AbstractRelation<ISPO>
localIndexManager
- The local index manager (optional, except when there is a
request for a shard local access path in scale-out).predicate
- The predicate used to request the access path.keyOrder
- The index which the access path will use.public IChunkedIterator<IV> distinctTermScan(IKeyOrder<ISPO> keyOrder)
IKeyOrder
. For example, using SPOKeyOrder.POS
will give you the term identifiers for the distinct predicates actually
in use within statements in the SPORelation
.keyOrder
- The selected index order.public IChunkedIterator<IV> distinctTermScan(IKeyOrder<ISPO> keyOrder, ITermIVFilter filter)
IKeyOrder
. For example, using SPOKeyOrder.POS
will give you the term identifiers for the distinct predicates actually
in use within statements in the SPORelation
.keyOrder
- The selected index order.filter
- An optional filter on the visited IV
s.public IChunkedIterator<IV> distinctTermScan(IKeyOrder<ISPO> keyOrder, byte[] fromKey, byte[] toKey, ITermIVFilter termIdFilter)
IKeyOrder
. For example, using SPOKeyOrder.POS
will give you the term identifiers for the distinct predicates actually
in use within statements in the SPORelation
.keyOrder
- The selected index order.fromKey
- The first key for the scan -or- null
to start the
scan at the head of the index.toKey
- The last key (exclusive upper bound) for the scan -or-
null
to scan until the end of the index.termIdFilter
- An optional filter on the visited IV
s.public IChunkedIterator<IV> distinctMultiTermScan(IKeyOrder<ISPO> keyOrder, IV[] knownTerms)
IKeyOrder
. For example, using SPOKeyOrder.POS
will give you the term identifiers for the distinct predicates actually
in use within statements in the SPORelation
.keyOrder
- The selected index order.public IChunkedIterator<IV> distinctMultiTermScan(IKeyOrder<ISPO> keyOrder, IV[] knownTerms, ITermIVFilter termIdFilter)
IKeyOrder
. For example, using SPOKeyOrder.POS
will give you the term identifiers for the distinct predicates actually
in use within statements in the SPORelation
.keyOrder
- The selected index order.knownTerms
- An array of term identifiers to be interpreted as bindings
using the keyOrder.termIdFilter
- An optional filter.public SPO newElement(List<BOp> a, IBindingSet bindingSet)
IRelation
a
- An ordered list of variables and/or constants.bindingSet
- A set of bindings.public Class<ISPO> getElementClass()
IRelation
public long insert(IChunkedOrderedIterator<ISPO> itr)
SPO
s, writing on the statement indices in parallel.
Note: This does NOT write on the justifications index. If justifications
are being maintained then the ISolution
s MUST report binding
sets and an AbstractSolutionBuffer.InsertSolutionBuffer
MUST be used that knows how to
write on the justifications index AND delegate writes on the statement
indices to this method.
Note: This does NOT assign statement identifiers. The SPORelation
does not have direct access to the LexiconRelation
and the latter
is responsible for assigning term identifiers. Code that writes explicit
statements onto the statement indices MUST use
AbstractTripleStore.addStatements(AbstractTripleStore, boolean, IChunkedOrderedIterator, IElementFilter)
,
which knows how to generate the statement identifiers. In turn, that
method will delegate each "chunk" to this method.
itr
- An iterator visiting the elements to be written.public long delete(IChunkedOrderedIterator<ISPO> itr)
SPO
s, writing on the statement indices in parallel.
Note: The ISPO.isModified()
flag is set by this method.
Note: This does NOT write on the justifications index. If justifications
are being maintained then the ISolution
s MUST report binding sets
and an AbstractSolutionBuffer.InsertSolutionBuffer
MUST be used that knows how to write
on the justifications index AND delegate writes on the statement indices
to this method.
Note: This does NOT perform truth maintenance!
Note: This does NOT compute the closure for statement identifiers (statements that need to be deleted because they are about a statement that is being deleted).
itr
- An iterator visiting the elements to be removed. Existing
elements in the relation having a key equal to the key formed
from the visited elements will be removed from the relation.AbstractTripleStore.removeStatements(IChunkedOrderedIterator,
boolean)
,
SPOAccessPath.removeAll()
public long insert(ISPO[] a, int numStmts, IElementFilter<ISPO> filter)
SPO
s, writing on the statement indices in parallel.
Note: The ISPO.isModified()
flag is set by this method.
Note: This does NOT write on the justifications index. If justifications
are being maintained then the ISolution
s MUST report binding sets
and an AbstractSolutionBuffer.InsertSolutionBuffer
MUST be used that knows how to write
on the justifications index AND delegate writes on the statement indices
to this method.
Note: This does NOT perform truth maintenance!
Note: This does NOT compute the closure for statement identifiers (statements that need to be deleted because they are about a statement that is being deleted). Note: The statements are inserted into each index in parallel. We clone the statement[] and sort and bulk load each statement index in parallel using a thread pool. All mutation to the statement indices goes through this method.
a
- An ISPO
[] of the statements to be written onto the
statement indices. For each ISPO
, the
ISPO.isModified()
flag will be set iff the tuple
corresponding to the statement was : (a) inserted; (b) updated
(state change, such as to the StatementEnum
value), or
(c) removed.numStmts
- The #of elements of that array that will be written.filter
- An optional filter on the elements to be written.public long delete(ISPO[] stmts, int numStmts)
SPO
s from the statement indices. Any justifications
for those statements will also be deleted. The ISPO.isModified()
flag is set by this method if the ISPO
was pre-existing in the
database and was therefore deleted by this operation.stmts
- The SPO
s.numStmts
- The #of elements in that array to be processed.public long addJustifications(IChunkedIterator<Justification> itr)
itr
- The iterator from which we will read the Justification
s
to be added. The iterator is closed by this operation.Justification
s written on the justifications
index.public StringBuilder dump(IKeyOrder<ISPO> keyOrder)
public boolean indicesHaveDeleteMarkers()
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.