@Test public void testEmptySort() throws IOException, IllegalAccessException { SimpleFeatureSource fsp = getFeatureSource(SystemTestData.PRIMITIVEGEOFEATURE); Query q = new Query(); q.setSortBy(SortBy.UNSORTED); SimpleFeatureCollection fc = fsp.getFeatures(q); // the above call used to add a SortedSimpleFeatureCollection wrapper that in turn killed // some visit optimizations while (fc instanceof DecoratingFeatureCollection) { assertThat(fc, not(instanceOf(SortedSimpleFeatureCollection.class))); Field field = FieldUtils.getDeclaredField(SortedSimpleFeatureCollection.class, "delegate"); field.setAccessible(true); Object delegate = field.get(fc); fc = (SimpleFeatureCollection) delegate; } }
defQuery.setSortBy(query.getSortBy());
result.setCoordinateSystemReproject(userQuery.getCoordinateSystemReproject()); result.setStartIndex(userQuery.getStartIndex()); result.setSortBy(userQuery.getSortBy());
if (sortBy != null && sortBy != SortBy.UNSORTED) { if (!source.getQueryCapabilities().supportsSorting(sortBy)) { query.setSortBy(null);
public SimpleFeatureCollection sort(org.opengis.filter.sort.SortBy sort) { Query query = new Query(); query.setSortBy(new org.opengis.filter.sort.SortBy[] {sort}); query = DataUtilities.mixQueries(this.query, query, null); return new ContentFeatureCollection(featureSource, query); }
public SimpleFeatureCollection sort(SortBy order) { Query subQuery = new Query(getSchema().getTypeName()); subQuery.setSortBy(new SortBy[] {order}); CollectionFeatureSource temp = new CollectionFeatureSource(this); return temp.getFeatures(subQuery); }
@Override public SimpleFeatureCollection sort(SortBy order) { Query subQuery = new Query(getSchema().getTypeName()); subQuery.setSortBy(new SortBy[] {order}); CollectionFeatureSource temp = new CollectionFeatureSource(this); return temp.getFeatures(subQuery); }
@Override public SimpleFeatureCollection sort(SortBy order) { Query q = new Query(getSchema().getTypeName()); q.setSortBy(new SortBy[] {order}); Query subQuery = DataUtilities.mixQueries(query, q, q.getHandle()); return CollectionFeatureSource.this.getFeatures(subQuery); } }
@Test public void testRetypeCannotSortCovered() throws Exception { Query q = new Query(); q.setPropertyNames(new String[] {"name", "z"}); q.setSortBy(new SortBy[] {ff.sort("z", SortOrder.ASCENDING)}); checkRetypeCannotSort(q, q); }
void assertDatesMatch(Filter filter, String... dates) throws Exception { FilterFactory ff = dataStore.getFilterFactory(); Query query = new Query(aname("dates"), filter); query.setSortBy(new SortBy[] {ff.sort(aname("dt"), SortOrder.ASCENDING)}); assertDatesMatch(query, dates); }
public void testNaturalSortingAsc() throws Exception { Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER}); try (SimpleFeatureIterator features = featureSource.getFeatures(q).features()) { String prevId = null; while (features.hasNext()) { String currId = features.next().getID(); if (prevId != null) assertTrue(prevId.compareTo(currId) <= 0); prevId = currId; } } }
public void testNaturalSortingdesc() throws Exception { Query q = new Query(featureSource.getSchema().getTypeName()); q.setSortBy(new SortBy[] {SortBy.REVERSE_ORDER}); try (SimpleFeatureIterator features = featureSource.getFeatures(q).features()) { String prevId = null; while (features.hasNext()) { String currId = features.next().getID(); if (prevId != null) assertTrue(prevId.compareTo(currId) >= 0); prevId = currId; } } }
@Test public void testRetypeCannotSortFullyCovered() throws Exception { Query q = new Query(); q.setPropertyNames( new String[] { "name", }); q.setSortBy(new SortBy[] {ff.sort("z", SortOrder.ASCENDING)}); Query expected = new Query(q); expected.setPropertyNames(new String[] {"name", "z"}); checkRetypeCannotSort(q, expected); }
@Test public void testRetypeCannotSortPartiallyCovered() throws Exception { Query q = new Query(); q.setPropertyNames( new String[] { "name", }); q.setSortBy( new SortBy[] { ff.sort("name", SortOrder.ASCENDING), ff.sort("z", SortOrder.ASCENDING) }); Query expected = new Query(q); expected.setPropertyNames(new String[] {"name", "z"}); checkRetypeCannotSort(q, expected); }
public void testTemporalJoin() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); After after = ff.after(ff.property(aname("dt")), ff.property("other." + aname("dt"))); Query q = new Query(tname("dates")); q.getJoins().add(new Join(tname("dates"), after).alias("other")); q.setSortBy(new SortBy[] {ff.sort(aname("dt"), SortOrder.ASCENDING)}); assertDatesMatch(q, "2009-06-28 15:12:41", "2009-09-29 17:54:23", "2009-09-29 17:54:23"); }
/** * Test the first page of one feature per page with reverse sorting. * * @throws IOException */ @Test public void reverseSortedOneFeatureFirstPage() throws IOException { Query query = new Query(); query.setSortBy(new SortBy[] {SortBy.REVERSE_ORDER}); query.setMaxFeatures(1); query.setStartIndex(0); SimpleFeatureSource fs = store.getFeatureSource(TYPENAME); SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray(); Assert.assertEquals(1, fs.getCount(query)); Assert.assertEquals("mock.3", features[0].getID()); }
/** * Test the second page of one feature per page with reverse sorting. * * @throws IOException */ @Test public void reverseSortedOneFeatureSecondPage() throws IOException { Query query = new Query(); query.setSortBy(new SortBy[] {SortBy.REVERSE_ORDER}); query.setMaxFeatures(1); query.setStartIndex(1); SimpleFeatureSource fs = store.getFeatureSource(TYPENAME); SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray(); Assert.assertEquals(1, fs.getCount(query)); Assert.assertEquals("mock.2", features[0].getID()); }
/** * Test the third page of one feature per page with natural sorting. * * @throws IOException */ @Test public void naturalSortedOneFeatureThirdPage() throws IOException { Query query = new Query(); query.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER}); query.setMaxFeatures(1); query.setStartIndex(2); SimpleFeatureSource fs = store.getFeatureSource(TYPENAME); SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray(); Assert.assertEquals(1, fs.getCount(query)); Assert.assertEquals("mock.3", features[0].getID()); }
/** * Test natural sorting. * * @throws IOException */ @Test public void naturalSortedFeatures() throws IOException { Query query = new Query(); query.setSortBy(new SortBy[] {SortBy.NATURAL_ORDER}); SimpleFeatureSource fs = store.getFeatureSource(TYPENAME); SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray(); Assert.assertEquals(3, fs.getCount(query)); Assert.assertEquals("mock.1", features[0].getID()); Assert.assertEquals("mock.2", features[1].getID()); Assert.assertEquals("mock.3", features[2].getID()); }
/** * Test reverse sorting. * * @throws IOException */ @Test public void reverseSortedFeatures() throws IOException { Query query = new Query(); query.setSortBy(new SortBy[] {SortBy.REVERSE_ORDER}); SimpleFeatureSource fs = store.getFeatureSource(TYPENAME); SimpleFeature[] features = (SimpleFeature[]) fs.getFeatures(query).toArray(); Assert.assertEquals(3, fs.getCount(query)); Assert.assertEquals("mock.3", features[0].getID()); Assert.assertEquals("mock.2", features[1].getID()); Assert.assertEquals("mock.1", features[2].getID()); }