public GroupByVisitorBuilder withGroupByAttributes( Collection<String> attributesNames, SimpleFeatureType type) { for (String attributeName : attributesNames) { withGroupByAttribute(attributeName, type); } return this; }
public GroupByVisitorBuilder withAggregateAttribute( int attributeTypeIndex, SimpleFeatureType type) { aggregateAttribute = toExpression(attributeTypeIndex, type); return this; }
private GroupByVisitor buildVisitor( String aggregateAttribute, String aggregateVisitor, String[] groupByAttributes) { GroupByVisitorBuilder visitorBuilder = new GroupByVisitorBuilder() .withAggregateAttribute(aggregateAttribute, buildingType) .withAggregateVisitor(aggregateVisitor); for (String groupByAttribute : groupByAttributes) { visitorBuilder.withGroupByAttribute(groupByAttribute, buildingType); } return visitorBuilder.build(); }
.map( function -> new GroupByVisitorBuilder() .withAggregateAttribute( function == AggregationFunction.SumArea ? factory.function( aggAttribute) .getLocalName())) .withAggregateVisitor(function.name()) .withGroupByAttributes( rawGroupByAttributes, features.getSchema()) .withProgressListener(progressListener) .build()) .collect(Collectors.toList());
private List<Object[]> genericGroupByTestTest( Query query, Aggregate aggregateVisitor, Expression aggregateAttribute, boolean expectOptimized, Expression... groupByAttributes) throws IOException { ContentFeatureSource featureSource = dataStore.getFeatureSource(tname("buildings_group_by_tests")); GroupByVisitorBuilder visitorBuilder = new GroupByVisitorBuilder() .withAggregateAttribute(aggregateAttribute) .withAggregateVisitor(aggregateVisitor); for (Expression groupByAttribute : groupByAttributes) { visitorBuilder.withGroupByAttribute(groupByAttribute); } GroupByVisitor visitor = visitorBuilder.build(); featureSource.accepts(query, visitor, null); assertEquals(expectOptimized, visitor.wasOptimized()); assertEquals(!expectOptimized, visitor.wasVisited()); List<Object[]> value = visitor.getResult().toList(); assertNotNull(value); return value; }
public void testSumAreaWithGroupBy() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyName p = ff.property(aname("geom")); GroupByVisitor v = new GroupByVisitorBuilder() .withAggregateAttribute(ff.function("area2", p)) .withAggregateVisitor("SumArea") .withGroupByAttributes( Collections.singleton(aname("name")), dataStore.getSchema(tname("aggregate"))) .build(); dataStore.getFeatureSource(tname("aggregate")).accepts(Query.ALL, v, null); if (dataStore.getSupportedFunctions().containsKey(FilterFunction_area.NAME.getName())) { assertFalse(visited); } List groups = v.getResult().toList(); assertEquals(20.0, (Double) ((Object[]) groups.get(0))[1], 0.01); assertEquals(10.0, (Double) ((Object[]) groups.get(1))[1], 0.01); }
public GroupByVisitorBuilder withAggregateAttribute( String attributeName, SimpleFeatureType type) { aggregateAttribute = toExpression(attributeName, type); return this; }
public GroupByVisitorBuilder withGroupByAttribute( String attributeName, SimpleFeatureType type) { groupByAttributes.add(toExpression(attributeName, type)); return this; }
public GroupByVisitorBuilder withGroupByAttribute( int attributeTypeIndex, SimpleFeatureType type) { groupByAttributes.add(toExpression(attributeTypeIndex, type)); return this; }