use of mil.nga.giat.geowave.adapter.vector.query.cql.CQLQuery in project incubator-rya by apache.
the class GeoWaveGTQueryTest method executeCQLQueryTest.
@Test
public void executeCQLQueryTest() throws IOException, CQLException {
System.out.println("Executing query, expecting to match two points...");
final Filter cqlFilter = ECQL.toFilter("BBOX(geometry,-77.6167,38.6833,-76.6,38.9200) and locationName like 'W%'");
final QueryOptions queryOptions = new QueryOptions(ADAPTER, INDEX);
final CQLQuery cqlQuery = new CQLQuery(null, cqlFilter, ADAPTER);
try (final CloseableIterator<SimpleFeature> iterator = dataStore.query(queryOptions, cqlQuery)) {
int count = 0;
while (iterator.hasNext()) {
System.out.println("Query match: " + iterator.next().getID());
count++;
}
System.out.println("executeCQLQueryTest count: " + count);
// Should match "Washington Monument" and "White House"
assertEquals(2, count);
}
}
use of mil.nga.giat.geowave.adapter.vector.query.cql.CQLQuery in project incubator-rya by apache.
the class GeoWaveGeoIndexer method getIteratorWrapper.
private CloseableIteration<Statement, QueryEvaluationException> getIteratorWrapper(final String filterString) {
return new CloseableIteration<Statement, QueryEvaluationException>() {
private CloseableIterator<SimpleFeature> featureIterator = null;
CloseableIterator<SimpleFeature> getIterator() throws QueryEvaluationException {
if (featureIterator == null) {
Filter cqlFilter;
try {
cqlFilter = ECQL.toFilter(filterString);
} catch (final CQLException e) {
logger.error("Error parsing query: " + LogUtils.clean(filterString), e);
throw new QueryEvaluationException(e);
}
final CQLQuery cqlQuery = new CQLQuery(null, cqlFilter, featureDataAdapter);
final QueryOptions queryOptions = new QueryOptions(featureDataAdapter, index);
try {
featureIterator = geoWaveDataStore.query(queryOptions, cqlQuery);
} catch (final Exception e) {
logger.error("Error performing query: " + filterString, e);
throw new QueryEvaluationException(e);
}
}
return featureIterator;
}
@Override
public boolean hasNext() throws QueryEvaluationException {
return getIterator().hasNext();
}
@Override
public Statement next() throws QueryEvaluationException {
final SimpleFeature feature = getIterator().next();
final String subjectString = feature.getAttribute(SUBJECT_ATTRIBUTE).toString();
final String predicateString = feature.getAttribute(PREDICATE_ATTRIBUTE).toString();
final String objectString = feature.getAttribute(OBJECT_ATTRIBUTE).toString();
final Object context = feature.getAttribute(CONTEXT_ATTRIBUTE);
final String contextString = context != null ? context.toString() : "";
final Statement statement = StatementSerializer.readStatement(subjectString, predicateString, objectString, contextString);
return statement;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not implemented");
}
@Override
public void close() throws QueryEvaluationException {
try {
getIterator().close();
} catch (final IOException e) {
throw new QueryEvaluationException(e);
}
}
};
}
Aggregations