RYA-377 Before Instant Function
diff --git a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/BeforeTemporalInstant.java b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/BeforeTemporalInstant.java
new file mode 100644
index 0000000..c9f31c3
--- /dev/null
+++ b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/BeforeTemporalInstant.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 before another.
+ */
+@DefaultAnnotation(NonNull.class)
+public class BeforeTemporalInstant extends TemporalRelationFunction {
+ public static final String URI = BASE_URI + "before";
+
+ @Override
+ public String getURI() {
+ return URI;
+ }
+
+ @Override
+ protected boolean relation(final ZonedDateTime d1, final ZonedDateTime d2) {
+ Objects.requireNonNull(d1);
+ Objects.requireNonNull(d2);
+ return d1.isBefore(d2);
+ }
+}
diff --git a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporal.java b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporal.java
index c8a6041..07391c8 100644
--- a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporal.java
+++ b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporal.java
@@ -25,6 +25,9 @@
import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
import edu.umd.cs.findbugs.annotations.NonNull;
+import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
+import edu.umd.cs.findbugs.annotations.NonNull;
+
/**
* Filter function in a SPARQL query used to filter equality over time.
*/
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 475b9dd..3cb1c56 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
@@ -1,3 +1,4 @@
+#
# 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
@@ -14,4 +15,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-org.apache.rya.api.function.temporal.EqualsTemporal
\ No newline at end of file
+#
+org.apache.rya.api.function.temporal.EqualsTemporal
+org.apache.rya.api.function.temporal.BeforeTemporalInstant
diff --git a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/TemporalFunctionsTest.java b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/BeforeTemporalFunctionsTest.java
similarity index 80%
copy from common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/TemporalFunctionsTest.java
copy to common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/BeforeTemporalFunctionsTest.java
index e0dabe1..1b15035 100644
--- a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/TemporalFunctionsTest.java
+++ b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/BeforeTemporalFunctionsTest.java
@@ -27,7 +27,7 @@
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.ValueFactoryImpl;
-public class TemporalFunctionsTest {
+public class BeforeTemporalFunctionsTest {
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");
@@ -35,8 +35,8 @@
final ValueFactory VF = ValueFactoryImpl.getInstance();
@Test
- public void testEquals_equal() throws Exception {
- final EqualsTemporal function = new EqualsTemporal();
+ public void testBefore_same() throws Exception {
+ final BeforeTemporalInstant function = new BeforeTemporalInstant();
// 2 times equal
final Value[] args = new Value[2];
@@ -44,30 +44,30 @@
args[1] = VF.createLiteral(TIME.toString());
final Value rez = function.evaluate(VF, args);
- assertEquals(VF.createLiteral(true), rez);
+ assertEquals(VF.createLiteral(false), rez);
}
@Test
- public void testEquals_before() throws Exception {
- final EqualsTemporal function = new EqualsTemporal();
+ public void testBefore_before() throws Exception {
+ final BeforeTemporalInstant function = new BeforeTemporalInstant();
- // first time is before
+ // 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);
+ assertEquals(VF.createLiteral(true), rez);
}
@Test
- public void testEquals_after() throws Exception {
- final EqualsTemporal function = new EqualsTemporal();
+ public void testBefore_after() throws Exception {
+ final BeforeTemporalInstant function = new BeforeTemporalInstant();
- // first time is after
+ // 2 times equal
final Value[] args = new Value[2];
args[0] = VF.createLiteral(TIME_20.toString());
- args[1] = VF.createLiteral(TIME_10.toString());
+ args[1] = VF.createLiteral(TIME.toString());
final Value rez = function.evaluate(VF, args);
assertEquals(VF.createLiteral(false), rez);
diff --git a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/TemporalFunctionsTest.java b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/EqualsTemporalFunctionsTest.java
similarity index 98%
rename from common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/TemporalFunctionsTest.java
rename to common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/EqualsTemporalFunctionsTest.java
index e0dabe1..f32904a 100644
--- a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/TemporalFunctionsTest.java
+++ b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/EqualsTemporalFunctionsTest.java
@@ -27,7 +27,7 @@
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.ValueFactoryImpl;
-public class TemporalFunctionsTest {
+public class EqualsTemporalFunctionsTest {
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");
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 2bc98ca..837b57b 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
@@ -57,8 +57,9 @@
public class TemporalFilterIT {
private static final ValueFactory vf = new ValueFactoryImpl();
private static final String TEMPORAL = "http://rya.apache.org/ns/temporal";
- private static final ZonedDateTime time1 = ZonedDateTime.parse("2015-12-30T12:00:00Z");
- private static final ZonedDateTime time2 = ZonedDateTime.parse("2015-12-30T12:00:10Z");
+ 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");
@Rule
public KafkaTestInstanceRule kafka = new KafkaTestInstanceRule(false);
@@ -73,12 +74,12 @@
}
}
- // There are 1 temporal functions registered, ensure that there are 1.
- assertEquals(1, count);
+ // There are 2 temporal functions registered, ensure that there are 2.
+ assertEquals(2, count);
}
@Test
- public void showProcessorWorks() throws Exception {
+ public void showEqualsWorks() throws Exception {
// Enumerate some topics that will be re-used
final String ryaInstance = UUID.randomUUID().toString();
final UUID queryId = UUID.randomUUID();
@@ -88,12 +89,12 @@
// 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:equals(?date, \"" + time1.toString() + "\")) "
- + "}";
+ + "PREFIX tempf: <http://rya.apache.org/ns/temporal/>\n"
+ + "SELECT * \n"
+ + "WHERE { \n"
+ + " <urn:time> time:atTime ?date .\n"
+ + " FILTER(tempf:equals(?date, \"" + TIME.toString() + "\")) "
+ + "}";
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
@@ -104,7 +105,7 @@
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
final MapBindingSet bs = new MapBindingSet();
- bs.addBinding("date", vf.createLiteral(time1.toString()));
+ bs.addBinding("date", vf.createLiteral(TIME.toString()));
expected.add( new VisibilityBindingSet(bs, "a") );
// Run the test.
@@ -113,8 +114,9 @@
private List<VisibilityStatement> getStatements() throws Exception {
final List<VisibilityStatement> statements = new ArrayList<>();
- statements.add(new VisibilityStatement(statement(time1), "a"));
- statements.add(new VisibilityStatement(statement(time2), "a"));
+ statements.add(new VisibilityStatement(statement(TIME), "a"));
+ statements.add(new VisibilityStatement(statement(TIME_10), "a"));
+ statements.add(new VisibilityStatement(statement(TIME_20), "a"));
return statements;
}
@@ -124,4 +126,4 @@
final Value object = vf.createLiteral(time.toString());
return new StatementImpl(subject, predicate, object);
}
-}
\ No newline at end of file
+}