/** * @return PropertyIsLessThan * @throws CQLException */ public PropertyIsLessThan buildLess() throws CQLException { Expression right = this.resultStack.popExpression(); Expression left = this.resultStack.popExpression(); return filterFactory.less(left, right); }
private Filter toLessFilter(FilterFactory ff, Expression variable, Range<T> range) { if (range.isMaxIncluded()) { return ff.lessOrEqual(variable, ff.literal(range.getMaxValue())); } else { return ff.less(variable, ff.literal(range.getMaxValue())); } }
public void testRangeExpression() throws Exception { SimpleFeatureType schema = DataUtilities.createType("test", "pop:String"); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setRangeSimplicationEnabled(true); visitor.setFeatureType(schema); Function func = ff.function("parseLong", ff.property("pop")); Filter f1 = ff.less(func, ff.literal(20000)); Filter f2 = ff.between(func, ff.literal(20000), ff.literal(50000)); Filter or = ff.or(f1, f2); Filter simplified = (Filter) or.accept(visitor, null); assertEquals(ff.lessOrEqual(func, ff.literal(50000)), simplified); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { Expression e1 = (Expression) node.getChildValue(0); Expression e2 = (Expression) node.getChildValue(1); return filterfactory.less(e1, e2); } }
public void testSimplifyStaticExclude() { assertEquals(Filter.EXCLUDE, simplify(ff.greater(ff.literal(3), ff.literal(5)))); assertEquals(Filter.EXCLUDE, simplify(ff.greaterOrEqual(ff.literal(3), ff.literal(5)))); assertEquals(Filter.EXCLUDE, simplify(ff.less(ff.literal(5), ff.literal(3)))); assertEquals(Filter.EXCLUDE, simplify(ff.lessOrEqual(ff.literal(5), ff.literal(3)))); assertEquals(Filter.EXCLUDE, simplify(ff.equal(ff.literal(5), ff.literal(3), true))); assertEquals( Filter.EXCLUDE, simplify(ff.between(ff.literal(3), ff.literal(1), ff.literal(2)))); }
/** * @return PropertyIsLessThan * @throws CQLException */ public PropertyIsLessThan buildPropertyIsLTFirsDate() throws CQLException { PeriodNode period = this.resultStack.popPeriodNode(); org.opengis.filter.expression.Literal date = period.getBeginning(); org.opengis.filter.expression.Expression property = this.resultStack.popExpression(); PropertyIsLessThan filter = filterFactory.less(property, date); return filter; }
public void testSimplifyStaticInclude() { assertEquals(Filter.INCLUDE, simplify(ff.less(ff.literal(3), ff.literal(5)))); assertEquals(Filter.INCLUDE, simplify(ff.lessOrEqual(ff.literal(3), ff.literal(5)))); assertEquals(Filter.INCLUDE, simplify(ff.greater(ff.literal(5), ff.literal(3)))); assertEquals(Filter.INCLUDE, simplify(ff.greaterOrEqual(ff.literal(5), ff.literal(3)))); assertEquals(Filter.INCLUDE, simplify(ff.equal(ff.literal(5), ff.literal(5), true))); assertEquals( Filter.INCLUDE, simplify(ff.between(ff.literal(3), ff.literal(1), ff.literal(4)))); }
public void testInWithLessThan() throws FilterToSQLException { FilterToSQL encoder = new FilterToSQL(output); Function function = buildInFunction("in", new Object[] {1, 2}); Filter filter = filterFac.less(function, filterFac.literal(true)); encoder.encode(filter); // weird but legit, at least in some databases assertEquals("WHERE (testAttr IN (1, 2)) < true", output.getBuffer().toString()); }
private SimpleFeatureSource getView() throws IllegalFilterException, IOException, SchemaException { FilterFactory fac = CommonFactoryFinder.getFilterFactory(null); Filter f = fac.less(fac.property("id"), fac.literal(3)); SimpleFeatureSource view = DataUtilities.createView(fs, new Query(typeName, f)); return view; } }
public void testCoalesheNestedOr() { Filter eq = ff.equal(ff.property("A"), ff.literal("3"), true); Filter gt = ff.greater(ff.property("b"), ff.literal("3")); Filter lt = ff.less(ff.property("c"), ff.literal("5")); Or nested = ff.or(Arrays.asList(ff.or(Arrays.asList(eq, gt)), lt)); Or simplified = (Or) nested.accept(simpleVisitor, null); assertEquals(3, simplified.getChildren().size()); assertEquals(ff.or(Arrays.asList(eq, gt, lt)), simplified); }
public void testCoalesheNestedAnd() { Filter eq = ff.equal(ff.property("A"), ff.literal("3"), true); Filter gt = ff.greater(ff.property("b"), ff.literal("3")); Filter lt = ff.less(ff.property("c"), ff.literal("5")); And nested = ff.and(Arrays.asList(ff.and(Arrays.asList(eq, gt)), lt)); And simplified = (And) nested.accept(simpleVisitor, null); assertEquals(3, simplified.getChildren().size()); assertEquals(ff.and(Arrays.asList(eq, gt, lt)), simplified); }
public void testNegateBetween() { PropertyName prop = ff.property("prop"); Literal l10 = ff.literal(10); Literal l20 = ff.literal(20); Filter f = ff.not(ff.between(prop, l10, l20)); Filter result = (Filter) f.accept(simpleVisitor, null); assertEquals( ff.or(Arrays.asList((Filter) ff.less(prop, l10), ff.greater(prop, l20))), result); }
private <T> void testOrDisjointRanges(Class<T> type, T max, T min) throws Exception { SimpleFeatureType schema = DataUtilities.createType("test", "a:" + type.getName()); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setFeatureType(schema); Filter original = ff.or( ff.greater(ff.property("a"), ff.literal(max)), ff.less(ff.property("a"), ff.literal(min))); Filter simplified = (Filter) original.accept(visitor, null); assertEquals(original, simplified); }
public void testNegateGreaterOrEqual() { Filter f = ff.not(ff.greaterOrEqual(ff.property("prop"), ff.literal(10))); Filter result = (Filter) f.accept(simpleVisitor, null); assertEquals(ff.less(ff.property("prop"), ff.literal(10)), result); // not simplified for complex features result = (Filter) f.accept(complexVisitor, null); assertEquals(f, result); }
public void testNegateLess() { Filter f = ff.not(ff.less(ff.property("prop"), ff.literal(10))); Filter result = (Filter) f.accept(simpleVisitor, null); assertEquals(ff.greaterOrEqual(ff.property("prop"), ff.literal(10)), result); // not simplified for complex features result = (Filter) f.accept(complexVisitor, null); assertEquals(f, result); }
private <T> void testAndDisjointRanges(Class<T> type, T max, T min) throws Exception { SimpleFeatureType schema = DataUtilities.createType("test", "a:" + type.getName()); SimplifyingFilterVisitor visitor = new SimplifyingFilterVisitor(); visitor.setRangeSimplicationEnabled(true); Filter original = ff.and( ff.greater(ff.property("a"), ff.literal(max)), ff.less(ff.property("a"), ff.literal(min))); Filter simplified = (Filter) original.accept(visitor, null); assertEquals(original, simplified); visitor.setFeatureType(schema); Filter simplified2 = (Filter) original.accept(visitor, null); assertEquals(Filter.EXCLUDE, simplified2); }
public void testNegateOr() throws Exception { // not(a > 3 or b = 5 or c < 0) Filter fa = ff.greater(ff.property(aname(A)), ff.literal(3)); Filter fb = ff.equal(ff.property(aname(B)), ff.literal(5), false); Filter fc = ff.less(ff.property(aname(C)), ff.literal(0)); Not filter = ff.not(ff.and(Arrays.asList(fa, fb, fc))); ContentFeatureSource fs = dataStore.getFeatureSource(tname(ABC)); Query q = new Query(tname(ABC), filter); int count = fs.getCount(q); assertEquals(2, count); }
public void testSumWithFilter() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyName p = ff.property(aname("doubleProperty")); SumVisitor v = new MySumVisitor(p); Filter f = ff.less(ff.property(aname("doubleProperty")), ff.literal(2)); Query q = new Query(tname("ft1"), f); dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null); assertFalse(visited); assertEquals(1.1, v.getResult().toDouble(), 0.01); }
public void testMaxWithFilter() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyName p = ff.property(aname("doubleProperty")); MaxVisitor v = new MyMaxVisitor(p); Filter f = ff.less(ff.property(aname("doubleProperty")), ff.literal(2)); Query q = new Query(tname("ft1"), f); dataStore.getFeatureSource(tname("ft1")).accepts(q, v, null); assertFalse(visited); assertEquals(1.1, v.getResult().toDouble(), 0.01); }
@Test public void testCustomLengthExpressions() { AttributeTypeBuilder builder = new AttributeTypeBuilder(); FilterFactory ff = CommonFactoryFinder.getFilterFactory(null); Function length = ff.function("LengthFunction", new Expression[] {ff.property(".")}); // strict less builder.addRestriction(ff.less(length, ff.literal(20))); builder.setBinding(String.class); AttributeDescriptor attribute = builder.buildDescriptor("attribute"); assertEquals(19, FeatureTypes.getFieldLength(attribute)); // flip expression builder.addRestriction(ff.greater(ff.literal(20), length)); builder.setBinding(String.class); attribute = builder.buildDescriptor("attribute"); assertEquals(19, FeatureTypes.getFieldLength(attribute)); }