Repository: incubator-rya Updated Branches: refs/heads/develop 80faf06d4 -> 990f1ffe2
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e5e227c1/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java index 8ca96bc..c204f3c 100644 --- a/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java +++ b/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/geo/GeoIndexerTest.java @@ -22,16 +22,12 @@ package mvm.rya.indexing.accumulo.geo; import static mvm.rya.api.resolver.RdfToRyaConversions.convertStatement; -import info.aduna.iteration.CloseableIteration; import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.UUID; -import mvm.rya.indexing.StatementContraints; -import mvm.rya.indexing.accumulo.ConfigUtils; - import org.apache.accumulo.core.client.admin.TableOperations; import org.apache.hadoop.conf.Configuration; import org.junit.Assert; @@ -55,6 +51,10 @@ import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.geom.PrecisionModel; import com.vividsolutions.jts.geom.impl.PackedCoordinateSequence; +import info.aduna.iteration.CloseableIteration; +import mvm.rya.indexing.StatementContraints; +import mvm.rya.indexing.accumulo.ConfigUtils; + public class GeoIndexerTest { private static final StatementContraints EMPTY_CONSTRAINTS = new StatementContraints(); @@ -89,42 +89,41 @@ public class GeoIndexerTest { @Test public void testRestrictPredicatesSearch() throws Exception { conf.setStrings(ConfigUtils.GEO_PREDICATES_LIST, "pred:1,pred:2"); - GeoMesaGeoIndexer f = new GeoMesaGeoIndexer(); - f.setConf(conf); - - ValueFactory vf = new ValueFactoryImpl(); + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); - Point point = gf.createPoint(new Coordinate(10, 10)); - Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT); - URI invalidPredicate = GeoConstants.GEO_AS_WKT; + ValueFactory vf = new ValueFactoryImpl(); - // These should not be stored because they are not in the predicate list - f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), invalidPredicate, pointValue))); - f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), invalidPredicate, pointValue))); + Point point = gf.createPoint(new Coordinate(10, 10)); + Value pointValue = vf.createLiteral("Point(10 10)", GeoConstants.XMLSCHEMA_OGC_WKT); + URI invalidPredicate = GeoConstants.GEO_AS_WKT; - URI pred1 = vf.createURI("pred:1"); - URI pred2 = vf.createURI("pred:2"); + // These should not be stored because they are not in the predicate list + f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), invalidPredicate, pointValue))); + f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), invalidPredicate, pointValue))); - // These should be stored because they are in the predicate list - Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1, pointValue); - Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), pred2, pointValue); - f.storeStatement(convertStatement(s3)); - f.storeStatement(convertStatement(s4)); + URI pred1 = vf.createURI("pred:1"); + URI pred2 = vf.createURI("pred:2"); - // This should not be stored because the object is not valid wkt - f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)")))); + // These should be stored because they are in the predicate list + Statement s3 = new StatementImpl(vf.createURI("foo:subj3"), pred1, pointValue); + Statement s4 = new StatementImpl(vf.createURI("foo:subj4"), pred2, pointValue); + f.storeStatement(convertStatement(s3)); + f.storeStatement(convertStatement(s4)); - // This should not be stored because the object is not a literal - f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj6"), pred1, vf.createURI("p:Point(10 10)")))); + // This should not be stored because the object is not valid wkt + f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj5"), pred1, vf.createLiteral("soint(10 10)")))); - f.flush(); + // This should not be stored because the object is not a literal + f.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj6"), pred1, vf.createURI("p:Point(10 10)")))); - Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS)); - Assert.assertEquals(2, actual.size()); - Assert.assertTrue(actual.contains(s3)); - Assert.assertTrue(actual.contains(s4)); + f.flush(); - f.close(); + Set<Statement> actual = getSet(f.queryEquals(point, EMPTY_CONSTRAINTS)); + Assert.assertEquals(2, actual.size()); + Assert.assertTrue(actual.contains(s3)); + Assert.assertTrue(actual.contains(s4)); + } } private static <X> Set<X> getSet(CloseableIteration<X, ?> iter) throws Exception { @@ -137,234 +136,264 @@ public class GeoIndexerTest { @Test public void testPrimeMeridianSearch() throws Exception { - - GeoMesaGeoIndexer f = new GeoMesaGeoIndexer(); - f.setConf(conf); - - ValueFactory vf = new ValueFactoryImpl(); - Resource subject = vf.createURI("foo:subj"); - URI predicate = GeoConstants.GEO_AS_WKT; - Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - Resource context = vf.createURI("foo:context"); - - Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 }; - double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 }; - double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 }; - - LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2)); - LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2)); - LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2)); - - Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - Polygon p2 = gf.createPolygon(r2, new LinearRing[] {}); - Polygon p3 = gf.createPolygon(r3, new LinearRing[] {}); - - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS))); - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS))); - - // Test a ring with a hole in it - Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 }); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS))); - - // test a ring outside the point - double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 }; - LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2)); - Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); - - f.close(); + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); + + ValueFactory vf = new ValueFactoryImpl(); + Resource subject = vf.createURI("foo:subj"); + URI predicate = GeoConstants.GEO_AS_WKT; + Value object = vf.createLiteral("Point(0 0)", GeoConstants.XMLSCHEMA_OGC_WKT); + Resource context = vf.createURI("foo:context"); + + Statement statement = new ContextStatementImpl(subject, predicate, object, context); + f.storeStatement(convertStatement(statement)); + f.flush(); + + double[] ONE = { 1, 1, -1, 1, -1, -1, 1, -1, 1, 1 }; + double[] TWO = { 2, 2, -2, 2, -2, -2, 2, -2, 2, 2 }; + double[] THREE = { 3, 3, -3, 3, -3, -3, 3, -3, 3, 3 }; + + LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2)); + LinearRing r2 = gf.createLinearRing(new PackedCoordinateSequence.Double(TWO, 2)); + LinearRing r3 = gf.createLinearRing(new PackedCoordinateSequence.Double(THREE, 2)); + + Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); + Polygon p2 = gf.createPolygon(r2, new LinearRing[] {}); + Polygon p3 = gf.createPolygon(r3, new LinearRing[] {}); + + Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); + Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p2, EMPTY_CONSTRAINTS))); + Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p3, EMPTY_CONSTRAINTS))); + + // Test a ring with a hole in it + Polygon p3m2 = gf.createPolygon(r3, new LinearRing[] { r2 }); + Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p3m2, EMPTY_CONSTRAINTS))); + + // test a ring outside the point + double[] OUT = { 3, 3, 1, 3, 1, 1, 3, 1, 3, 3 }; + LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2)); + Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {}); + Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); + } } @Test public void testDcSearch() throws Exception { // test a ring around dc - GeoMesaGeoIndexer f = new GeoMesaGeoIndexer(); - f.setConf(conf); - - ValueFactory vf = new ValueFactoryImpl(); - Resource subject = vf.createURI("foo:subj"); - URI predicate = GeoConstants.GEO_AS_WKT; - Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - Resource context = vf.createURI("foo:context"); - - Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - - // test a ring outside the point - double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 }; - LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2)); - Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); - - f.close(); + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); + + ValueFactory vf = new ValueFactoryImpl(); + Resource subject = vf.createURI("foo:subj"); + URI predicate = GeoConstants.GEO_AS_WKT; + Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); + Resource context = vf.createURI("foo:context"); + + Statement statement = new ContextStatementImpl(subject, predicate, object, context); + f.storeStatement(convertStatement(statement)); + f.flush(); + + double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; + LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); + Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); + Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); + + // test a ring outside the point + double[] OUT = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 }; + LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(OUT, 2)); + Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {}); + Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); + } } @Test - public void testDcSearchWithContext() throws Exception { + public void testDeleteSearch() throws Exception { // test a ring around dc - GeoMesaGeoIndexer f = new GeoMesaGeoIndexer(); - f.setConf(conf); + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); + + ValueFactory vf = new ValueFactoryImpl(); + Resource subject = vf.createURI("foo:subj"); + URI predicate = GeoConstants.GEO_AS_WKT; + Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); + Resource context = vf.createURI("foo:context"); + + Statement statement = new ContextStatementImpl(subject, predicate, object, context); + f.storeStatement(convertStatement(statement)); + f.flush(); + + f.deleteStatement(convertStatement(statement)); + + // test a ring that the point would be inside of if not deleted + double[] in = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; + LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(in, 2)); + Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); + Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); + + // test a ring that the point would be outside of if not deleted + double[] out = { -77, 39, -76, 39, -76, 38, -77, 38, -77, 39 }; + LinearRing rOut = gf.createLinearRing(new PackedCoordinateSequence.Double(out, 2)); + Polygon pOut = gf.createPolygon(rOut, new LinearRing[] {}); + Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pOut, EMPTY_CONSTRAINTS))); + + // test a ring for the whole world and make sure the point is gone + double[] world = { -180, 90, 180, 90, -180, 90, -180, -90, -180, 90 }; + LinearRing rWorld = gf.createLinearRing(new PackedCoordinateSequence.Double(world, 2)); + Polygon pWorld = gf.createPolygon(rWorld, new LinearRing[] {}); + Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(pWorld, EMPTY_CONSTRAINTS))); + } + } - ValueFactory vf = new ValueFactoryImpl(); - Resource subject = vf.createURI("foo:subj"); - URI predicate = GeoConstants.GEO_AS_WKT; - Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - Resource context = vf.createURI("foo:context"); + @Test + public void testDcSearchWithContext() throws Exception { + // test a ring around dc + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); - Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); + ValueFactory vf = new ValueFactoryImpl(); + Resource subject = vf.createURI("foo:subj"); + URI predicate = GeoConstants.GEO_AS_WKT; + Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); + Resource context = vf.createURI("foo:context"); - double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); + Statement statement = new ContextStatementImpl(subject, predicate, object, context); + f.storeStatement(convertStatement(statement)); + f.flush(); - // query with correct context - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementContraints().setContext(context)))); + double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; + LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); + Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - // query with wrong context - Assert.assertEquals(Sets.newHashSet(), - getSet(f.queryWithin(p1, new StatementContraints().setContext(vf.createURI("foo:context2"))))); + // query with correct context + Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementContraints().setContext(context)))); - f.close(); + // query with wrong context + Assert.assertEquals(Sets.newHashSet(), + getSet(f.queryWithin(p1, new StatementContraints().setContext(vf.createURI("foo:context2"))))); + } } @Test public void testDcSearchWithSubject() throws Exception { // test a ring around dc - GeoMesaGeoIndexer f = new GeoMesaGeoIndexer(); - f.setConf(conf); - - ValueFactory vf = new ValueFactoryImpl(); - Resource subject = vf.createURI("foo:subj"); - URI predicate = GeoConstants.GEO_AS_WKT; - Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - Resource context = vf.createURI("foo:context"); - - Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - - // query with correct subject - Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementContraints().setSubject(subject)))); - - // query with wrong subject - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementContraints().setSubject(vf.createURI("foo:subj2"))))); - - f.close(); + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); + + ValueFactory vf = new ValueFactoryImpl(); + Resource subject = vf.createURI("foo:subj"); + URI predicate = GeoConstants.GEO_AS_WKT; + Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); + Resource context = vf.createURI("foo:context"); + + Statement statement = new ContextStatementImpl(subject, predicate, object, context); + f.storeStatement(convertStatement(statement)); + f.flush(); + + double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; + LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); + Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); + + // query with correct subject + Assert.assertEquals(Sets.newHashSet(statement), getSet(f.queryWithin(p1, new StatementContraints().setSubject(subject)))); + + // query with wrong subject + Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementContraints().setSubject(vf.createURI("foo:subj2"))))); + } } @Test public void testDcSearchWithSubjectAndContext() throws Exception { // test a ring around dc - GeoMesaGeoIndexer f = new GeoMesaGeoIndexer(); - f.setConf(conf); + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); - ValueFactory vf = new ValueFactoryImpl(); - Resource subject = vf.createURI("foo:subj"); - URI predicate = GeoConstants.GEO_AS_WKT; - Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - Resource context = vf.createURI("foo:context"); + ValueFactory vf = new ValueFactoryImpl(); + Resource subject = vf.createURI("foo:subj"); + URI predicate = GeoConstants.GEO_AS_WKT; + Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); + Resource context = vf.createURI("foo:context"); - Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); + Statement statement = new ContextStatementImpl(subject, predicate, object, context); + f.storeStatement(convertStatement(statement)); + f.flush(); - double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); + double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; + LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); + Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - // query with correct context subject - Assert.assertEquals(Sets.newHashSet(statement), - getSet(f.queryWithin(p1, new StatementContraints().setContext(context).setSubject(subject)))); + // query with correct context subject + Assert.assertEquals(Sets.newHashSet(statement), + getSet(f.queryWithin(p1, new StatementContraints().setContext(context).setSubject(subject)))); - // query with wrong context - Assert.assertEquals(Sets.newHashSet(), - getSet(f.queryWithin(p1, new StatementContraints().setContext(vf.createURI("foo:context2"))))); + // query with wrong context + Assert.assertEquals(Sets.newHashSet(), + getSet(f.queryWithin(p1, new StatementContraints().setContext(vf.createURI("foo:context2"))))); - // query with wrong subject - Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementContraints().setSubject(vf.createURI("foo:subj2"))))); - - f.close(); + // query with wrong subject + Assert.assertEquals(Sets.newHashSet(), getSet(f.queryWithin(p1, new StatementContraints().setSubject(vf.createURI("foo:subj2"))))); + } } @Test public void testDcSearchWithPredicate() throws Exception { // test a ring around dc - GeoMesaGeoIndexer f = new GeoMesaGeoIndexer(); - f.setConf(conf); - - ValueFactory vf = new ValueFactoryImpl(); - Resource subject = vf.createURI("foo:subj"); - URI predicate = GeoConstants.GEO_AS_WKT; - Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); - Resource context = vf.createURI("foo:context"); - - Statement statement = new ContextStatementImpl(subject, predicate, object, context); - f.storeStatement(convertStatement(statement)); - f.flush(); - - double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; - LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); - Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - - // query with correct Predicate - Assert.assertEquals(Sets.newHashSet(statement), - getSet(f.queryWithin(p1, new StatementContraints().setPredicates(Collections.singleton(predicate))))); - - // query with wrong predicate - Assert.assertEquals(Sets.newHashSet(), - getSet(f.queryWithin(p1, new StatementContraints().setPredicates(Collections.singleton(vf.createURI("other:pred")))))); - - f.close(); + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); + + ValueFactory vf = new ValueFactoryImpl(); + Resource subject = vf.createURI("foo:subj"); + URI predicate = GeoConstants.GEO_AS_WKT; + Value object = vf.createLiteral("Point(-77.03524 38.889468)", GeoConstants.XMLSCHEMA_OGC_WKT); + Resource context = vf.createURI("foo:context"); + + Statement statement = new ContextStatementImpl(subject, predicate, object, context); + f.storeStatement(convertStatement(statement)); + f.flush(); + + double[] IN = { -78, 39, -77, 39, -77, 38, -78, 38, -78, 39 }; + LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(IN, 2)); + Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); + + // query with correct Predicate + Assert.assertEquals(Sets.newHashSet(statement), + getSet(f.queryWithin(p1, new StatementContraints().setPredicates(Collections.singleton(predicate))))); + + // query with wrong predicate + Assert.assertEquals(Sets.newHashSet(), + getSet(f.queryWithin(p1, new StatementContraints().setPredicates(Collections.singleton(vf.createURI("other:pred")))))); + } } // @Test public void testAntiMeridianSearch() throws Exception { // verify that a search works if the bounding box crosses the anti meridian - GeoMesaGeoIndexer f = new GeoMesaGeoIndexer(); - f.setConf(conf); + try (GeoMesaGeoIndexer f = new GeoMesaGeoIndexer()) { + f.setConf(conf); - ValueFactory vf = new ValueFactoryImpl(); - Resource context = vf.createURI("foo:context"); + ValueFactory vf = new ValueFactoryImpl(); + Resource context = vf.createURI("foo:context"); - Resource subjectEast = vf.createURI("foo:subj:east"); - URI predicateEast = GeoConstants.GEO_AS_WKT; - Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - Statement statementEast = new ContextStatementImpl(subjectEast, predicateEast, objectEast, context); - f.storeStatement(convertStatement(statementEast)); + Resource subjectEast = vf.createURI("foo:subj:east"); + URI predicateEast = GeoConstants.GEO_AS_WKT; + Value objectEast = vf.createLiteral("Point(179 0)", GeoConstants.XMLSCHEMA_OGC_WKT); + Statement statementEast = new ContextStatementImpl(subjectEast, predicateEast, objectEast, context); + f.storeStatement(convertStatement(statementEast)); - Resource subjectWest = vf.createURI("foo:subj:west"); - URI predicateWest = GeoConstants.GEO_AS_WKT; - Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT); - Statement statementWest = new ContextStatementImpl(subjectWest, predicateWest, objectWest, context); - f.storeStatement(convertStatement(statementWest)); + Resource subjectWest = vf.createURI("foo:subj:west"); + URI predicateWest = GeoConstants.GEO_AS_WKT; + Value objectWest = vf.createLiteral("Point(-179 0)", GeoConstants.XMLSCHEMA_OGC_WKT); + Statement statementWest = new ContextStatementImpl(subjectWest, predicateWest, objectWest, context); + f.storeStatement(convertStatement(statementWest)); - f.flush(); + f.flush(); - double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 }; + double[] ONE = { 178.1, 1, -178, 1, -178, -1, 178.1, -1, 178.1, 1 }; - LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2)); + LinearRing r1 = gf.createLinearRing(new PackedCoordinateSequence.Double(ONE, 2)); - Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); + Polygon p1 = gf.createPolygon(r1, new LinearRing[] {}); - Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); - - f.close(); + Assert.assertEquals(Sets.newHashSet(statementEast, statementWest), getSet(f.queryWithin(p1, EMPTY_CONSTRAINTS))); + } } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e5e227c1/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/temporal/AccumuloTemporalIndexerTest.java ---------------------------------------------------------------------- diff --git a/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/temporal/AccumuloTemporalIndexerTest.java b/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/temporal/AccumuloTemporalIndexerTest.java index 60d237d..1c6628f 100644 --- a/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/temporal/AccumuloTemporalIndexerTest.java +++ b/extras/indexing/src/test/java/mvm/rya/indexing/accumulo/temporal/AccumuloTemporalIndexerTest.java @@ -1,6 +1,3 @@ -/** - * - */ package mvm.rya.indexing.accumulo.temporal; /* @@ -26,7 +23,6 @@ package mvm.rya.indexing.accumulo.temporal; import static mvm.rya.api.resolver.RdfToRyaConversions.convertStatement; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import info.aduna.iteration.CloseableIteration; import java.io.IOException; import java.io.PrintStream; @@ -42,15 +38,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; -import junit.framework.Assert; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.indexing.StatementContraints; -import mvm.rya.indexing.TemporalInstant; -import mvm.rya.indexing.TemporalInterval; -import mvm.rya.indexing.accumulo.ConfigUtils; -import mvm.rya.indexing.accumulo.StatementSerializer; - -import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Scanner; @@ -59,6 +46,7 @@ import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.admin.TableOperations; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Value; +import org.apache.accumulo.core.security.Authorizations; import org.apache.commons.codec.binary.StringUtils; import org.apache.commons.io.output.NullOutputStream; import org.apache.hadoop.conf.Configuration; @@ -78,25 +66,34 @@ import org.openrdf.query.QueryEvaluationException; import com.beust.jcommander.internal.Lists; +import info.aduna.iteration.CloseableIteration; +import junit.framework.Assert; +import mvm.rya.api.domain.RyaStatement; +import mvm.rya.indexing.StatementContraints; +import mvm.rya.indexing.TemporalInstant; +import mvm.rya.indexing.TemporalInterval; +import mvm.rya.indexing.accumulo.ConfigUtils; +import mvm.rya.indexing.accumulo.StatementSerializer; + /** * JUnit tests for TemporalIndexer and it's implementation AccumuloTemporalIndexer - * + * * If you enjoy this test, please read RyaTemporalIndexerTest and YagoKBTest, which contain * many example SPARQL queries and updates and attempts to test independently of Accumulo: - * + * * extras/indexingSail/src/test/java/mvm/rya/indexing/accumulo/RyaTemporalIndexerTest.java * {@link mvm.rya.indexing.accumulo.RyaTemporalIndexerTest} * {@link mvm.rya.indexing.accumulo.YagoKBTest.java} - * + * * Remember, this class in instantiated fresh for each @test method. * so fields are reset, unless they are static. - * + * * These are covered: - * Instance {before, equals, after} given Instance + * Instance {before, equals, after} given Instance * Instance {before, after, inside} given Interval * Instance {hasBeginning, hasEnd} given Interval * And a few more. - * + * */ public final class AccumuloTemporalIndexerTest { // Configuration properties, this is reset per test in setup. @@ -268,7 +265,7 @@ public final class AccumuloTemporalIndexerTest { /** * Test method for {@link AccumuloTemporalIndexer#TemporalIndexerImpl(org.apache.hadoop.conf.Configuration)} . - * + * * @throws TableExistsException * @throws TableNotFoundException * @throws AccumuloSecurityException @@ -283,7 +280,7 @@ public final class AccumuloTemporalIndexerTest { /** * Test method for {@link AccumuloTemporalIndexer#storeStatement(convertStatement(org.openrdf.model.Statement)} - * + * * @throws NoSuchAlgorithmException */ @Test @@ -339,7 +336,41 @@ public final class AccumuloTemporalIndexerTest { Assert.assertEquals("Number of rows stored.", rowsStoredExpected*4, rowsStoredActual); // 4 index entries per statement } - + + @Test + public void testDelete() throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NoSuchAlgorithmException { + // count rows expected to store: + int rowsStoredExpected = 0; + + ValueFactory vf = new ValueFactoryImpl(); + + URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME); + URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA); + + final String testDate2014InBRST = "2014-12-31T23:59:59-02:00"; + final String testDate2016InET = "2016-12-31T20:59:59-05:00"; + + // These should be stored because they are in the predicate list. + // BUT they will get converted to the same exact datetime in UTC. + Statement s1 = new StatementImpl(vf.createURI("foo:subj3"), pred1_atTime, vf.createLiteral(testDate2014InBRST)); + Statement s2 = new StatementImpl(vf.createURI("foo:subj4"), pred2_circa, vf.createLiteral(testDate2016InET)); + tIndexer.storeStatement(convertStatement(s1)); + rowsStoredExpected++; + tIndexer.storeStatement(convertStatement(s2)); + rowsStoredExpected++; + + tIndexer.flush(); + + int rowsStoredActual = printTables("junit testing: Temporal entities stored in testDelete before delete", System.out, null); + Assert.assertEquals("Number of rows stored.", rowsStoredExpected*4, rowsStoredActual); // 4 index entries per statement + + tIndexer.deleteStatement(convertStatement(s1)); + tIndexer.deleteStatement(convertStatement(s2)); + + int afterDeleteRowsStoredActual = printTables("junit testing: Temporal entities stored in testDelete after delete", System.out, null); + Assert.assertEquals("Number of rows stored after delete.", 0, afterDeleteRowsStoredActual); + } + @Test public void testStoreStatementWithInterestingLiterals() throws Exception { ValueFactory vf = new ValueFactoryImpl(); @@ -356,36 +387,35 @@ public final class AccumuloTemporalIndexerTest { } /** - * Test method for {@link AccumuloTemporalIndexer#storeStatement(convertStatement(org.openrdf.model.Statement)} - * - * @throws NoSuchAlgorithmException - */ - @Test - public void testStoreStatementBadInterval() throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NoSuchAlgorithmException { - // count rows expected to store: - int rowsStoredExpected = 0; - - ValueFactory vf = new ValueFactoryImpl(); - URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME); - - // Test: Should not store an improper date interval, and log a warning (log warning not tested). - final String invalidDateIntervalString="[bad,interval]"; - // Silently logs a warning for bad dates. - tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), pred1_atTime, vf.createLiteral(invalidDateIntervalString)))); - - final String validDateIntervalString="[2016-12-31T20:59:59-05:00,2016-12-31T21:00:00-05:00]"; - tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, vf.createLiteral(validDateIntervalString)))); - rowsStoredExpected++; - - tIndexer.flush(); - - int rowsStoredActual = printTables("junit testing: Temporal intervals stored in testStoreStatement", null, null); - Assert.assertEquals("Only good intervals should be stored.", rowsStoredExpected*2, rowsStoredActual); // 2 index entries per interval statement - } - - @Test - public void testStoreStatementsSameTime() throws IOException, NoSuchAlgorithmException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException - { + * Test method for {@link AccumuloTemporalIndexer#storeStatement(convertStatement(org.openrdf.model.Statement)} + * + * @throws NoSuchAlgorithmException + */ + @Test + public void testStoreStatementBadInterval() throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NoSuchAlgorithmException { + // count rows expected to store: + int rowsStoredExpected = 0; + + ValueFactory vf = new ValueFactoryImpl(); + URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME); + + // Test: Should not store an improper date interval, and log a warning (log warning not tested). + final String invalidDateIntervalString="[bad,interval]"; + // Silently logs a warning for bad dates. + tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj1"), pred1_atTime, vf.createLiteral(invalidDateIntervalString)))); + + final String validDateIntervalString="[2016-12-31T20:59:59-05:00,2016-12-31T21:00:00-05:00]"; + tIndexer.storeStatement(convertStatement(new StatementImpl(vf.createURI("foo:subj2"), pred1_atTime, vf.createLiteral(validDateIntervalString)))); + rowsStoredExpected++; + + tIndexer.flush(); + + int rowsStoredActual = printTables("junit testing: Temporal intervals stored in testStoreStatement", null, null); + Assert.assertEquals("Only good intervals should be stored.", rowsStoredExpected*2, rowsStoredActual); // 2 index entries per interval statement + } + + @Test + public void testStoreStatementsSameTime() throws IOException, NoSuchAlgorithmException, AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException { ValueFactory vf = new ValueFactoryImpl(); URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME); URI pred2_circa = vf.createURI(URI_PROPERTY_CIRCA); @@ -416,7 +446,7 @@ public final class AccumuloTemporalIndexerTest { /** * Test method for {@link AccumuloTemporalIndexer#storeStatements(java.util.Collection)} . - * + * * @throws TableExistsException * @throws TableNotFoundException * @throws AccumuloSecurityException @@ -482,9 +512,9 @@ public final class AccumuloTemporalIndexerTest { /** * Test instant equal to a given instant. * From the series: instant {equal, before, after} instant - * @throws AccumuloSecurityException - * @throws AccumuloException - * @throws TableNotFoundException + * @throws AccumuloSecurityException + * @throws AccumuloException + * @throws TableNotFoundException */ @Test public void testQueryInstantEqualsInstant() throws IOException, QueryEvaluationException, TableNotFoundException, AccumuloException, AccumuloSecurityException { @@ -525,9 +555,9 @@ public final class AccumuloTemporalIndexerTest { /** * Test instant after a given instant. * From the series: instant {equal, before, after} instant - * @throws AccumuloSecurityException - * @throws AccumuloException - * @throws TableNotFoundException + * @throws AccumuloSecurityException + * @throws AccumuloException + * @throws TableNotFoundException */ @Test public void testQueryInstantAfterInstant() throws IOException, QueryEvaluationException, TableNotFoundException, AccumuloException, AccumuloSecurityException { @@ -579,7 +609,7 @@ public final class AccumuloTemporalIndexerTest { } tIndexer.flush(); CloseableIteration<Statement, QueryEvaluationException> iter; - + iter = tIndexer.queryInstantBeforeInstant(seriesTs[searchForSeconds], EMPTY_CONSTRAINTS); int count = 0; while (iter.hasNext()) { @@ -763,9 +793,9 @@ public final class AccumuloTemporalIndexerTest { * Test method for * {@link mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexer#queryIntervalEquals(TemporalInterval, StatementContraints)} * . - * @throws IOException - * @throws QueryEvaluationException - * + * @throws IOException + * @throws QueryEvaluationException + * */ @Test public void testQueryIntervalEquals() throws IOException, QueryEvaluationException { @@ -789,9 +819,9 @@ public final class AccumuloTemporalIndexerTest { /** * Test interval before a given interval, for method: * {@link AccumuloTemporalIndexer#queryIntervalBefore(TemporalInterval, StatementContraints)}. - * - * @throws IOException - * @throws QueryEvaluationException + * + * @throws IOException + * @throws QueryEvaluationException */ @Test public void testQueryIntervalBefore() throws IOException, QueryEvaluationException { @@ -804,7 +834,7 @@ public final class AccumuloTemporalIndexerTest { // instants should be ignored. tIndexer.storeStatement(convertStatement(spo_B30_E32)); tIndexer.storeStatement(convertStatement(seriesSpo[1])); // instance at 1 seconds - tIndexer.storeStatement(convertStatement(seriesSpo[2])); + tIndexer.storeStatement(convertStatement(seriesSpo[2])); tIndexer.storeStatement(convertStatement(seriesSpo[31])); tIndexer.flush(); @@ -819,9 +849,9 @@ public final class AccumuloTemporalIndexerTest { /** * interval is after the given interval. Find interval beginnings after the endings of the given interval. * {@link AccumuloTemporalIndexer#queryIntervalAfter(TemporalInterval, StatementContraints). - * - * @throws IOException - * @throws QueryEvaluationException + * + * @throws IOException + * @throws QueryEvaluationException */ @Test public void testQueryIntervalAfter() throws IOException, QueryEvaluationException { @@ -837,7 +867,7 @@ public final class AccumuloTemporalIndexerTest { // instants should be ignored. tIndexer.storeStatement(convertStatement(spo_B02)); tIndexer.storeStatement(convertStatement(seriesSpo[1])); // instance at 1 seconds - tIndexer.storeStatement(convertStatement(seriesSpo[2])); + tIndexer.storeStatement(convertStatement(seriesSpo[2])); tIndexer.storeStatement(convertStatement(seriesSpo[31])); tIndexer.flush(); @@ -874,7 +904,7 @@ public final class AccumuloTemporalIndexerTest { URI pred3_CIRCA_ = vf.createURI(URI_PROPERTY_CIRCA); // this one to ignore. URI pred2_eventTime = vf.createURI(URI_PROPERTY_EVENT_TIME); URI pred1_atTime = vf.createURI(URI_PROPERTY_AT_TIME); - + // add the predicate = EventTime ; Store in an array for verification. Statement[] SeriesTs_EventTime = new Statement[expectedResultCount+1]; for (int s = 0; s <= searchForSeconds + expectedResultCount; s++) { // <== logic here @@ -892,7 +922,7 @@ public final class AccumuloTemporalIndexerTest { CloseableIteration<Statement, QueryEvaluationException> iter; StatementContraints constraints = new StatementContraints(); constraints.setPredicates(new HashSet<URI>(Arrays.asList( pred2_eventTime, pred1_atTime ))); - + iter = tIndexer.queryInstantAfterInstant(seriesTs[searchForSeconds], constraints); // EMPTY_CONSTRAINTS);// int count_AtTime = 0; int count_EventTime = 0; @@ -910,17 +940,17 @@ public final class AccumuloTemporalIndexerTest { } else { assertTrue("This predicate should not be returned: "+s, false); } - + } - + Assert.assertEquals("Should find count of atTime rows.", expectedResultCount, count_AtTime); Assert.assertEquals("Should find count of eventTime rows.", expectedResultCount, count_EventTime); } - + /** * Test method for {@link AccumuloTemporalIndexer#getIndexablePredicates()} . - * + * * @throws TableExistsException * @throws TableNotFoundException * @throws AccumuloSecurityException @@ -936,7 +966,7 @@ public final class AccumuloTemporalIndexerTest { /** * Count all the entries in the temporal index table, return the count. * Uses printTables for reliability. - * + * */ public int countAllRowsInTable() throws AccumuloException, AccumuloSecurityException, TableNotFoundException, NoSuchAlgorithmException { return printTables("Counting rows.", null, null); @@ -944,7 +974,7 @@ public final class AccumuloTemporalIndexerTest { /** * Print and gather statistics on the entire index table. - * + * * @param description * Printed to the console to find the test case. * @param out @@ -967,19 +997,18 @@ public final class AccumuloTemporalIndexerTest { out.println("Reading : " + this.uniquePerTestTemporalIndexTableName); out.format(FORMAT, "--Row--", "--ColumnFamily--", "--ColumnQualifier--", "--Value--"); - Scanner s = ConfigUtils.getConnector(conf).createScanner(this.uniquePerTestTemporalIndexTableName, Constants.NO_AUTHS); + Scanner s = ConfigUtils.getConnector(conf).createScanner(this.uniquePerTestTemporalIndexTableName, Authorizations.EMPTY); for (Entry<Key, org.apache.accumulo.core.data.Value> entry : s) { rowsPrinted++; Key k = entry.getKey(); - out.format(FORMAT, toHumanString(k.getRow()), - toHumanString(k.getColumnFamily()), - toHumanString(k.getColumnQualifier()), - toHumanString(entry.getValue())); + out.format(FORMAT, toHumanString(k.getRow()), + toHumanString(k.getColumnFamily()), + toHumanString(k.getColumnQualifier()), + toHumanString(entry.getValue())); keyHasher = hasher(keyHasher, (StringUtils.getBytesUtf8(entry.getKey().toStringNoTime()))); valueHasher = hasher(valueHasher, (entry.getValue().get())); } out.println(); - // } if (statistics != null) { statistics.put(STAT_COUNT, (long) rowsPrinted); @@ -994,7 +1023,7 @@ public final class AccumuloTemporalIndexerTest { /** * Order independent hashcode. * Read more: http://stackoverflow.com/questions/18021643/hashing-a-set-of-integers-in-an-order-independent-way - * + * * @param hashcode * @param list * @return @@ -1013,28 +1042,28 @@ public final class AccumuloTemporalIndexerTest { * @param value * @return Human readable representation. */ - static String toHumanString(Value value) { - return toHumanString(value==null?null:value.get()); - } - static String toHumanString(Text text) { - return toHumanString(text==null?null:text.copyBytes()); - } - static String toHumanString(byte[] bytes) { - if (bytes==null) - return "{null}"; - StringBuilder sb = new StringBuilder(); - for (byte b : bytes) { - if ((b > 0x7e) || (b < 32)) { - sb.append("{"); - sb.append(Integer.toHexString( b & 0xff )); // Lop off the sign extended ones. - sb.append("}"); - } else if (b == '{'||b == '}') { // Escape the literal braces. - sb.append("{"); - sb.append((char)b); - sb.append("}"); - } else - sb.append((char)b); - } - return sb.toString(); - } + static String toHumanString(Value value) { + return toHumanString(value==null?null:value.get()); + } + static String toHumanString(Text text) { + return toHumanString(text==null?null:text.copyBytes()); + } + static String toHumanString(byte[] bytes) { + if (bytes==null) + return "{null}"; + StringBuilder sb = new StringBuilder(); + for (byte b : bytes) { + if ((b > 0x7e) || (b < 32)) { + sb.append("{"); + sb.append(Integer.toHexString( b & 0xff )); // Lop off the sign extended ones. + sb.append("}"); + } else if (b == '{'||b == '}') { // Escape the literal braces. + sb.append("{"); + sb.append((char)b); + sb.append("}"); + } else + sb.append((char)b); + } + return sb.toString(); + } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e5e227c1/extras/indexingExample/src/main/java/EntityDirectExample.java ---------------------------------------------------------------------- diff --git a/extras/indexingExample/src/main/java/EntityDirectExample.java b/extras/indexingExample/src/main/java/EntityDirectExample.java index ae83520..04b4f74 100644 --- a/extras/indexingExample/src/main/java/EntityDirectExample.java +++ b/extras/indexingExample/src/main/java/EntityDirectExample.java @@ -21,11 +21,6 @@ import java.util.List; -import mvm.rya.accumulo.AccumuloRdfConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.indexing.RyaSailFactory; -import mvm.rya.indexing.accumulo.ConfigUtils; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.TableNotFoundException; @@ -47,6 +42,11 @@ import org.openrdf.repository.sail.SailRepository; import org.openrdf.repository.sail.SailRepositoryConnection; import org.openrdf.sail.Sail; +import mvm.rya.accumulo.AccumuloRdfConfiguration; +import mvm.rya.api.RdfCloudTripleStoreConfiguration; +import mvm.rya.indexing.RyaSailFactory; +import mvm.rya.indexing.accumulo.ConfigUtils; + public class EntityDirectExample { private static final Logger log = Logger.getLogger(EntityDirectExample.class); @@ -59,18 +59,18 @@ public class EntityDirectExample { private static final String INSTANCE = "instance"; private static final String RYA_TABLE_PREFIX = "x_test_triplestore_"; private static final String AUTHS = "U"; - + public static void main(String[] args) throws Exception { Configuration conf = getConf(); conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, PRINT_QUERIES); - + log.info("Creating the tables as root."); SailRepository repository = null; SailRepositoryConnection conn = null; - + try { log.info("Connecting to Indexing Sail Repository."); - + Sail extSail = RyaSailFactory.getInstance(conf); repository = new SailRepository(extSail); repository.initialize(); @@ -80,7 +80,7 @@ public class EntityDirectExample { testAddAndDelete(conn); log.info("Running SAIL/SPARQL Example: Add and Temporal Search"); testAddAndTemporalSearchWithPCJ(conn); - + } finally { log.info("Shutting down"); closeQuietly(conn); @@ -108,10 +108,10 @@ public class EntityDirectExample { } } - - + + public static void testAddAndDelete(SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException, UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException, AccumuloException, AccumuloSecurityException, TableNotFoundException { @@ -127,7 +127,7 @@ public class EntityDirectExample { Update update = conn.prepareUpdate(QueryLanguage.SPARQL, query); update.execute(); - + query = "select ?x {GRAPH <http://updated/test> {?x <http://acme.com/actions/likes> \"A new book\" . "// + " ?x <http://acme.com/actions/likes> \"Avocados\" }}"; CountingResultHandler resultHandler = new CountingResultHandler(); @@ -138,29 +138,28 @@ public class EntityDirectExample { Validate.isTrue(resultHandler.getCount() == 1); resultHandler.resetCount(); - //TODO delete currently not implemented in AccumuloRyaDAO for -// // Delete Data -// query = "DELETE DATA\n" // -// + "{ GRAPH <http://updated/test> {\n" -// + " <http://acme.com/people/Mike> <http://acme.com/actions/likes> \"A new book\" ;\n" -// + " <http://acme.com/actions/likes> \"Avocados\" .\n" + "}}"; -// -// update = conn.prepareUpdate(QueryLanguage.SPARQL, query); -// update.execute(); -// -// query = "select ?x {GRAPH <http://updated/test> {?x <http://acme.com/actions/likes> \"A new book\" . "// -// + " ?x <http://acme.com/actions/likes> \"Avocados\" }}"; -// tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); -// tupleQuery.evaluate(resultHandler); -// log.info("Result count : " + resultHandler.getCount()); -// -// Validate.isTrue(resultHandler.getCount() == 0); + // Delete Data + query = "DELETE DATA\n" // + + "{ GRAPH <http://updated/test> {\n" + + " <http://acme.com/people/Mike> <http://acme.com/actions/likes> \"A new book\" ;\n" + + " <http://acme.com/actions/likes> \"Avocados\" .\n" + "}}"; + + update = conn.prepareUpdate(QueryLanguage.SPARQL, query); + update.execute(); + + query = "select ?x {GRAPH <http://updated/test> {?x <http://acme.com/actions/likes> \"A new book\" . "// + + " ?x <http://acme.com/actions/likes> \"Avocados\" }}"; + tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); + tupleQuery.evaluate(resultHandler); + log.info("Result count : " + resultHandler.getCount()); + + Validate.isTrue(resultHandler.getCount() == 0); } - - - - + + + + private static void testAddAndTemporalSearchWithPCJ(SailRepositoryConnection conn) throws Exception { // create some resources and literals to make statements out of @@ -178,7 +177,7 @@ public class EntityDirectExample { Update update = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlInsert); update.execute(); - + String queryString = "PREFIX pref: <http://www.model/pref#> \n" // + "SELECT ?x ?z \n" // + "WHERE { \n" @@ -187,8 +186,8 @@ public class EntityDirectExample { + " ?x pref:hasProperty2 'property2' . \n"// + " ?x pref:hasProperty3 'property3' . \n"// + "}";// - - + + TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); CountingResultHandler tupleHandler = new CountingResultHandler(); @@ -196,7 +195,7 @@ public class EntityDirectExample { log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); Validate.isTrue(tupleHandler.getBsSize() == 2); - + queryString = "PREFIX pref: <http://www.model/pref#> \n" // + "SELECT ?x ?w ?z \n" // + "WHERE { \n" @@ -204,29 +203,29 @@ public class EntityDirectExample { + " ?x pref:hasProperty4 'property4' . \n"// + " ?x pref:hasProperty5 ?w . \n"// + "}";// - - + + tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); tupleHandler = new CountingResultHandler(); tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); Validate.isTrue(tupleHandler.getBsSize() == 3); - - - queryString = "PREFIX pref: <http://www.model/pref#> " - + "SELECT ?v ?w ?x ?y ?z " - + "WHERE { " - + " ?w a ?z . " - + " ?w pref:hasProperty1 ?v . " - + " ?w pref:hasProperty2 'property2' . " - + " ?w pref:hasProperty3 'property3' . " + + + queryString = "PREFIX pref: <http://www.model/pref#> " + + "SELECT ?v ?w ?x ?y ?z " + + "WHERE { " + + " ?w a ?z . " + + " ?w pref:hasProperty1 ?v . " + + " ?w pref:hasProperty2 'property2' . " + + " ?w pref:hasProperty3 'property3' . " + " ?x a ?z . " - + " ?x pref:hasProperty4 'property4' . " - + " ?x pref:hasProperty5 ?y . " + + " ?x pref:hasProperty4 'property4' . " + + " ?x pref:hasProperty5 ?y . " + "}"; - - + + tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); tupleHandler = new CountingResultHandler(); @@ -234,10 +233,10 @@ public class EntityDirectExample { log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); Validate.isTrue(tupleHandler.getBsSize() == 5); - + } - - + + private static Configuration getConf() { AccumuloRdfConfiguration conf = new AccumuloRdfConfiguration(); @@ -254,7 +253,7 @@ public class EntityDirectExample { return conf; } - + private static class CountingResultHandler implements TupleQueryResultHandler { private int count = 0; @@ -264,11 +263,11 @@ public class EntityDirectExample { public int getCount() { return count; } - + public int getBsSize() { return bindingSize; } - + public void resetBsSize() { bindingSize = 0; bsSizeSet = false; @@ -298,14 +297,10 @@ public class EntityDirectExample { @Override public void handleBoolean(boolean arg0) throws QueryResultHandlerException { - // TODO Auto-generated method stub - } @Override public void handleLinks(List<String> arg0) throws QueryResultHandlerException { - // TODO Auto-generated method stub - } } } http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e5e227c1/extras/indexingExample/src/main/java/RyaDirectExample.java ---------------------------------------------------------------------- diff --git a/extras/indexingExample/src/main/java/RyaDirectExample.java b/extras/indexingExample/src/main/java/RyaDirectExample.java index b3e8dae..0d2df3f 100644 --- a/extras/indexingExample/src/main/java/RyaDirectExample.java +++ b/extras/indexingExample/src/main/java/RyaDirectExample.java @@ -20,13 +20,6 @@ import java.util.List; -import mvm.rya.accumulo.AccumuloRdfConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.indexing.RyaSailFactory; -import mvm.rya.indexing.accumulo.ConfigUtils; -import mvm.rya.indexing.accumulo.geo.GeoConstants; -import mvm.rya.indexing.external.tupleSet.AccumuloIndexSet; - import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; import org.apache.accumulo.core.client.Connector; @@ -60,6 +53,13 @@ import org.openrdf.repository.sail.SailRepositoryConnection; import org.openrdf.sail.Sail; import org.openrdf.sail.SailException; +import mvm.rya.accumulo.AccumuloRdfConfiguration; +import mvm.rya.api.RdfCloudTripleStoreConfiguration; +import mvm.rya.indexing.RyaSailFactory; +import mvm.rya.indexing.accumulo.ConfigUtils; +import mvm.rya.indexing.accumulo.geo.GeoConstants; +import mvm.rya.indexing.external.tupleSet.AccumuloIndexSet; + public class RyaDirectExample { private static final Logger log = Logger.getLogger(RyaDirectExample.class); @@ -72,27 +72,27 @@ public class RyaDirectExample { private static final String INSTANCE = "instance"; private static final String RYA_TABLE_PREFIX = "x_test_triplestore_"; private static final String AUTHS = ""; - - - + + + public static void main(String[] args) throws Exception { Configuration conf = getConf(); conf.setBoolean(ConfigUtils.DISPLAY_QUERY_PLAN, PRINT_QUERIES); - + log.info("Creating the tables as root."); // createTables(addRootConf(conf), conf); SailRepository repository = null; SailRepositoryConnection conn = null; - + try { log.info("Connecting to Indexing Sail Repository."); - + Sail extSail = RyaSailFactory.getInstance(conf); repository = new SailRepository(extSail); repository.initialize(); conn = repository.getConnection(); - + createPCJ(conn); long start = System.currentTimeMillis(); @@ -110,6 +110,12 @@ public class RyaDirectExample { testTemporalFreeGeoSearch(conn); log.info("Running SPARQL Example: Geo, Freetext, and PCJ Search"); testGeoFreetextWithPCJSearch(conn); + log.info("Running SPARQL Example: Delete Temporal Data"); + testDeleteTemporalData(conn); + log.info("Running SPARQL Example: Delete Free Text Data"); + testDeleteFreeTextData(conn); + log.info("Running SPARQL Example: Delete Geo Data"); + testDeleteGeoData(conn); log.info("TIME: " + (System.currentTimeMillis() - start) / 1000.); } finally { @@ -201,10 +207,10 @@ public class RyaDirectExample { Validate.isTrue(resultHandler.getCount() == 0); } - - + + private static void testPCJSearch(SailRepositoryConnection conn) throws Exception { - + String queryString; TupleQuery tupleQuery; CountingResultHandler tupleHandler; @@ -222,7 +228,7 @@ public class RyaDirectExample { tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); - + // ///////////// search for bob queryString = "PREFIX fts: <http://rdf.useekm.com/fts#> "// + "SELECT ?e ?c ?l ?o " // @@ -236,13 +242,13 @@ public class RyaDirectExample { tupleHandler = new CountingResultHandler(); tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); - Validate.isTrue(tupleHandler.getCount() == 2); - + Validate.isTrue(tupleHandler.getCount() == 2); + } - - - + + + private static void testAddAndTemporalSearchWithPCJ(SailRepositoryConnection conn) throws Exception { // create some resources and literals to make statements out of @@ -254,15 +260,16 @@ public class RyaDirectExample { + " time:inXSDDateTime '2001-01-01T04:01:02.000-05:00'^^<http://www.w3.org/2001/XMLSchema#dateTime> ;\n" // 2 seconds + " time:inXSDDateTime \"2001-01-01T01:01:03-08:00\" ;\n" // 3 seconds + " time:inXSDDateTime '2001-01-01T01:01:04-08:00' ;\n" // 4 seconds - + " time:inXSDDateTime '2001-01-01T09:01:05Z' ;\n" - + " time:inXSDDateTime '2006-01-01' ;\n" - + " time:inXSDDateTime '2007-01-01' ;\n" + + " time:inXSDDateTime '2001-01-01T09:01:05Z' ;\n" + + " time:inXSDDateTime '2006-01-01' ;\n" + + " time:inXSDDateTime '2007-01-01' ;\n" + " time:inXSDDateTime '2008-01-01' ; .\n" + "}"; Update update = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlInsert); update.execute(); + // Find all stored dates. String queryString = "PREFIX time: <http://www.w3.org/2006/time#> \n"// + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n"// @@ -271,15 +278,15 @@ public class RyaDirectExample { + " ?event time:inXSDDateTime ?time . \n"// + " FILTER(tempo:after(?time, '2001-01-01T01:01:03-08:00') ) \n"// after 3 seconds + "}";// - - + + TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); CountingResultHandler tupleHandler = new CountingResultHandler(); tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 5); - + // Find all stored dates. queryString = "PREFIX time: <http://www.w3.org/2006/time#> \n"// + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n"// @@ -320,10 +327,6 @@ public class RyaDirectExample { } - - - - private static void testAddAndFreeTextSearchWithPCJ(SailRepositoryConnection conn) throws Exception { // add data to the repository using the SailRepository add methods ValueFactory f = conn.getValueFactory(); @@ -338,7 +341,7 @@ public class RyaDirectExample { uuid = "urn:people:bobss"; conn.add(f.createURI(uuid), RDF.TYPE, person); conn.add(f.createURI(uuid), RDFS.LABEL, f.createLiteral("Bob Snob Hose", "en")); - + String queryString; TupleQuery tupleQuery; CountingResultHandler tupleHandler; @@ -355,7 +358,7 @@ public class RyaDirectExample { tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); - + // ///////////// search for alice and bob queryString = "PREFIX fts: <http://rdf.useekm.com/fts#> "// @@ -370,7 +373,7 @@ public class RyaDirectExample { tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 2); - + // ///////////// search for alice and bob queryString = "PREFIX fts: <http://rdf.useekm.com/fts#> "// + "SELECT ?person ?match " // @@ -385,8 +388,8 @@ public class RyaDirectExample { tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); - - + + // ///////////// search for bob queryString = "PREFIX fts: <http://rdf.useekm.com/fts#> "// + "SELECT ?person ?match ?e ?c ?l ?o " // @@ -421,11 +424,11 @@ public class RyaDirectExample { Update u = conn.prepareUpdate(QueryLanguage.SPARQL, update); u.execute(); - + String queryString; TupleQuery tupleQuery; CountingResultHandler tupleHandler; - + // point outside search ring queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "// @@ -442,7 +445,8 @@ public class RyaDirectExample { tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 0); - + + // point inside search ring queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "// @@ -457,14 +461,14 @@ public class RyaDirectExample { + " ?point geo:asWKT ?wkt . "// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " // + "}";// - + tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); tupleHandler = new CountingResultHandler(); tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); - - + + // point inside search ring with Pre-Computed Join queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "// @@ -479,7 +483,7 @@ public class RyaDirectExample { + " ?point geo:asWKT ?wkt . "// + " FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " // + "}";// - + tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); tupleHandler = new CountingResultHandler(); tupleQuery.evaluate(tupleHandler); @@ -505,7 +509,7 @@ public class RyaDirectExample { tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 0); - + // point inside search ring with different Pre-Computed Join queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "// + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "// @@ -526,12 +530,12 @@ public class RyaDirectExample { log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); } - - - private static void testTemporalFreeGeoSearch(SailRepositoryConnection conn) throws MalformedQueryException, + + + private static void testTemporalFreeGeoSearch(SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException, UpdateExecutionException, TupleQueryResultHandlerException, QueryEvaluationException { - - + + String queryString; TupleQuery tupleQuery; CountingResultHandler tupleHandler; @@ -556,21 +560,21 @@ public class RyaDirectExample { + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . "// + " FILTER(fts:text(?match, \"pal*\")) " // + "}";// - - - + + + tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); tupleHandler = new CountingResultHandler(); tupleQuery.evaluate(tupleHandler); log.info("Result count : " + tupleHandler.getCount()); - Validate.isTrue(tupleHandler.getCount() == 5); - + Validate.isTrue(tupleHandler.getCount() == 5); + } - - - - private static void testGeoFreetextWithPCJSearch(SailRepositoryConnection conn) throws MalformedQueryException, + + + + private static void testGeoFreetextWithPCJSearch(SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException { // ring outside point String queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "// @@ -596,12 +600,122 @@ public class RyaDirectExample { log.info("Result count : " + tupleHandler.getCount()); Validate.isTrue(tupleHandler.getCount() == 1); } - - - - private static void createPCJ(SailRepositoryConnection conn) + + + private static void testDeleteTemporalData(SailRepositoryConnection conn) throws Exception { + // Delete all stored dates + String sparqlDelete = "PREFIX time: <http://www.w3.org/2006/time#>\n" + + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n"// + + "DELETE {\n" // + + " ?event time:inXSDDateTime ?time . \n" + + "}\n" + + "WHERE { \n" + + " ?event time:inXSDDateTime ?time . \n"// + + "}";// + + Update deleteUpdate = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlDelete); + deleteUpdate.execute(); + + + // Find all stored dates. + String queryString = "PREFIX time: <http://www.w3.org/2006/time#> \n"// + + "PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> \n"// + + "SELECT ?event ?time \n" // + + "WHERE { \n" + + " ?event time:inXSDDateTime ?time . \n"// + + " FILTER(tempo:after(?time, '2001-01-01T01:01:03-08:00') ) \n"// after 3 seconds + + "}";// + + + CountingResultHandler tupleHandler = new CountingResultHandler(); + TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); + tupleQuery.evaluate(tupleHandler); + log.info("Result count : " + tupleHandler.getCount()); + Validate.isTrue(tupleHandler.getCount() == 0); + } + + + private static void testDeleteFreeTextData(SailRepositoryConnection conn) throws Exception { + // Delete data from the repository using the SailRepository remove methods + ValueFactory f = conn.getValueFactory(); + URI person = f.createURI("http://example.org/ontology/Person"); + + String uuid; + + uuid = "urn:people:alice"; + conn.remove(f.createURI(uuid), RDF.TYPE, person); + conn.remove(f.createURI(uuid), RDFS.LABEL, f.createLiteral("Alice Palace Hose", f.createURI("xsd:string"))); + + uuid = "urn:people:bobss"; + conn.remove(f.createURI(uuid), RDF.TYPE, person); + conn.remove(f.createURI(uuid), RDFS.LABEL, f.createLiteral("Bob Snob Hose", "en")); + + conn.remove(person, RDFS.LABEL, f.createLiteral("label", "en")); + + String queryString; + TupleQuery tupleQuery; + CountingResultHandler tupleHandler; + + // Find all + queryString = "PREFIX fts: <http://rdf.useekm.com/fts#> "// + + "SELECT ?person ?match " // + + "{" // + + " ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . "// + + " ?person a <http://example.org/ontology/Person> . "// + + "}";// + tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); + tupleHandler = new CountingResultHandler(); + tupleQuery.evaluate(tupleHandler); + log.info("Result count : " + tupleHandler.getCount()); + Validate.isTrue(tupleHandler.getCount() == 0); + } + + + private static void testDeleteGeoData(SailRepositoryConnection conn) throws Exception { + // Delete all stored points + String sparqlDelete = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "// + + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "// + + "DELETE {\n" // + + " ?feature a geo:Feature . "// + + " ?feature geo:hasGeometry ?point . "// + + " ?point a geo:Point . "// + + " ?point geo:asWKT ?wkt . "// + + "}\n" + + "WHERE { \n" + + " ?feature a geo:Feature . "// + + " ?feature geo:hasGeometry ?point . "// + + " ?point a geo:Point . "// + + " ?point geo:asWKT ?wkt . "// + + "}";// + + Update deleteUpdate = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlDelete); + deleteUpdate.execute(); + + String queryString; + TupleQuery tupleQuery; + CountingResultHandler tupleHandler; + + // Find all stored points + queryString = "PREFIX geo: <http://www.opengis.net/ont/geosparql#> "// + + "PREFIX geof: <http://www.opengis.net/def/function/geosparql/> "// + + "SELECT ?feature ?point ?wkt " // + + "{" // + + " ?feature a geo:Feature . "// + + " ?feature geo:hasGeometry ?point . "// + + " ?point a geo:Point . "// + + " ?point geo:asWKT ?wkt . "// + + "}";// + tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString); + tupleHandler = new CountingResultHandler(); + tupleQuery.evaluate(tupleHandler); + log.info("Result count : " + tupleHandler.getCount()); + Validate.isTrue(tupleHandler.getCount() == 0); + } + + + private static void createPCJ(SailRepositoryConnection conn) throws RepositoryException, AccumuloException, AccumuloSecurityException, TableExistsException { - + String queryString1 = ""// + "SELECT ?e ?c ?l ?o " // + "{" // @@ -609,7 +723,7 @@ public class RyaDirectExample { + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + " ?e <uri:talksTo> ?o . "// + "}";// - + String queryString2 = ""// + "SELECT ?e ?c ?l ?o " // + "{" // @@ -617,8 +731,8 @@ public class RyaDirectExample { + " ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "// + " ?e <uri:talksTo> ?o . "// + "}";// - - + + URI obj,subclass,talksTo; URI person = new URIImpl("urn:people:alice"); URI feature = new URIImpl("urn:feature"); @@ -632,33 +746,24 @@ public class RyaDirectExample { conn.add(sub, RDF.TYPE, subclass); conn.add(sub, RDFS.LABEL, new LiteralImpl("label")); conn.add(sub, talksTo, obj); - - AccumuloIndexSet ais1 = null; - AccumuloIndexSet ais2 = null; + + AccumuloIndexSet ais1 = null; + AccumuloIndexSet ais2 = null; String tablename1 = RYA_TABLE_PREFIX + "INDEX_1"; String tablename2 = RYA_TABLE_PREFIX + "INDEX_2"; Connector accCon = new MockInstance(INSTANCE).getConnector("root", new PasswordToken("".getBytes())); accCon.tableOperations().create(tablename1); accCon.tableOperations().create(tablename2); - + try { ais1 = new AccumuloIndexSet(queryString1, conn, accCon, tablename1); ais2 = new AccumuloIndexSet(queryString2, conn, accCon, tablename2); - } catch (MalformedQueryException e) { - e.printStackTrace(); - } catch (SailException e) { - e.printStackTrace(); - } catch (QueryEvaluationException e) { - e.printStackTrace(); - } catch (MutationsRejectedException e) { - e.printStackTrace(); - } catch (TableNotFoundException e) { - e.printStackTrace(); + } catch (MalformedQueryException | SailException | QueryEvaluationException | MutationsRejectedException | TableNotFoundException e) { + log.error("Error creating Accumulo Index", e); } - } - + private static class CountingResultHandler implements TupleQueryResultHandler { private int count = 0; @@ -687,14 +792,10 @@ public class RyaDirectExample { @Override public void handleBoolean(boolean arg0) throws QueryResultHandlerException { - // TODO Auto-generated method stub - } @Override public void handleLinks(List<String> arg0) throws QueryResultHandlerException { - // TODO Auto-generated method stub - } } }