public class AccessPath<R> extends Object implements IAccessPath<R>, IBindingSetAccessPath<R>
IAccessPath
implementations.
Note: Filters should be specified when the IAccessPath
is constructed
so that they will be evaluated on the data service rather than materializing
the elements and then filtering them. This can be accomplished by adding the
filter as a constraint on the predicate when specifying the access path.
Modifier and Type | Field and Description |
---|---|
protected IFilter |
accessPathFilter
The filter derived from optional
IPredicate.Annotations#ACCESS_PATH_FILTER . |
protected int |
chunkCapacity |
protected int |
chunkOfChunksCapacity |
protected int |
flags
Iterator flags.
|
protected int |
fullyBufferedReadThreshold |
protected IFilter |
indexLocalFilter
The filter derived from optional
IPredicate.Annotations#INDEX_LOCAL_FILTER . |
protected IIndexManager |
indexManager
Access to the index, resource locator, executor service, etc.
|
protected IKeyOrder<R> |
keyOrder
Index order (the relation namespace plus the index order and the option
partitionId constraint on the predicate identify the index).
|
protected static org.apache.log4j.Logger |
log |
protected static int |
MAX_FULLY_BUFFERED_READ_LIMIT
The maximum limit that is allowed for a fully-buffered read.
|
protected IIndex |
ndx
The index.
|
protected IPredicate<R> |
predicate
Predicate (the resource name on the predicate is the relation namespace).
|
protected long |
timestamp
Timestamp of the view.
|
Constructor and Description |
---|
AccessPath(IRelation<R> relation,
IIndexManager localIndexManager,
IPredicate<R> predicate,
IKeyOrder<R> keyOrder) |
Modifier and Type | Method and Description |
---|---|
protected void |
assertInitialized() |
protected IChunkedOrderedIterator<R> |
asynchronousIterator(Iterator<R> src)
Asynchronous read using a
BlockingBuffer . |
ScanCostReport |
estimateCost()
Return an estimate of the cost of a scan on the predicate.
|
int |
getChunkCapacity() |
int |
getChunkOfChunksCapacity() |
byte[] |
getFromKey()
The key corresponding to the inclusive lower bound for the
IAccessPath null if there is no lower bound. |
IIndex |
getIndex()
The index selected for the access path.
|
IIndexManager |
getIndexManager() |
IKeyOrder<R> |
getKeyOrder()
The order in which the elements will be visited.
|
IPredicate<R> |
getPredicate()
The constraints on the
IAccessPath . |
IRelation<R> |
getRelation() |
long |
getTimestamp() |
byte[] |
getToKey()
The key corresponding to the exclusive upper bound for the
IAccessPath -or- null if there is no upper bound. |
boolean |
hasFilter()
true iff there is a filter for the access path (either local
or remote). |
AccessPath<R> |
init()
Required post-ctor initialization.
|
boolean |
isEmpty()
True iff the access path is empty (there are no matches for the
IPredicate ) This is more conclusive than #rangeCount()
since you MAY have a non-zero range count when the key range is in fact
empty (there may be "deleted" index entries within the key range). |
boolean |
isFullyBoundForKey()
true iff all elements in the predicate which are required
to generate the key are bound to constants. |
IChunkedOrderedIterator<R> |
iterator()
An iterator visiting elements using the natural order of the index
selected for the
IPredicate . |
IChunkedOrderedIterator<R> |
iterator(long offset,
long limit,
int capacity)
An iterator visiting elements using the natural order of the index
selected for the
IPredicate . |
long |
rangeCount(boolean exact)
Return the maximum #of elements spanned by the
IPredicate . |
protected ITupleIterator<R> |
rangeIterator(int capacity,
int flags,
IFilter filter) |
long |
removeAll()
This implementation removes all tuples that would be visited by the
access path from the backing index.
|
ICloseableIterator<IBindingSet[]> |
solutions(BOpContext context,
long limit,
BaseJoinStats stats)
Return an iterator which will visit the solutions drawn from the access
path with a limit on the number of solutions drawn.
|
protected IChunkedOrderedIterator<R> |
synchronousIterator(long offset,
long limit,
Iterator<R> src)
Fully buffers all elements that would be visited by the
IAccessPath iterator. |
String |
toString() |
protected static final org.apache.log4j.Logger log
protected final IIndexManager indexManager
protected final long timestamp
protected final IPredicate<R> predicate
protected final IKeyOrder<R> keyOrder
protected final IIndex ndx
protected final int flags
protected final int chunkOfChunksCapacity
protected final int chunkCapacity
protected final int fullyBufferedReadThreshold
protected static final int MAX_FULLY_BUFFERED_READ_LIMIT
asynchronousIterator(Iterator)
will always be used above this
limit.
FIXME Array limits in truth maintenance code. This should probably be
close to the branching factor or chunk capacity. It has been temporarily
raised to a very large value in order to support truth maintenance where
the code assumes access to the fully buffered result. That change needs
to be examined for an impact on query performance. It is effectively
forcing all access path reads to be fully buffered rather than using an
asynchronous iterator pattern.protected final IFilter indexLocalFilter
IPredicate.Annotations#INDEX_LOCAL_FILTER
. If there are shared
variables in the IPredicate
then a SameVariableConstraint
is added regardless of whether the IPredicate
specified a filter
or not.protected final IFilter accessPathFilter
IPredicate.Annotations#ACCESS_PATH_FILTER
.public AccessPath(IRelation<R> relation, IIndexManager localIndexManager, IPredicate<R> predicate, IKeyOrder<R> keyOrder)
relation
- The relation for the access path (optional). The
relation> is not specified when requested an
IAccessPath
for a specific index partition in order to
avoid forcing the materialization of the IRelation
.localIndexManager
- Access to the indices, resource locators, executor service,
etc.predicate
- The constraints on the access path.keyOrder
- The order in which the elements would be visited for this
access path.public final boolean hasFilter()
true
iff there is a filter for the access path (either local
or remote).public boolean isFullyBoundForKey()
true
iff all elements in the predicate which are required
to generate the key are bound to constants.public int getChunkCapacity()
AbstractResource.getChunkCapacity()
public int getChunkOfChunksCapacity()
public final byte[] getFromKey()
IAccessPath
null
if there is no lower bound.public final byte[] getToKey()
IAccessPath
-or- null
if there is no upper bound.public final IKeyOrder<R> getKeyOrder()
IAccessPath
getKeyOrder
in interface IAccessPath<R>
protected final void assertInitialized()
IllegalStateException
- unless init()
has been invoked.public AccessPath<R> init()
public IIndexManager getIndexManager()
public long getTimestamp()
public IPredicate<R> getPredicate()
IAbstractAccessPath
IAccessPath
.getPredicate
in interface IAbstractAccessPath<R>
public IIndex getIndex()
IAccessPath
Note: The access path may incorporate additional constraints from the
specified IPredicate
that are not present on the IIndex
returned by this method.
getIndex
in interface IAccessPath<R>
public boolean isEmpty()
IAbstractAccessPath
IPredicate
) This is more conclusive than #rangeCount()
since you MAY have a non-zero range count when the key range is in fact
empty (there may be "deleted" index entries within the key range).isEmpty
in interface IAbstractAccessPath<R>
public ICloseableIterator<IBindingSet[]> solutions(BOpContext context, long limit, BaseJoinStats stats)
solutions
in interface IBindingSetAccessPath<R>
limit
- The maximum #of solutions to visit.stats
- Some statistics are updated as solutions are visited.(Access path
should visit solutions for high level query).
public final IChunkedOrderedIterator<R> iterator()
IAccessPath
IPredicate
. This is equivalent to
iterator(0L, 0L, 0)since an offset of ZERO (0L) means no offset, a limit of ZERO (0L) means no limit and a capacity of ZERO (0) means whatever is the default capacity.
Note: Filters should be specified when the IAccessPath
is
constructed so that they will be evaluated on the IDataService
rather than materializing the elements and then filtering then. This can
be accomplished by adding the filter as an IElementFilter
on the
IPredicate
when requesting IAccessPath
.
iterator
in interface IAccessPath<R>
IRelation.getAccessPath(IPredicate)
public final IChunkedOrderedIterator<R> iterator(long offset, long limit, int capacity)
IAccessPath
IPredicate
.
The offset and limit together describe an optional
slice that will be visited by the iterator. When a slice is
specified, the iterator will count off the elements accepted by the
IPredicate
up to the offset, but not materialize them.
Elements by the IPredicate
starting with the offset and up
to (but not including) offset+limit will be materialized for the
client. The iterator will halt processing after observing
offset+limit accepted elements. Note that slices for JOINs (vs a
simple IAccessPath
scan) are handled by IQueryOptions
for
an IRule
.
The meaning of "accepted" is that: (a) the elements lie in the key-range
constraint implied by the IPredicate
; and (b) the elements pass
any optional constraints that the IPredicate
imposes.
iterator
in interface IAccessPath<R>
offset
- The first element accepted by the iterator that it will visit
(materialize for the client). The offset must be non-negative.
This is ZERO (0L) to visit all accepted elements.limit
- The last element accepted by the iterator that it will visit
(materialize for the client). The limit must be non-negative.
This is ZERO (0L) to visit all accepted elements (the value
Long.MAX_VALUE
is interpreted exactly like ZERO(0L)).capacity
- The maximum capacity for the buffer used by the iterator. When
ZERO(0), a default capacity will be used. When a limit
is specified, the capacity will never exceed the limit.IAccessPath
. This way they
will be correctly applied when IAbstractAccessPath.isEmpty()
is implemented
using the IAccessPath.iterator()
to determine if any elements can be
visited.RejectedExecutionException
- if the iterator is run asynchronously and the
ExecutorService
is shutdown or has a maximum capacity
and is saturated.
FIXME Support both offset and limit for asynchronous
iterators. right now this will force the use of the
synchronousIterator(long, long, Iterator)
when the
offset or limit are non-zero, but that is only permitted up
to a limit of MAX_FULLY_BUFFERED_READ_LIMIT
.
FIXME in order to support large limits we need to verify that
the asynchronous iterator can correctly handle REMOVEALL and
that incremental materialization up to the [limit] will not
effect the semantics for REMOVEALL or the other iterator
flags (per above). (In fact, the asynchronous iterator does
not support either [offset] or [limit] at this time).
FIXME write unit tests for slice handling by this method and
modify the SAIL integration to use it for SLICE on an
IAccessPath
scan. Note that there are several
IAccessPath
implementations and they all need to be
tested with SLICE.
Those tests should be located in
TestSPOAccessPath
.
FIXME The offset and limit should probably be rolled into the
predicate and removed from the IAccessPath
. This way
they will be correctly applied when isEmpty()
is
implemented using the iterator()
to determine if anyprotected final IChunkedOrderedIterator<R> synchronousIterator(long offset, long limit, Iterator<R> src)
IAccessPath
iterator.accessPath
- The access path (including the triple pattern).offset
- The first element that will be materialized (non-negative).limit
- The maximum #of elements that will be materialized (must be
positive, so use a range count before calling this method if
there was no limit specified by the caller).
FIXME pass the offset and limit into the source iterator and remove them
from this method's signature. This will require a change to the
IRangeQuery
API and ITupleIterator
impls.protected final IChunkedOrderedIterator<R> asynchronousIterator(Iterator<R> src)
BlockingBuffer
.src
- The source iterator.RejectedExecutionException
- if the ExecutorService
is shutdown or has a maximum
capacity and is saturated.public final long rangeCount(boolean exact)
IAbstractAccessPath
IPredicate
.
Note: When there is an IFilter
on the IPredicate
the
exact range count MUST apply that IFilter
, which means that it
will be required to traverse the index counting tuples which pass the
IFilter
. However, IFilter
s are ignored for the fast
range count.
rangeCount
in interface IAbstractAccessPath<R>
exact
- When true
, the result will be an exact count and
may require a key-range scan. When false
, the
result will be an upper bound IFF delete markers are
provisioned for the backing index (delete markers are required
for transactions and for scale-out indices).IRangeQuery
protected ITupleIterator<R> rangeIterator(int capacity, int flags, IFilter filter)
public long removeAll()
Note: If you are maintaining multiple indices then you MUST override this method to remove the data from each of those indices.
removeAll
in interface IAbstractAccessPath<R>
public ScanCostReport estimateCost()
pred
- The predicate.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.