You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rya.apache.org by ca...@apache.org on 2018/01/09 21:48:56 UTC

[39/50] [abbrv] incubator-rya git commit: RYA-377 After temporal isntant function

RYA-377 After temporal isntant function


Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/9e02a541
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/9e02a541
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/9e02a541

Branch: refs/heads/master
Commit: 9e02a541c848defd027ff737f6149b66b73273b2
Parents: 5603a10
Author: Andrew Smith <sm...@gmail.com>
Authored: Fri Dec 1 13:30:25 2017 -0500
Committer: caleb <ca...@parsons.com>
Committed: Tue Jan 9 15:13:01 2018 -0500

----------------------------------------------------------------------
 .../function/temporal/AfterTemporalInstant.java | 46 ++++++++++++
 ...f.query.algebra.evaluation.function.Function |  1 +
 .../temporal/AfterTemporalFunctionsTest.java    | 75 ++++++++++++++++++++
 .../AggregationProcessorSupplier.java           |  2 +-
 .../processors/filter/TemporalFilterIT.java     | 72 ++++++++++++++++++-
 5 files changed, 193 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e02a541/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/AfterTemporalInstant.java
----------------------------------------------------------------------
diff --git a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/AfterTemporalInstant.java b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/AfterTemporalInstant.java
new file mode 100644
index 0000000..38c02ba
--- /dev/null
+++ b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/AfterTemporalInstant.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.rya.api.function.temporal;
+
+import java.time.ZonedDateTime;
+import java.util.Objects;
+
+import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
+import edu.umd.cs.findbugs.annotations.NonNull;
+
+/**
+ * Filter function in a SPARQL query used to filter when a point of time is after another.
+ */
+@DefaultAnnotation(NonNull.class)
+public class AfterTemporalInstant extends TemporalRelationFunction {
+    public static final String URI = BASE_URI + "after";
+
+    @Override
+    public String getURI() {
+        return URI;
+    }
+
+    @Override
+    protected boolean relation(final ZonedDateTime d1, final ZonedDateTime d2) {
+        Objects.requireNonNull(d1);
+        Objects.requireNonNull(d2);
+        return d1.isAfter(d2);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e02a541/common/rya.api.function/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
----------------------------------------------------------------------
diff --git a/common/rya.api.function/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function b/common/rya.api.function/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
index 3cb1c56..2ec01d5 100644
--- a/common/rya.api.function/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
+++ b/common/rya.api.function/src/main/resources/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function
@@ -18,3 +18,4 @@
 #
 org.apache.rya.api.function.temporal.EqualsTemporal
 org.apache.rya.api.function.temporal.BeforeTemporalInstant
+org.apache.rya.api.function.temporal.AfterTemporalInstant

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e02a541/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/AfterTemporalFunctionsTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/AfterTemporalFunctionsTest.java b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/AfterTemporalFunctionsTest.java
new file mode 100644
index 0000000..f5f18f7
--- /dev/null
+++ b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/AfterTemporalFunctionsTest.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.rya.api.function.temporal;
+
+import static org.junit.Assert.assertEquals;
+
+import java.time.ZonedDateTime;
+
+import org.junit.Test;
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.model.impl.ValueFactoryImpl;
+
+public class AfterTemporalFunctionsTest {
+    private static final ZonedDateTime TIME = ZonedDateTime.parse("2015-12-30T12:00:00Z");
+    private static final ZonedDateTime TIME_10 = ZonedDateTime.parse("2015-12-30T12:00:10Z");
+    private static final ZonedDateTime TIME_20 = ZonedDateTime.parse("2015-12-30T12:00:20Z");
+
+    final ValueFactory VF = ValueFactoryImpl.getInstance();
+
+    @Test
+    public void testAfter_same() throws Exception {
+        final AfterTemporalInstant function = new AfterTemporalInstant();
+
+        // 2 times equal
+        final Value[] args = new Value[2];
+        args[0] = VF.createLiteral(TIME.toString());
+        args[1] = VF.createLiteral(TIME.toString());
+        final Value rez = function.evaluate(VF, args);
+
+        assertEquals(VF.createLiteral(false), rez);
+    }
+
+    @Test
+    public void testAfter_before() throws Exception {
+        final AfterTemporalInstant function = new AfterTemporalInstant();
+
+        // 2 times equal
+        final Value[] args = new Value[2];
+        args[0] = VF.createLiteral(TIME.toString());
+        args[1] = VF.createLiteral(TIME_10.toString());
+        final Value rez = function.evaluate(VF, args);
+
+        assertEquals(VF.createLiteral(false), rez);
+    }
+
+    @Test
+    public void testAfter_after() throws Exception {
+        final AfterTemporalInstant function = new AfterTemporalInstant();
+
+        // 2 times equal
+        final Value[] args = new Value[2];
+        args[0] = VF.createLiteral(TIME_20.toString());
+        args[1] = VF.createLiteral(TIME.toString());
+        final Value rez = function.evaluate(VF, args);
+
+        assertEquals(VF.createLiteral(true), rez);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e02a541/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/processors/aggregation/AggregationProcessorSupplier.java
----------------------------------------------------------------------
diff --git a/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/processors/aggregation/AggregationProcessorSupplier.java b/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/processors/aggregation/AggregationProcessorSupplier.java
index c8e1049..c101914 100644
--- a/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/processors/aggregation/AggregationProcessorSupplier.java
+++ b/extras/rya.streams/kafka/src/main/java/org/apache/rya/streams/kafka/processors/aggregation/AggregationProcessorSupplier.java
@@ -39,7 +39,7 @@ import org.openrdf.query.algebra.Group;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.beust.jcommander.internal.Lists;
+import com.google.common.collect.Lists;
 
 import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
 import edu.umd.cs.findbugs.annotations.NonNull;

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/9e02a541/extras/rya.streams/kafka/src/test/java/org/apache/rya/streams/kafka/processors/filter/TemporalFilterIT.java
----------------------------------------------------------------------
diff --git a/extras/rya.streams/kafka/src/test/java/org/apache/rya/streams/kafka/processors/filter/TemporalFilterIT.java b/extras/rya.streams/kafka/src/test/java/org/apache/rya/streams/kafka/processors/filter/TemporalFilterIT.java
index 837b57b..cac9559 100644
--- a/extras/rya.streams/kafka/src/test/java/org/apache/rya/streams/kafka/processors/filter/TemporalFilterIT.java
+++ b/extras/rya.streams/kafka/src/test/java/org/apache/rya/streams/kafka/processors/filter/TemporalFilterIT.java
@@ -74,8 +74,8 @@ public class TemporalFilterIT {
             }
         }
 
-        // There are 2 temporal functions registered, ensure that there are 2.
-        assertEquals(2, count);
+        // There are 3 temporal functions registered, ensure that there are 3.
+        assertEquals(3, count);
     }
 
     @Test
@@ -111,6 +111,74 @@ public class TemporalFilterIT {
         // Run the test.
         RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, 2000, statements, expected, VisibilityBindingSetDeserializer.class);
     }
+    
+    @Test
+    public void showBeforeWorks() throws Exception {
+        // Enumerate some topics that will be re-used
+        final String ryaInstance = UUID.randomUUID().toString();
+        final UUID queryId = UUID.randomUUID();
+        final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
+        final String resultsTopic = KafkaTopics.queryResultsTopic(queryId);
+
+        // Get the RDF model objects that will be used to build the query.
+        final String sparql =
+                "PREFIX time: <http://www.w3.org/2006/time/> \n"
+            + "PREFIX tempf: <http://rya.apache.org/ns/temporal/>\n"
+            + "SELECT * \n"
+            + "WHERE { \n"
+            + "  <urn:time> time:atTime ?date .\n"
+            + " FILTER(tempf:before(?date, \"" + TIME_10.toString() + "\")) "
+            + "}";
+        // Setup a topology.
+        final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
+
+        // Create the statements that will be input into the query.
+        final ValueFactory vf = new ValueFactoryImpl();
+        final List<VisibilityStatement> statements = getStatements();
+
+        // Make the expected results.
+        final Set<VisibilityBindingSet> expected = new HashSet<>();
+        final MapBindingSet bs = new MapBindingSet();
+        bs.addBinding("date", vf.createLiteral(TIME.toString()));
+        expected.add( new VisibilityBindingSet(bs, "a") );
+
+        // Run the test.
+        RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, 2000, statements, expected, VisibilityBindingSetDeserializer.class);
+    }
+    
+    @Test
+    public void showAfterWorks() throws Exception {
+        // Enumerate some topics that will be re-used
+        final String ryaInstance = UUID.randomUUID().toString();
+        final UUID queryId = UUID.randomUUID();
+        final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
+        final String resultsTopic = KafkaTopics.queryResultsTopic(queryId);
+
+        // Get the RDF model objects that will be used to build the query.
+        final String sparql =
+                "PREFIX time: <http://www.w3.org/2006/time/> \n"
+            + "PREFIX tempf: <http://rya.apache.org/ns/temporal/>\n"
+            + "SELECT * \n"
+            + "WHERE { \n"
+            + "  <urn:time> time:atTime ?date .\n"
+            + " FILTER(tempf:after(?date, \"" + TIME_10.toString() + "\")) "
+            + "}";
+        // Setup a topology.
+        final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
+
+        // Create the statements that will be input into the query.
+        final ValueFactory vf = new ValueFactoryImpl();
+        final List<VisibilityStatement> statements = getStatements();
+
+        // Make the expected results.
+        final Set<VisibilityBindingSet> expected = new HashSet<>();
+        final MapBindingSet bs = new MapBindingSet();
+        bs.addBinding("date", vf.createLiteral(TIME_20.toString()));
+        expected.add( new VisibilityBindingSet(bs, "a") );
+
+        // Run the test.
+        RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, 2000, statements, expected, VisibilityBindingSetDeserializer.class);
+    }
 
     private List<VisibilityStatement> getStatements() throws Exception {
         final List<VisibilityStatement> statements = new ArrayList<>();