private boolean isStatic(Expression exp) { FilterAttributeExtractor attributeExtractor = new FilterAttributeExtractor(); exp.accept(attributeExtractor, null); return attributeExtractor.getAttributeNameSet().isEmpty(); }
/** * Uses FilterAttributeExtractor to return the list of all mentioned attribute names. * * <p>You can use this method to quickly build up the set of any mentioned attribute names. * * @param filter * @return Set of propertyNames */ public Set<String> attributeNames(Filter filter) { if (filter == null) { return Collections.emptySet(); } FilterAttributeExtractor extractor = new FilterAttributeExtractor(); filter.accept(extractor, new HashSet<String>()); return extractor.getAttributeNameSet(); }
/** * Traverses the expression and returns any encountered property names. * * <p>The feature type is supplied as contexts used to lookup expressions in cases where the * attributeName does not match the actual name of the type. */ public static Set<PropertyName> propertyNames( Expression expression, final SimpleFeatureType featureType) { if (expression == null) { return Collections.emptySet(); } FilterAttributeExtractor attExtractor = new FilterAttributeExtractor(featureType); expression.accept(attExtractor, null); Set<PropertyName> propertyNames = attExtractor.getPropertyNameSet(); return propertyNames; }
/** * Traverses the expression and returns any encountered property names. * * <p>The feature type is supplied as contexts used to lookup expressions in cases where the * attributeName does not match the actual name of the type. */ public static Set<PropertyName> propertyNames( Expression expression, final SimpleFeatureType featureType) { if (expression == null) { return Collections.emptySet(); } FilterAttributeExtractor attExtractor = new FilterAttributeExtractor(featureType); expression.accept(attExtractor, null); Set<PropertyName> propertyNames = attExtractor.getPropertyNameSet(); return propertyNames; }
/** * Traverses the filter and returns any encountered property names. * * <p>The feature type is supplied as contexts used to lookup expressions in cases where the * attributeName does not match the actual name of the type. */ public static Set<PropertyName> propertyNames( Filter filter, final SimpleFeatureType featureType) { if (filter == null) { return Collections.emptySet(); } FilterAttributeExtractor attExtractor = new FilterAttributeExtractor(featureType); filter.accept(attExtractor, null); Set<PropertyName> propertyNames = attExtractor.getPropertyNameSet(); return propertyNames; }
/** * Traverses the filter and returns any encountered property names. * * <p>The feature type is supplied as contexts used to lookup expressions in cases where the * attributeName does not match the actual name of the type. */ public static Set<PropertyName> propertyNames( Filter filter, final SimpleFeatureType featureType) { if (filter == null) { return Collections.emptySet(); } FilterAttributeExtractor attExtractor = new FilterAttributeExtractor(featureType); filter.accept(attExtractor, null); Set<PropertyName> propertyNames = attExtractor.getPropertyNameSet(); return propertyNames; }
private <T extends Filter> NestedAttributeExpression getNestedAttributeExpression(T filter) { FilterAttributeExtractor extractor = new FilterAttributeExtractor(); filter.accept(extractor, null); Set<PropertyName> propertyNames = extractor.getPropertyNameSet(); for (PropertyName property : propertyNames) { if (property instanceof NestedAttributeExpression) { return (NestedAttributeExpression) property; } } return null; }
/** * Traverses the filter and returns any encountered property names. * * <p>The feature type is supplied as contexts used to lookup expressions in cases where the * attributeName does not match the actual name of the type. */ public static String[] attributeNames(Filter filter, final SimpleFeatureType featureType) { if (filter == null) { return new String[0]; } FilterAttributeExtractor attExtractor = new FilterAttributeExtractor(featureType); filter.accept(attExtractor, null); String[] attributeNames = attExtractor.getAttributeNames(); return attributeNames; }
/** * Traverses the filter and returns any encountered property names. * * <p>The feature type is supplied as contexts used to lookup expressions in cases where the * attributeName does not match the actual name of the type. */ public static String[] attributeNames(Filter filter, final SimpleFeatureType featureType) { if (filter == null) { return new String[0]; } FilterAttributeExtractor attExtractor = new FilterAttributeExtractor(featureType); filter.accept(attExtractor, null); String[] attributeNames = attExtractor.getAttributeNames(); return attributeNames; }
public RecodeFunction(List<Expression> parameters, Literal fallback) { this.parameters = parameters; this.fallback = fallback; // check inputs if (parameters.size() % 2 != 1 && parameters.size() != 0) { throw new IllegalArgumentException( "There must be an equal number of lookup data and return values"); } // see if the table is full of attribute independent expressions FilterAttributeExtractor extractor = new FilterAttributeExtractor(); for (int i = 1; i < parameters.size(); i++) { Expression expression = parameters.get(i); if (expression != null) { extractor.clear(); expression.accept(extractor, null); if (!extractor.isConstantExpression()) { staticTable = false; break; } } } }
/** * Traverses the expression and returns any encountered property names. * * <p>The feature type is supplied as contexts used to lookup expressions in cases where the * attributeName does not match the actual name of the type. */ public static String[] attributeNames( Expression expression, final SimpleFeatureType featureType) { if (expression == null) { return new String[0]; } FilterAttributeExtractor attExtractor = new FilterAttributeExtractor(featureType); expression.accept(attExtractor, null); String[] attributeNames = attExtractor.getAttributeNames(); return attributeNames; }
/** * Returns all the JSON paths associated with the provided property name as property names, in * practice this method finds the source expression associated with the attribute mapping * matching the provided property name and extracts its JSON path converting it to a property * name. Since the source expression may use multiple attributes, multiple JSON paths may be * found. */ private List<PropertyName> extractJsonPaths( FeatureTypeMapping featureTypeMapping, PropertyName propertyName) { // get the expression of the mapping attribute matching the provided property name Expression expression = findPropertyExpression(featureTypeMapping, propertyName); if (expression == null) { // no attribute matches the provided property, let's move on return Collections.emptyList(); } // extracts all the properties from the attribute mapping expression FilterAttributeExtractor propertiesExtractor = new FilterAttributeExtractor(); expression.accept(propertiesExtractor, null); // convert all properties \ attributes to a property name return propertiesExtractor .getAttributeNameSet() .stream() .map(attributeName -> filterFactory.property(attributeName)) .collect(Collectors.toList()); }
SimpleFeatureType[] buildQueryAndReturnFeatureTypes( SimpleFeatureType featureType, String[] propertyNames, Filter filter) { SimpleFeatureType[] types = null; if (propertyNames == Query.ALL_NAMES) { return new SimpleFeatureType[] {featureType, featureType}; } else { SimpleFeatureType returnedSchema = SimpleFeatureTypeBuilder.retype(featureType, propertyNames); SimpleFeatureType querySchema = returnedSchema; if (filter != null && !filter.equals(Filter.INCLUDE)) { FilterAttributeExtractor extractor = new FilterAttributeExtractor(featureType); filter.accept(extractor, null); String[] extraAttributes = extractor.getAttributeNames(); if (extraAttributes != null && extraAttributes.length > 0) { List<String> allAttributes = new ArrayList<String>(Arrays.asList(propertyNames)); for (String extraAttribute : extraAttributes) { if (!allAttributes.contains(extraAttribute)) allAttributes.add(extraAttribute); } String[] allAttributeArray = allAttributes.toArray(new String[allAttributes.size()]); querySchema = SimpleFeatureTypeBuilder.retype(getSchema(), allAttributeArray); } } types = new SimpleFeatureType[] {querySchema, returnedSchema}; } return types; }
/** * Sets up a schema and a test feature. * * @throws SchemaException If there is a problem setting up the schema. */ protected void setUp() throws SchemaException { if (set) { return; } set = true; fae = new FilterAttributeExtractor(); fac = CommonFactoryFinder.getFilterFactory2(null); }
/** * Builds the list of original attributes required to run the specified query * * @param source * @param query * @return */ String[] getRequiredAttributes(Query query) { Set<String> attributes = new HashSet<String>(); FilterAttributeExtractor extractor = new FilterAttributeExtractor(); if (query.getPropertyNames() == Query.ALL_NAMES) { for (Expression ex : expressions.values()) { ex.accept(extractor, null); } } else { for (String name : query.getPropertyNames()) { Expression ex = expressions.get(name); ex.accept(extractor, null); } } attributes.addAll(extractor.getAttributeNameSet()); return attributes.toArray(new String[attributes.size()]); }
/** * A filter is considered <em>nested</em> if it operates on at least one nested attribute. * * <p>Technically, this means that at least one of the expressions in it is an instance of * {@link NestedAttributeExpression}. * * @param filter the filter to test * @return <code>true</code> if the filter involves at least one nested attribute, <code>false * </code> otherwise */ public static boolean isNestedFilter(Filter filter) { FilterAttributeExtractor extractor = new FilterAttributeExtractor(); filter.accept(extractor, null); return hasNestedAttributes(extractor.getPropertyNameSet()); }
public Object visit(org.opengis.filter.expression.Function expression, Object data) { if (expression instanceof VolatileFunction) { usingVolatileFunctions = true; } if (expression instanceof FilterFunction_property) { boolean foundLiteral = false; // dynamic property usage if (expression.getParameters() != null && expression.getParameters().size() > 0) { org.opengis.filter.expression.Expression firstParam = expression.getParameters().get(0); FilterAttributeExtractor secondary = new FilterAttributeExtractor(); firstParam.accept(secondary, null); if (secondary.isConstantExpression()) { String name = firstParam.evaluate(null, String.class); if (name != null) { attributeNames.add(name); propertyNames.add(FF.property(name)); foundLiteral = true; } } } if (!foundLiteral) { usingDynamicProperties = true; } } return super.visit(expression, data); };
/** * Returns true if the visitor is geometryless, that is, it's not accessing a geometry field in * the target schema * * @param visitor * @return */ public static boolean isGeometryless(FeatureVisitor visitor, SimpleFeatureType schema) { if (visitor instanceof FeatureAttributeVisitor) { // pass through unless one of the expressions requires the geometry attribute FilterAttributeExtractor extractor = new FilterAttributeExtractor(schema); for (Expression e : ((FeatureAttributeVisitor) visitor).getExpressions()) { e.accept(extractor, null); } for (PropertyName pname : extractor.getPropertyNameSet()) { AttributeDescriptor att = (AttributeDescriptor) pname.evaluate(schema); if (att instanceof GeometryDescriptor) { return false; } } return true; } else if (visitor instanceof CountVisitor) { return true; } return false; } }
public Object visit(org.opengis.filter.expression.Function function, Object extraData) { // can't optimize out volatile functions if (isVolatileFunction(function)) { return super.visit(function, extraData); } // stable function, is it using attributes? if (attributeExtractor == null) { attributeExtractor = new FilterAttributeExtractor(); } else { attributeExtractor.clear(); } function.accept(attributeExtractor, null); // if so we can replace it with a literal if (attributeExtractor.isConstantExpression()) { Object result = function.evaluate(null); return ff.literal(result); } else { return super.visit(function, extraData); } }
public void testPropertyNameSet() throws IllegalFilterException { Filter filter = fac.equals(fac.property("testString"), fac.literal("test string data")); Expression expression1 = fac.property("code"); Expression expression2 = fac.function("length", fac.property("identification")); FilterAttributeExtractor extract = new FilterAttributeExtractor(null); Set<String> names = new HashSet<String>(); // used to collect names from expression1, expression2, and filter expression1.accept(extract, names); expression2.accept(extract, names); filter.accept(extract, names); String array[] = extract.getAttributeNames(); Set<String> attributes = extract.getAttributeNameSet(); Set<PropertyName> properties = extract.getPropertyNameSet(); assertEquals(3, array.length); assertEquals(3, attributes.size()); assertEquals(3, properties.size()); } /**