Search in sources :

Example 1 with CloseableIterator

use of mil.nga.giat.geowave.core.store.CloseableIterator 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);
            }
        }
    };
}
Also used : CloseableIterator(mil.nga.giat.geowave.core.store.CloseableIterator) RyaStatement(org.apache.rya.api.domain.RyaStatement) Statement(org.eclipse.rdf4j.model.Statement) CQLQuery(mil.nga.giat.geowave.adapter.vector.query.cql.CQLQuery) IOException(java.io.IOException) QueryOptions(mil.nga.giat.geowave.core.store.query.QueryOptions) SimpleFeature(org.opengis.feature.simple.SimpleFeature) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) GeoWavePluginException(mil.nga.giat.geowave.adapter.vector.plugin.GeoWavePluginException) ParseException(com.vividsolutions.jts.io.ParseException) SchemaException(org.geotools.feature.SchemaException) CQLException(org.geotools.filter.text.cql2.CQLException) IOException(java.io.IOException) CloseableIteration(org.eclipse.rdf4j.common.iteration.CloseableIteration) QueryEvaluationException(org.eclipse.rdf4j.query.QueryEvaluationException) Filter(org.opengis.filter.Filter) CQLException(org.geotools.filter.text.cql2.CQLException)

Aggregations

ParseException (com.vividsolutions.jts.io.ParseException)1 IOException (java.io.IOException)1 GeoWavePluginException (mil.nga.giat.geowave.adapter.vector.plugin.GeoWavePluginException)1 CQLQuery (mil.nga.giat.geowave.adapter.vector.query.cql.CQLQuery)1 CloseableIterator (mil.nga.giat.geowave.core.store.CloseableIterator)1 QueryOptions (mil.nga.giat.geowave.core.store.query.QueryOptions)1 RyaStatement (org.apache.rya.api.domain.RyaStatement)1 CloseableIteration (org.eclipse.rdf4j.common.iteration.CloseableIteration)1 Statement (org.eclipse.rdf4j.model.Statement)1 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)1 SchemaException (org.geotools.feature.SchemaException)1 CQLException (org.geotools.filter.text.cql2.CQLException)1 SimpleFeature (org.opengis.feature.simple.SimpleFeature)1 Filter (org.opengis.filter.Filter)1