public class BOpUtility extends Object
Modifier and Type | Field and Description |
---|---|
static IBindingSet[] |
EMPTY_CHUNK
An empty
IBindingSet []. |
Constructor and Description |
---|
BOpUtility() |
Modifier and Type | Method and Description |
---|---|
static Iterator<BOp> |
annotationOpIterator(BOp op)
Visit all annotations which are
BOp s (non-recursive). |
static ICloseableIterator<IBindingSet[]> |
asIterator(IBindingSet[] bindingSets)
Wrap the solutions with an
ICloseableIterator . |
static IConstraint[] |
concat(IConstraint[] a,
IConstraint[] b)
Combine two arrays of constraints.
|
static long |
copy(Iterator<IBindingSet[]> source,
IBlockingBuffer<IBindingSet[]> sink,
IBlockingBuffer<IBindingSet[]> sink2,
IBindingSet mergeSolution,
IVariable<?>[] selectVars,
IConstraint[] constraints,
BOpStats stats)
Copy binding sets from the source to the sink(s).
|
static int |
countVarOccurrencesOutsideProjections(BOp op,
IVariable inputVar)
Counts the number of occurrences of a BOp inside another BOp.
|
static <T extends BOp> |
deepCopy(T op)
Deep copy.
|
static int |
getArgumentVariableCount(BOp op)
The #of arguments to this operation which are variables.
|
static Iterator<IVariable<?>> |
getArgumentVariables(BOp op)
Return the variables from the operator's arguments.
|
static Integer |
getEffectiveDefaultSink(BOp bop,
BOp p)
Return the effective default sink.
|
static Integer[] |
getEvaluationOrder(BOp op)
Return a list containing the evaluation order for the pipeline.
|
static Map<Integer,BOp> |
getIndex(BOp op)
|
static <C> C |
getOnly(BOp op,
Class<C> class1)
Return the sole instance of the specified class.
|
static BOp |
getParent(BOp root,
BOp op)
Return the parent of the operator in the operator tree (this does not
search the annotations, just the children).
|
static BOp |
getPipelineStart(BOp op)
Return the left-deep child of the operator.
|
static int[] |
getPredIds(IPredicate<?>[] path)
Return an ordered array of the bopIds associated with an ordered array of
predicates (aka a join path).
|
static Set<IVariable<?>> |
getSharedVars(BOp p,
BOp c)
Return the variable references shared by two operators.
|
static Iterator<IVariable<?>> |
getSpannedVariables(BOp op)
Return the distinct variables recursively using a pre-order traversal
present whether in the operator tree or on annotations attached to
operators.
|
static boolean |
isConsistent(IConstraint[] constraints,
IBindingSet bindingSet)
Check constraints.
|
static PipelineOp |
makeAggregateDistinct(PipelineOp subQuery)
Return a copy of the subquery in which each
IAggregate function
is a distinct instance. |
static Iterator<BOp> |
postOrderIterator(BOp op)
Post-order recursive visitation of the operator tree (arguments only, no
annotations).
|
static Iterator<BOp> |
postOrderIteratorWithAnnotations(BOp op)
Recursive post-order traversal of the operator tree with visitation of
all operator annotations.
|
static Iterator<BOp> |
preOrderIterator(BOp op)
Pre-order recursive visitation of the operator tree (arguments only, no
annotations).
|
static Iterator<BOp> |
preOrderIteratorWithAnnotations(BOp op)
Recursive pre-order traversal of the operator tree with visitation of all
operator annotations.
|
static IBindingSet[] |
toArray(Iterator<IBindingSet[]> itr,
BOpStats stats)
Combine chunks drawn from an iterator into a single chunk.
|
static IVariable[] |
toArray(Iterator<IVariable<?>> it)
Return an array containing the
IVariable s visited by the
iterator. |
static <C> List<C> |
toList(BOp op,
Class<C> clas)
Return a list containing references to all nodes of the given type
(recursive, including annotations).
|
static <T> List<T> |
toList(Iterator<T> it)
|
static String |
toString(BOp bop)
Pretty print a bop.
|
static String |
toString2(BOp bop) |
static <C> Iterator<C> |
visitAll(BOp op,
Class<C> clas)
Return an iterator visiting references to all nodes of the given type
(recursive, including annotations).
|
public static final IBindingSet[] EMPTY_CHUNK
IBindingSet
[].public static Iterator<BOp> preOrderIterator(BOp op)
public static Iterator<BOp> postOrderIterator(BOp op)
public static Iterator<BOp> annotationOpIterator(BOp op)
BOp
s (non-recursive).op
- An operator.BOp
annotations in an
arbitrary order.public static Iterator<BOp> preOrderIteratorWithAnnotations(BOp op)
BOp
s
are visited. Annotation BOp
s are also recursively visited with
the pre-order traversal.op
- An operator.public static Iterator<BOp> postOrderIteratorWithAnnotations(BOp op)
BOp
s are visited. Annotation BOp
s are also recursively
visited with the pre-order traversal.op
- An operator.public static Iterator<IVariable<?>> getSpannedVariables(BOp op)
Note: This will find variables within subqueries as well, which may not be what is intended.
StaticAnalysis#getSpannedVariables(BOp, Set), which will only report
the variables which are actually visible (variables not projected
from subqueries are not reported).
public static IVariable[] toArray(Iterator<IVariable<?>> it)
IVariable
s visited by the
iterator.it
- The iterator.public static <C> List<C> toList(BOp op, Class<C> clas)
Note: This may be used to work around concurrent modification errors since the returned list is structurally independent of the original operator tree.
op
- The root of the operator tree.clas
- The type of the node to be extracted.visitAll(BOp, Class)
public static <C> C getOnly(BOp op, Class<C> class1)
op
- The root of the traversal.class1
- The class to look for.NoSuchElementException
- if there is no such instance.RuntimeException
- if there is more than one such instance.public static <C> Iterator<C> visitAll(BOp op, Class<C> clas)
op
- The root of the operator tree.clas
- The type of the node to be extracted.toList(BOp, Class)
public static Iterator<IVariable<?>> getArgumentVariables(BOp op)
op
- The operator.IVariable
arguments.public static int getArgumentVariableCount(BOp op)
IConstraint
, etc.public static Map<Integer,BOp> getIndex(BOp op)
BOp.Annotations.BOP_ID
to the
BOp
for each spanned PipelineOp
. BOp
s without
identifiers are not indexed. It is an error a non-PipelineOp
is
encountered.
BOp
s should form directed acyclic graphs, but this is not
strictly enforced. The recursive traversal iterators declared by this
class do not protect against loops in the operator tree. However,
getIndex(BOp)
detects and report loops based on duplicate
BOp.Annotations.BOP_ID
s -or- duplicate BOp
references.
op
- A BOp
.DuplicateBOpIdException
- if there are two or more BOp
s having the same
BOp.Annotations.BOP_ID
.BadBOpIdTypeException
- if the BOp.Annotations.BOP_ID
is not an Integer
.NoBOpIdException
- if a PipelineOp
does not have a
BOp.Annotations.BOP_ID
.NotPipelineOpException
- if op or any of its arguments visited during recursive
traversal are not a PipelineOp
.public static BOp getParent(BOp root, BOp op)
Note that Var
is a singleton pattern for each distinct variable
node, so there can be multiple parents for a Var
.
root
- The root of the operator tree (or at least a known ancestor of
the operator).op
- The operator.null
if op is not found in
the operator tree.IllegalArgumentException
- if either argument is null
.public static BOp getPipelineStart(BOp op)
Note: This does not protect against loops in the operator tree.
op
- The operator.IllegalArgumentException
- if the argument is null
.public static Integer getEffectiveDefaultSink(BOp bop, BOp p)
bop
- The operator.p
- The parent of that operator, if any.public static Integer[] getEvaluationOrder(BOp op)
BOpStats
objects when they are run as a
subquery. The evaluation order is given by the depth-first left-deep
traversal of the query.public static IBindingSet[] toArray(Iterator<IBindingSet[]> itr, BOpStats stats)
itr
- The iteratorstats
- BOpStats.chunksIn
and BOpStats.unitsIn
are
updated.public static ICloseableIterator<IBindingSet[]> asIterator(IBindingSet[] bindingSets)
ICloseableIterator
.bindingSets
- The solutions.ICloseableIterator
.public static String toString(BOp bop)
bop
- The bop.public static boolean isConsistent(IConstraint[] constraints, IBindingSet bindingSet)
constraints
- bindingSet
- true
iff the constraints are satisfied.public static long copy(Iterator<IBindingSet[]> source, IBlockingBuffer<IBindingSet[]> sink, IBlockingBuffer<IBindingSet[]> sink2, IBindingSet mergeSolution, IVariable<?>[] selectVars, IConstraint[] constraints, BOpStats stats)
Note: You MUST use IBlockingBuffer.flush()
to flush the sink(s)
in order for the last chunk in the sink(s) to be pushed to the downstream
operator for that sink. However, do NOT use flush() if the operator
evaluation fails since you do not want to push outputs from a failed
operator to downstream operators.
source
- The source.sink
- The sink (required).sink2
- Another sink (optional).mergeSolution
- A solution to be merged in with each solution copied from the
source (optional). When given, the selectVars
will be applied first to prune the copied solutions to just
the selected variables and any additional bindings will then
be added from the mergeSolution. This supports the
lexical scoping on variables within a subquery when that
subquery is being pipelined.selectVars
- The variables to be retained (optional). When not specified,
all variables will be retained.constraints
- Binding sets which fail these constraints will NOT be copied
(optional).stats
- The BOpStats.chunksIn
and BOpStats.unitsIn
will be updated during the copy (optional).public static int[] getPredIds(IPredicate<?>[] path)
path
- A join path.IllegalArgumentException
- if the argument is null
.IllegalArgumentException
- if any element of the argument is null
.IllegalStateException
- if any IPredicate
does not have a defined bopId as
reported by BOp.getId()
.public static Set<IVariable<?>> getSharedVars(BOp p, BOp c)
BOp
are considered, regardless of whether they
appear as operands or within annotations.p
- An operator.c
- Another operator.null
.IllegalArgumentException
- if the two either reference is null
.public static PipelineOp makeAggregateDistinct(PipelineOp subQuery)
IAggregate
function
is a distinct instance. This prevents inappropriate sharing of state
across invocations of the subquery.subQuery
- public static <T extends BOp> T deepCopy(T op)
public static IConstraint[] concat(IConstraint[] a, IConstraint[] b)
null
or
empty. If both were null
or empty, then a null
will be returned.a
- One set of constraints.b
- Another set of constraints.public static int countVarOccurrencesOutsideProjections(BOp op, IVariable inputVar)
op
- the BOp to scan for occurrences of innerinner
- the nested BOp we're looking forCopyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.