public class CEConstraint
extends java.lang.Object
The constraint object is defined with respect to some underlying DMR. It defines a subset view over that DMR in that it specifies a set of declarations (variables, enums, dimensions, groups) to be included. For each such variable, the constraint specifies any overriding of the dimensions of the variables. Additionally, each variable (if appropriate) may have a filter expr.
Thus, there are three 'sub' constraints within a full constraint. 1. Referencing - is a variable from the underlying dataset included in the constraint, directly (by or indirectly: e.g. fields of a structure when only the structure is referenced 2. Projection - the actual values of a variable to be included in the constraint; this is specified by a triple [start:stride:stop] for each dimension of a variable. 3. Selection (aka filters) - A predicate over the scalar fields of a row of a Sequence; if it evaluates to true, then that row matches the constraint.
There are multiple ways to effect a constraint. 1. Generate and test mode: the constraint is asked if a given element matches the constraint. E.g. a. For referencing, one might ask the constraint if a given variable or field is in the constraint b. For a projection filter, one might ask the constraint if a given set of dimension indices match the projection. c. For a selection filter, one might ask the constraint if a given sequence row matches the filter predicate 2. Iteration mode: the constraint provides an iterator that returns the elements matching the constraint. E.g. a. For referencing, the iterator would return all the variables and fields referenced in the constraint. b. For a projection filter, the iterator would return the successive sets of indices of the projection, or it could return the actual matching value. c. For a selection filter, the iterator would return either the row indices or the actual rows of a sequence that matched the filter predicate
3. Read mode: Sometimes, it may be more efficient to let the DataVariable object handle the constraint more directly. E.g. a. For example, if the data variable was backed by a netcdf file, then passing in the complete projection might be more efficient than pulling values 1 by 1. b. Similarly, if the sequence object had an associated btree, then it would be more efficient to allow the sequence object to evaluate the filter using the btree. Note that this requires analysis of the filter expression to see if the btree is usable.
Ideally, we would allow all three modes, but for now, only generate-and-test is implemented, and only a subset of that. Generate-and-test is provided for referencing and selection. It is not provided for projection (for now) because it essentially requires the inverse of iteration and that is fairly tricky.
Modifier and Type | Class and Description |
---|---|
protected static class |
CEConstraint.Expand |
protected static class |
CEConstraint.Segment |
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<DapNode,java.util.List<DapAttribute>> |
attributes |
protected static boolean |
DEBUG |
protected java.util.List<DapDimension> |
dimrefs |
protected DapDataset |
dmr |
protected java.util.List<DapEnumeration> |
enums |
protected CEConstraint.Expand |
expansion |
protected boolean |
finished |
protected java.util.List<DapGroup> |
groups |
protected static boolean |
PARSEDEBUG |
protected java.util.Map<DapDimension,DapDimension> |
redef |
protected java.util.Map<DapDimension,Slice> |
redefslice |
protected java.util.List<DapDimension> |
refdims |
protected java.util.List<CEConstraint.Segment> |
segments
"Map" of variables (at all levels) to be included
Maps variables -> associated slices
and is modified by computdimensions().
|
protected static java.util.Map<DapDataset,CEConstraint> |
universals |
protected java.util.List<DapVariable> |
variables
Also keep a raw list of variables
|
Constructor and Description |
---|
CEConstraint() |
CEConstraint(DapDataset dmr) |
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(DapNode node,
DapAttribute attr) |
void |
addRedef(DapDimension dim,
Slice slice) |
void |
addVariable(DapVariable var,
java.util.List<Slice> slices) |
protected static int |
compare(java.lang.Object lvalue,
java.lang.Object rvalue) |
static CEConstraint |
compile(java.lang.String sce,
DapDataset dmr) |
protected void |
computedimensions()
Compute dimension related information
using slicing and redef info.
|
protected void |
computeenums()
Walk all the included variables and accumulate
the referenced enums
|
protected void |
computegroups()
Walk all the included declarations
and accumulate the set of referenced groups
|
void |
contract()
Locate each Structure|Sequence and:
1.
|
protected boolean |
contractR(DapStructure dstruct,
java.util.Set<DapStructure> contracted)
Recursive helper
|
protected void |
dumpvar(CEConstraint.Segment seg,
java.lang.StringBuilder buf,
boolean forconstraint)
Recursive helper for tostring/toConstraintString
|
protected java.lang.Object |
eval(DapVariable var,
DapSequence seq,
D4Array record,
CEAST expr)
Evaluate a filter with respect to a Sequence record.
|
void |
expand()
Locate each unexpanded Structure|Sequence and:
1.
|
protected int |
expansionCount(DapStructure struct)
Count the number of fields of a structure that
already in this view.
|
protected CEConstraint.Segment |
findSegment(DapVariable var) |
protected int |
findVariableIndex(DapVariable var) |
CEConstraint |
finish()
Finish creating this Constraint.
|
java.util.List<DapDimension> |
getConstrainedDimensions(DapVariable var) |
java.util.List<Slice> |
getConstrainedSlices(DapVariable var) |
DapDataset |
getDMR() |
DapDimension |
getRedefDim(DapDimension orig) |
static CEConstraint |
getUniversal(DapDataset dmr) |
boolean |
isUniversal() |
protected boolean |
isWholeCompound(DapStructure dstruct)
See if a structure is "whole", which
means that none of its fields is missing from the
constraint, all of fields use default (non-constrained)
dimension), and all of its fields are also whole.
|
boolean |
match(DapVariable sqvar,
DapSequence seq,
D4Array rec)
Selection X match
|
protected boolean |
matches(DapVariable var,
DapSequence seq,
D4Array rec,
CEAST filter)
Evaluate a filter with respect to a Sequence record.
|
boolean |
references(DapNode node)
Reference X match
|
static void |
release(DapDataset dmr) |
void |
setFilter(DapVariable var,
CEAST filter) |
java.lang.String |
toConstraintString()
Convert the view to a constraint string suitable
for use in a URL, except not URL encoded.
|
java.lang.String |
toString() |
protected static final boolean PARSEDEBUG
protected static final boolean DEBUG
protected static java.util.Map<DapDataset,CEConstraint> universals
protected DapDataset dmr
protected java.util.List<CEConstraint.Segment> segments
protected java.util.List<DapVariable> variables
protected java.util.Map<DapDimension,Slice> redefslice
protected java.util.Map<DapNode,java.util.List<DapAttribute>> attributes
protected java.util.Map<DapDimension,DapDimension> redef
protected java.util.List<DapDimension> dimrefs
protected java.util.List<DapEnumeration> enums
protected java.util.List<DapGroup> groups
protected java.util.List<DapDimension> refdims
protected boolean finished
protected CEConstraint.Expand expansion
public CEConstraint()
public CEConstraint(DapDataset dmr)
public static CEConstraint getUniversal(DapDataset dmr)
public static void release(DapDataset dmr)
protected static int compare(java.lang.Object lvalue, java.lang.Object rvalue) throws DapException
DapException
protected java.lang.Object eval(DapVariable var, DapSequence seq, D4Array record, CEAST expr) throws DapException
seq
- the templaterecord
- the record to evaluateexpr
- the filterDapException
public boolean isUniversal()
public DapDataset getDMR()
public DapDimension getRedefDim(DapDimension orig)
public void addRedef(DapDimension dim, Slice slice)
public void addVariable(DapVariable var, java.util.List<Slice> slices) throws DapException
DapException
public void addAttribute(DapNode node, DapAttribute attr)
public void setFilter(DapVariable var, CEAST filter)
public java.util.List<Slice> getConstrainedSlices(DapVariable var) throws DapException
DapException
public java.util.List<DapDimension> getConstrainedDimensions(DapVariable var)
public java.lang.String toString()
toString
in class java.lang.Object
public CEConstraint finish() throws DapException
DapException
public java.lang.String toConstraintString()
protected void dumpvar(CEConstraint.Segment seg, java.lang.StringBuilder buf, boolean forconstraint)
seg
- buf
- forconstraint
- public boolean references(DapNode node)
node
- to testpublic boolean match(DapVariable sqvar, DapSequence seq, D4Array rec) throws DapException
Evaluate a filter with respect to a Sequence record. Assumes the filter has been canonicalized.
seq
- the templaterec
- the record to evaluateDapException
protected boolean matches(DapVariable var, DapSequence seq, D4Array rec, CEAST filter) throws DapException
seq
- the templaterec
- the record to evaluatefilter
- the filterDapException
protected int findVariableIndex(DapVariable var)
protected CEConstraint.Segment findSegment(DapVariable var)
public void expand()
public void contract()
protected boolean contractR(DapStructure dstruct, java.util.Set<DapStructure> contracted)
dstruct
- to contractcontracted
- set of already contracted compoundsprotected int expansionCount(DapStructure struct)
struct
- the dapstructure to checkDapException
protected boolean isWholeCompound(DapStructure dstruct)
dstruct
- to testprotected void computedimensions() throws DapException
Assume that the constraint compiler has given us the following info:
Two products will be produced.
The processing is as follows
DapException
protected void computeenums()
protected void computegroups()
public static CEConstraint compile(java.lang.String sce, DapDataset dmr) throws DapException
DapException