Class SimplifyingFilterVisitor
- Object
-
- DuplicatingFilterVisitor
-
- SimplifyingFilterVisitor
-
- All Implemented Interfaces:
ExpressionVisitor
,FilterVisitor
public class SimplifyingFilterVisitor extends DuplicatingFilterVisitor
Takes a filter and returns a simplified, equivalent one. At the moment the filter:- simplifies out
Filter.INCLUDE
andFilter.EXCLUDE
in logical expressions - removes double logic negations
- deal with FID filter validation removing invalid fids
- optimize out all non volatile functions that do not happen to use attributes, replacing them with literals
FID filter validation is meant to wipe out non valid feature ids from
Id
filters. This is so in order to avoid sending feature ids down to DataStores that are not valid as per the specific FeatureType fid structure. Since this is structure is usually DataStore specific, some times being a strategy based on how the feature type primary key is generated, fid validation is abstracted out to theSimplifyingFilterVisitor.FIDValidator
interface so when a DataStore is about to send a query down to the backend it van provide this visitor with a validator specific for the feature type fid structure being queried.By default all feature ids are valid. DataStores that want non valid fids to be wiped out should set a
SimplifyingFilterVisitor.FIDValidator
through thesetFIDValidator(FIDValidator)
method.- Since:
- 2.5.x
- Author:
- Andrea Aime - OpenGeo, Gabriel Roldan (OpenGeo)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SimplifyingFilterVisitor.FIDValidator
Defines a simple means of assessing whether a feature id in anId
filter is structurally valid and hence can be send down to the backend with confidence it will not cause trouble, the most common one being filtering by pk number even if the type name prefix does not match.static class
SimplifyingFilterVisitor.RegExFIDValidator
A FID validator that matches the fids with a given regular expression to determine the fid's validity.static class
SimplifyingFilterVisitor.TypeNameDotNumberFidValidator
A convenient fid validator for the common case of a feature id being a composition of a<typename>.<number>
-
Field Summary
Fields Modifier and Type Field Description static SimplifyingFilterVisitor.FIDValidator
ANY_FID_VALID
A 'null-object' fid validator that assumes any feature id in anId
filter is validprotected FeatureType
featureType
-
Fields inherited from class DuplicatingFilterVisitor
ff
-
-
Constructor Summary
Constructors Constructor Description SimplifyingFilterVisitor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected List<Filter>
basicAndSimplification(List<Filter> filters)
protected List<Filter>
basicOrSimplification(List<Filter> filters)
protected <T extends BinaryLogicOperator>
List<Filter>collect(T filter, Class<T> type, Object extraData, List<Filter> collected)
protected List<Filter>
extraAndSimplification(Object extraData, List<Filter> filters)
protected List<Filter>
extraOrSimplification(Object extraData, List<Filter> filters)
protected boolean
isConstant(Expression ex)
boolean
isRangeSimplicationEnabled()
protected boolean
isSimpleFeature()
Returns true if the target feature type is a simple feature oneprotected boolean
isVolatileFunction(Function function)
Checks if a function is volatile in this context.void
setFeatureType(FeatureType featureType)
void
setFIDValidator(SimplifyingFilterVisitor.FIDValidator validator)
void
setRangeSimplicationEnabled(boolean rangeSimplicationEnabled)
Enables/disable range simplification.static Filter
simplify(Filter filter)
Tries to simplify the filter if it's not already a simple one.static Filter
simplify(Filter filter, FeatureType featureType)
Tries to simplify the filter if it's not already a simple oneObject
visit(And filter, Object extraData)
Object
visit(Add expression, Object extraData)
Object
visit(Divide expression, Object extraData)
Object
visit(Function function, Object extraData)
Object
visit(Multiply expression, Object extraData)
Object
visit(Subtract expression, Object extraData)
Object
visit(Id filter, Object extraData)
Uses the currentSimplifyingFilterVisitor.FIDValidator
to wipe out illegal feature ids from the returned filters.Object
visit(Not filter, Object extraData)
Object
visit(Or filter, Object extraData)
Object
visit(PropertyIsBetween filter, Object extraData)
Object
visit(PropertyIsEqualTo filter, Object extraData)
Object
visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData)
Object
visit(PropertyIsGreaterThan filter, Object extraData)
Object
visit(PropertyIsLessThanOrEqualTo filter, Object extraData)
Object
visit(PropertyIsLessThan filter, Object extraData)
Object
visit(PropertyIsLike filter, Object extraData)
Object
visit(PropertyIsNil filter, Object extraData)
Object
visit(PropertyIsNotEqualTo filter, Object extraData)
Object
visit(PropertyIsNull filter, Object extraData)
-
Methods inherited from class DuplicatingFilterVisitor
getFactory, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visitNullFilter
-
-
-
-
Field Detail
-
ANY_FID_VALID
public static final SimplifyingFilterVisitor.FIDValidator ANY_FID_VALID
A 'null-object' fid validator that assumes any feature id in anId
filter is valid
-
featureType
protected FeatureType featureType
-
-
Method Detail
-
setFIDValidator
public void setFIDValidator(SimplifyingFilterVisitor.FIDValidator validator)
-
setFeatureType
public void setFeatureType(FeatureType featureType)
-
visit
public Object visit(And filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
collect
protected <T extends BinaryLogicOperator> List<Filter> collect(T filter, Class<T> type, Object extraData, List<Filter> collected)
-
visit
public Object visit(Or filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
extraAndSimplification
protected List<Filter> extraAndSimplification(Object extraData, List<Filter> filters)
-
extraOrSimplification
protected List<Filter> extraOrSimplification(Object extraData, List<Filter> filters)
-
visit
public Object visit(Id filter, Object extraData)
Uses the currentSimplifyingFilterVisitor.FIDValidator
to wipe out illegal feature ids from the returned filters.- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
- Returns:
- a filter containing only valid fids as per the current
SimplifyingFilterVisitor.FIDValidator
, may beFilter.EXCLUDE
if none matches or the filter is already empty
-
visit
public Object visit(Not filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
isSimpleFeature
protected boolean isSimpleFeature()
Returns true if the target feature type is a simple feature one
-
visit
public Object visit(Function function, Object extraData)
- Specified by:
visit
in interfaceExpressionVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
isVolatileFunction
protected boolean isVolatileFunction(Function function)
Checks if a function is volatile in this context. By default it checks if the function implements theVolatileFunction
interface, subclasses can override
-
simplify
public static Filter simplify(Filter filter)
Tries to simplify the filter if it's not already a simple one.
-
simplify
public static Filter simplify(Filter filter, FeatureType featureType)
Tries to simplify the filter if it's not already a simple one
-
isConstant
protected boolean isConstant(Expression ex)
-
visit
public Object visit(PropertyIsBetween filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsEqualTo filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsNotEqualTo filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsGreaterThan filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsGreaterThanOrEqualTo filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsLessThan filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsLike filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsNil filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(PropertyIsNull filter, Object extraData)
- Specified by:
visit
in interfaceFilterVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(Add expression, Object extraData)
- Specified by:
visit
in interfaceExpressionVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(Divide expression, Object extraData)
- Specified by:
visit
in interfaceExpressionVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(Subtract expression, Object extraData)
- Specified by:
visit
in interfaceExpressionVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
visit
public Object visit(Multiply expression, Object extraData)
- Specified by:
visit
in interfaceExpressionVisitor
- Overrides:
visit
in classDuplicatingFilterVisitor
-
isRangeSimplicationEnabled
public boolean isRangeSimplicationEnabled()
-
setRangeSimplicationEnabled
public void setRangeSimplicationEnabled(boolean rangeSimplicationEnabled)
Enables/disable range simplification. Range simplification can figure out that the logic combination of multiple ranges against the same property can be turned into a single range, a INCLUDE, or a EXCLUDE, but it requires the range boundaries to be of the same type as the
-
-