Search in sources :

Example 21 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.

the class TemporalIntervalTest method relationsTest.

@Test
public void relationsTest() throws Exception {
    TemporalInterval ti01 = new TemporalInterval(// 
    new TemporalInstantRfc3339(2015, 12, 30, 12, 59, 59), // 
    new TemporalInstantRfc3339(2016, 12, 30, 13, 00, 00));
    TemporalInterval ti02 = new TemporalInterval(// 
    new TemporalInstantRfc3339(2015, 12, 30, 12, 59, 59), // 
    new TemporalInstantRfc3339(2016, 12, 30, 13, 00, 00));
    Assert.assertTrue("same constructor parameters, should be equal.", ti01.equals(ti02));
    Assert.assertTrue("same constructor parameters, should compare 0 equal.", 0 == ti01.compareTo(ti02));
}
Also used : TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInterval(org.apache.rya.indexing.TemporalInterval) Test(org.junit.Test)

Example 22 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.

the class TemporalIntervalTest method hashTest.

@Test
public void hashTest() throws Exception {
    // Use MAX to see how it handles overflowing values.  Should silently go negative.
    int hashcode01Same = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(Integer.MAX_VALUE / 2)), new TemporalInstantRfc3339(new DateTime(Integer.MAX_VALUE)))).hashCode();
    int hashcode02Same = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(Integer.MAX_VALUE / 2)), new TemporalInstantRfc3339(new DateTime(Integer.MAX_VALUE)))).hashCode();
    int hashcode03Diff = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(Integer.MAX_VALUE / 2)), new TemporalInstantRfc3339(new DateTime(Integer.MAX_VALUE)))).hashCode();
    int hashcode04Diff = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(Integer.MIN_VALUE)), new TemporalInstantRfc3339(new DateTime(Integer.MIN_VALUE)))).hashCode();
    int hashcode05Diff = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(Integer.MAX_VALUE)), new TemporalInstantRfc3339(new DateTime(Integer.MAX_VALUE)))).hashCode();
    int hashcode06Diff = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(0)), new TemporalInstantRfc3339(new DateTime(0)))).hashCode();
    int hashcode07Diff = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(1000)), new TemporalInstantRfc3339(new DateTime(1000)))).hashCode();
    int hashcode08Diff = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(0)), new TemporalInstantRfc3339(new DateTime(1000)))).hashCode();
    int hashcode09Diff = (new TemporalInterval((TemporalInstantRfc3339.getMinimumInstance()), (TemporalInstantRfc3339.getMaximumInstance()))).hashCode();
    int hashcode10Diff = (new TemporalInterval(new TemporalInstantRfc3339(new DateTime(0)), (TemporalInstantRfc3339.getMaximumInstance()))).hashCode();
    Assert.assertEquals("Same input should produce same hashcode. (always!)", hashcode01Same, hashcode02Same);
    Assert.assertTrue("Different small input should produce different hashcode. (usually!) hashcodes:" + hashcode03Diff + " " + hashcode04Diff + " " + hashcode03Diff + " " + hashcode05Diff, hashcode03Diff != hashcode04Diff && hashcode03Diff != hashcode05Diff);
    Assert.assertTrue("Different large input should produce different hashcode. (usually!) hashcodes:" + hashcode06Diff + " " + hashcode07Diff + " " + hashcode06Diff + " " + hashcode08Diff + " key for date 0= " + (new TemporalInstantRfc3339(new DateTime(0))).getAsKeyString() + " key for date 1000= " + (new TemporalInstantRfc3339(new DateTime(1000))).getAsKeyString(), hashcode06Diff != hashcode07Diff && hashcode06Diff != hashcode08Diff);
    Assert.assertTrue("Different max and min input should produce different hashcode. (usually!) hashcodes:" + hashcode09Diff + " != " + hashcode10Diff + "fyi: key for date max= " + (TemporalInstantRfc3339.getMaximumInstance()).getAsKeyString() + " key for date min= " + (TemporalInstantRfc3339.getMinimumInstance()).getAsKeyString(), hashcode09Diff != hashcode10Diff);
}
Also used : TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) TemporalInterval(org.apache.rya.indexing.TemporalInterval) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 23 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.

the class AccumuloTemporalIndexer method storeStatement.

/**
 * Store a statement in the index if it meets the criterion: Object should be
 * a literal and one of the validPredicates from the configuration.
 * If it does not meet the criteria, it is silently ignored.
 * logs a warning if the object is not parse-able.
 * Attempts to parse with calendarValue = literalValue.calendarValue()
 * if that fails, tries: org.joda.time.DateTime.parse() .
 * T O D O parse an interval using multiple predicates for same subject -- ontology dependent.
 */
