public class BOpBase extends CoreBaseBOp
BOp
s. The BOpBase
class
is used for query evaluation operators. The copy-on-write contract provides a
safety margin during concurrent evaluation of query plans by ensuring that
all references are fully published.
Instances of this class are effectively immutable (mutation APIs always
return a deep copy of the operator to which the mutation has been applied),
Serializable
to facilitate distributed computing, and
Cloneable
to facilitate non-destructive tree rewrites.
BOp
s should define the following public constructors
public Class(BOp[] args, Map<String,Object> anns)
BOp
from the caller's data or when generated a query plan from Prolog. There are
some exceptions to this rule. For example, Constant
does not define a
shallow copy constructor because that would not provide a means to set the
constant's value.public Class(Class src)
BOp
, apply the mutation to the copy, and then return the copy. This
is the "effectively immutable" contract. Again, there are some exceptions.
For example, Var
provides a canonicalized mapping such that reference
tests may be used to determine if two Var
s are the same. In order to
support that contract it overrides Var.clone()
.BOp.Annotations
DEFAULT_INITIAL_CAPACITY
Constructor and Description |
---|
BOpBase(BOp[] args,
Map<String,Object> annotations)
Shallow copy constructor (required).
|
BOpBase(BOpBase op)
Deep copy constructor (required).
|
Modifier and Type | Method and Description |
---|---|
void |
__replaceArg(int index,
BOp newArg)
Effectively overwrites the specified argument with the provided value.
|
protected void |
_clearProperty(String name)
Clear an annotation.
|
protected void |
_set(int index,
BOp op)
Set the value of an operand.
|
protected Object |
_setProperty(String name,
Object value)
Set an annotation.
|
Map<String,Object> |
annotations()
The operator's annotations.
|
protected Map<String,Object> |
annotationsCopy()
A copy of the annotations.
|
protected boolean |
annotationsEqual(BOp o)
|
protected Map<String,Object> |
annotationsRef()
A reference to the actual annotations map object.
|
Iterator<BOp> |
argIterator()
An iterator visiting the operator's arguments.
|
List<BOp> |
args()
The operator's arguments as list.
|
protected BOp[] |
argsCopy()
A copy of the args[] array.
|
int |
arity()
The #of arguments to the operation.
|
BOp |
clearAnnotations(String[] names)
Strips off the named annotations.
|
BOpBase |
clearProperty(String name)
Clear the named annotation.
|
protected static BOp[] |
deepCopy(BOp[] a)
Deep copy the arguments.
|
protected static Map<String,Object> |
deepCopy(Map<String,Object> a)
Deep copy the annotations.
|
BOp |
get(int index)
Return an argument to the operation.
|
Object |
getProperty(String name)
Return the value of a named property.
|
BOpBase |
setArg(int index,
BOp newArg)
Return a new
BOpBase in which the child operand has been replaced
by the given expression. |
BOpBase |
setProperty(String name,
Object value)
Unconditionally sets the property.
|
BOpBase |
setUnboundProperty(String name,
Object value)
Conditionally sets the property.
|
BOp[] |
toArray()
A shallow copy of the operator's arguments.
|
<T> T[] |
toArray(T[] a)
A shallow copy of the operator's arguments using the generic type of the
caller's array.
|
annotationsEqual, annotationsToString, annotationsToString, annotationValueToString, checkArgs, clone, equals, getEvaluationContext, getId, getProperty, getRequiredProperty, hashCode, indent, isController, mutation, shortenName, toShortString, toString, toString
public BOpBase(BOpBase op)
Each BOp
MUST implement a public copy constructor with the
signature:
public Foo(Foo)This construct is invoked by
CoreBaseBOp.clone()
using reflection and is
responsible for the deep copy semantics for the BOp
.
The default implementation makes a deep copy of args()
and
annotations()
but DOES NOT perform field-by-field copying.
Subclasses may simply delegate the constructor to their super class
unless they have additional fields which need to be copied.
This design pattern was selected because it preserves the immutable
contract of the BOp
which gives us our thread safety and
visibility guarantees. Since the deep copy is realized by the BOp
implementation classes, it is important that each class take
responsibility for the deep copy semantics of any fields it may declare.
op
- A deep copy will be made of this BOp
.NullPointerException
- if the argument is null
.public final Map<String,Object> annotations()
BOp
protected boolean annotationsEqual(BOp o)
CoreBaseBOp
true
iff the annotations of this BOp
and the
other BOp
are equals.
Note: This method permits override by subclasses with direct access to the maps to be compared.
annotationsEqual
in class CoreBaseBOp
CoreBaseBOp.annotationsEqual(Map, Map)
protected final BOp[] argsCopy()
protected final Map<String,Object> annotationsRef()
BOpBase
instance is created so we can know
this locally by inspection of the code).public BOp get(int index)
BOp
index
- The argument index in [0:BOp.arity()
-1].protected final void _set(int index, BOp op)
Note: This is protected to facilitate copy-on-write patterns. It is not
public to prevent arbitrary changes to operators outside of methods which
clone the operator and return the modified version. This is part of the
effectively immutable contract for BOp
s.
index
- The index.op
- The operand.public BOpBase setArg(int index, BOp newArg)
BOpBase
in which the child operand has been replaced
by the given expression.index
- The index of the child expression to be replaced.newArg
- The new child expression.BOpBase
in which the child operand has
been replaced.public void __replaceArg(int index, BOp newArg)
WARNING: this method could break logic of the code, which relies on immutability of the arguments list. It is introduced while fixing issues with deferred IV resolution and intended to be used only before IV resolution completed. This method triggers mutation notification.
index
- The index of the child expression to be replaced.newArg
- The new child expression.(Date literals in complex FILTER not properly resolved)
public int arity()
BOp
public final List<BOp> args()
Note: This is much less efficient than argIterator()
.
public final Iterator<BOp> argIterator()
The iterator does not support removal. (This is more efficient than #args()).
public BOp[] toArray()
BOp
public <T> T[] toArray(T[] a)
BOp
null
is appended to mark the end of the data.protected static BOp[] deepCopy(BOp[] a)
Note: As long as we stick to the immutable semantics for bops, we can just make a shallow copy of the arguments in the "copy" constructor and then modify them within the specific operator constructor before returning control to the caller. This would result in less heap churn.
public Object getProperty(String name)
IPropertySet
name
- The property name.protected Object _setProperty(String name, Object value)
Note: This is protected to facilitate copy-on-write patterns. It is not
public to prevent arbitrary changes to operators outside of methods which
clone the operator and return the modified version. This is part of the
effectively immutable contract for BOp
s.
name
- The name.value
- The value.protected void _clearProperty(String name)
Note: This is protected to facilitate copy-on-write patterns. It is not
public to prevent arbitrary changes to operators outside of methods which
clone the operator and return the modified version. This is part of the
effectively immutable contract for BOp
s.
name
- The name.public BOpBase setProperty(String name, Object value)
BOp
name
- The name.value
- The value.BOp
on which the property has been set.public BOpBase setUnboundProperty(String name, Object value)
name
- The name.value
- The value.BOp
on which the property has been set.IllegalStateException
- if the property is already set.public BOpBase clearProperty(String name)
name
- The annotation.BOp
in which the named annotation has been
removed.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.