Refine search
/** * 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 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; }
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; }
protected boolean isConstant(Expression ex) { // quick common cases first if (ex instanceof Literal) { return true; } else if (ex instanceof PropertyName) { return false; } // ok, check for attribute dependencies and volatile functions then attributeExtractor.clear(); ex.accept(attributeExtractor, null); return attributeExtractor.isConstantExpression(); }
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; } } } }
private boolean isStatic(Expression exp) { FilterAttributeExtractor attributeExtractor = new FilterAttributeExtractor(); exp.accept(attributeExtractor, null); return attributeExtractor.getAttributeNameSet().isEmpty(); }
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()); } /**
query = new JoiningQuery(query); if (hasIdColumn) { FilterAttributeExtractor extractor = new FilterAttributeExtractor(); mapping.getFeatureIdExpression().accept(extractor, null); for (String pn : extractor.getAttributeNameSet()) { ((JoiningQuery) query).addId(pn); IsListFilterVisitor listChecker = new IsListFilterVisitor(listMappings, mapping); Filter complexFilter = query.getFilter(); complexFilter.accept(listChecker, null); if (listChecker.isListFilterExists()) { isListFilter = AppSchemaDataAccess.unrollFilter(complexFilter, mapping); ComplexFilterSplitter splitter = new ComplexFilterSplitter(capabilities, mapping); Filter filter = query.getFilter(); filter.accept(splitter, null); Filter preFilter = splitter.getFilterPre(); query.setFilter(preFilter);
/** * 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 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; }
SimpleFeatureType getReadSchema(Query q) { if (q.getPropertyNames() == Query.ALL_NAMES) { return getSchema(); } // Step 1: start with requested property names LinkedHashSet<String> attributes = new LinkedHashSet<String>(); attributes.addAll(Arrays.asList(q.getPropertyNames())); Filter filter = q.getFilter(); if (filter != null && !Filter.INCLUDE.equals(filter)) { // Step 2: Add query attributes (if needed) // Step 3: Fill empty XPath with appropriate property names FilterAttributeExtractor fat = new AbsoluteAttributeExtractor(getSchema()); filter.accept(fat, null); attributes.addAll(fat.getAttributeNameSet()); } return SimpleFeatureTypeBuilder.retype(getSchema(), new ArrayList<String>(attributes)); }
private void assertAttributeName(org.opengis.filter.Filter filter, String[] names) { fae.clear(); filter.accept(fae, null); Set<String> attNames = fae.getAttributeNameSet(); assertNotNull(attNames); assertEquals(attNames.size(), names.length); for (int i = 0; i < names.length; i++) { assertTrue(attNames.contains(names[i])); } // make sure the property name set is aligned Set<PropertyName> propNames = fae.getPropertyNameSet(); assertNotNull(propNames); assertEquals(attNames.size(), propNames.size()); for (PropertyName pn : propNames) { assertTrue(attNames.contains(pn.getPropertyName())); } }
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); } }
/** * 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); }
/** * Returns true if the last visited expression is a constant, that is, does not depend on any * attribute and does not use any {@link VolatileFunction} * * @return */ public boolean isConstantExpression() { return !usingVolatileFunctions && !usingDynamicProperties && getAttributeNameSet().isEmpty(); }
String lastValue = lastParameter.evaluate(null, String.class); FilterAttributeExtractor extractor = new FilterAttributeExtractor(); thresholds = new double[(parameters.size() - 1) / 2]; values = new Expression[thresholds.length + 1]; Expression expression = parameters.get(i); if (expression != null) { extractor.clear(); expression.accept(extractor, null); if (!extractor.isConstantExpression()) { staticTable = false; thresholds = null; } else { if (i % 2 == 0) { Double threshold = expression.evaluate(null, Double.class); if (threshold == null) { staticTable = false;
/** * 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()]); }
/** * 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. * </p> */ 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; }
protected boolean isConstant(Expression ex) { // quick common cases first if (ex instanceof Literal) { return true; } else if (ex instanceof NilExpression) { return true; } else if (ex instanceof PropertyName) { return false; } // ok, check for attribute dependencies and volatile functions then attributeExtractor.clear(); ex.accept(attributeExtractor, null); return attributeExtractor.isConstantExpression(); }