private void storeStatement(final Statement statement) throws IOException, IllegalArgumentException {
    Objects.requireNonNull(temporalIndexBatchWriter, "This is not initialized for writing.  Must call setMultiTableBatchWriter() and init().");
    // if the predicate list is empty, accept all predicates.
    // Otherwise, make sure the predicate is on the "valid" list
    final boolean isValidPredicate = validPredicates == null || validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
    if (!isValidPredicate || !(statement.getObject() instanceof Literal)) {
        return;
    }
    // 0 begin, 1 end of interval
    final DateTime[] indexDateTimes = new DateTime[2];
    extractDateTime(statement, indexDateTimes);
    if (indexDateTimes[0] == null) {
        return;
    }
    if (!this.isInit)
        throw new RuntimeException("Method .init() was not called (or failed) before attempting to store statements.");
    // Add this as an instant, or interval.
    try {
        if (indexDateTimes[1] != null) {
            final TemporalInterval interval = new TemporalInterval(new TemporalInstantRfc3339(indexDateTimes[0]), new TemporalInstantRfc3339(indexDateTimes[1]));
            addInterval(temporalIndexBatchWriter, interval, statement);
        } else {
            final TemporalInstant instant = new TemporalInstantRfc3339(indexDateTimes[0]);
            addInstant(temporalIndexBatchWriter, instant, statement);
        }
    } catch (final MutationsRejectedException e) {
        throw new IOException("While adding interval/instant for statement =" + statement, e);
    }
}
Also used : Literal(org.openrdf.model.Literal) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) IOException(java.io.IOException) TemporalInstant(org.apache.rya.indexing.TemporalInstant) TemporalInterval(org.apache.rya.indexing.TemporalInterval) DateTime(org.joda.time.DateTime) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 24 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.

the class MongoEventStorageIT method delete.

@Test
public void delete() throws Exception {
    final Geometry geo = GF.createPoint(new Coordinate(10, 10));
    final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
    // An Event that will be stored.
    final Event event = Event.builder().setSubject(new RyaURI("urn:event/002")).setGeometry(geo).setTemporalInstant(instant).build();
    // Create it.
    final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    storage.create(event);
    // Delete it.
    final boolean deleted = storage.delete(new RyaURI("urn:event/002"));
    // Verify a document was deleted.
    assertTrue(deleted);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Event(org.apache.rya.indexing.geotemporal.model.Event) TemporalInstant(org.apache.rya.indexing.TemporalInstant) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Example 25 with TemporalInstantRfc3339

use of org.apache.rya.indexing.TemporalInstantRfc3339 in project incubator-rya by apache.

the class MongoEventStorageIT method update_differentSubjects.

@Test(expected = EventStorageException.class)
public void update_differentSubjects() throws Exception {
    final EventStorage storage = new MongoEventStorage(super.getMongoClient(), RYA_INSTANCE_NAME);
    final Geometry geo = GF.createPoint(new Coordinate(10, 10));
    final TemporalInstant instant = new TemporalInstantRfc3339(DateTime.now());
    // Two objects that do not have the same Subjects.
    final Event old = Event.builder().setSubject(new RyaURI("urn:event/001")).setGeometry(geo).setTemporalInstant(instant).build();
    final Event updated = Event.builder().setSubject(new RyaURI("urn:event/002")).setGeometry(geo).setTemporalInstant(instant).build();
    // The update will fail.
    storage.update(old, updated);
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) RyaURI(org.apache.rya.api.domain.RyaURI) Coordinate(com.vividsolutions.jts.geom.Coordinate) TemporalInstantRfc3339(org.apache.rya.indexing.TemporalInstantRfc3339) Event(org.apache.rya.indexing.geotemporal.model.Event) TemporalInstant(org.apache.rya.indexing.TemporalInstant) EventStorage(org.apache.rya.indexing.geotemporal.storage.EventStorage) Test(org.junit.Test)

Aggregations

TemporalInstantRfc3339 (org.apache.rya.indexing.TemporalInstantRfc3339)34 Test (org.junit.Test)26 TemporalInstant (org.apache.rya.indexing.TemporalInstant)21 RyaURI (org.apache.rya.api.domain.RyaURI)15 Geometry (com.vividsolutions.jts.geom.Geometry)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)12 TemporalInterval (org.apache.rya.indexing.TemporalInterval)12 EventStorage (org.apache.rya.indexing.geotemporal.storage.EventStorage)11 URI (org.openrdf.model.URI)11 Event (org.apache.rya.indexing.geotemporal.model.Event)9 Value (org.openrdf.model.Value)9 ValueFactory (org.openrdf.model.ValueFactory)9 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)9 EventQueryNode (org.apache.rya.indexing.geotemporal.model.EventQueryNode)7 DateTime (org.joda.time.DateTime)5 MongoEventStorage (org.apache.rya.indexing.geotemporal.mongo.MongoEventStorage)4 BindingSet (org.openrdf.query.BindingSet)4 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)4 MapBindingSet (org.openrdf.query.impl.MapBindingSet)4 IOException (java.io.IOException)3