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:49:03 UTC
[46/50] [abbrv] incubator-rya git commit: RYA-377 Before Instant
Function
RYA-377 Before Instant 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/2957c75a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/2957c75a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/2957c75a
Branch: refs/heads/master
Commit: 2957c75a930396f86b606be8f7373dd3adcaf46c
Parents: bc92591
Author: Andrew Smith <sm...@gmail.com>
Authored: Fri Dec 1 12:40:27 2017 -0500
Committer: caleb <ca...@parsons.com>
Committed: Tue Jan 9 15:13:01 2018 -0500
----------------------------------------------------------------------
.../temporal/BeforeTemporalInstant.java | 46 ++++++++++++
.../api/function/temporal/EqualsTemporal.java | 3 +
...f.query.algebra.evaluation.function.Function | 5 +-
.../temporal/BeforeTemporalFunctionsTest.java | 75 ++++++++++++++++++++
.../temporal/EqualsTemporalFunctionsTest.java | 75 ++++++++++++++++++++
.../temporal/TemporalFunctionsTest.java | 75 --------------------
.../processors/filter/TemporalFilterIT.java | 32 +++++----
7 files changed, 220 insertions(+), 91 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2957c75a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/BeforeTemporalInstant.java
----------------------------------------------------------------------
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);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2957c75a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporal.java
----------------------------------------------------------------------
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 java.util.Objects;
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.
*/
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2957c75a/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 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
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2957c75a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/BeforeTemporalFunctionsTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/BeforeTemporalFunctionsTest.java b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/BeforeTemporalFunctionsTest.java
new file mode 100644
index 0000000..1b15035
--- /dev/null
+++ b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/BeforeTemporalFunctionsTest.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 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");
+
+ final ValueFactory VF = ValueFactoryImpl.getInstance();
+
+ @Test
+ public void testBefore_same() throws Exception {
+ final BeforeTemporalInstant function = new BeforeTemporalInstant();
+
+ // 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 testBefore_before() throws Exception {
+ final BeforeTemporalInstant function = new BeforeTemporalInstant();
+
+ // 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(true), rez);
+ }
+
+ @Test
+ public void testBefore_after() throws Exception {
+ final BeforeTemporalInstant function = new BeforeTemporalInstant();
+
+ // 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(false), rez);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2957c75a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/EqualsTemporalFunctionsTest.java
----------------------------------------------------------------------
diff --git a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/EqualsTemporalFunctionsTest.java b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/EqualsTemporalFunctionsTest.java
new file mode 100644
index 0000000..f32904a
--- /dev/null
+++ b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/EqualsTemporalFunctionsTest.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 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");
+
+ final ValueFactory VF = ValueFactoryImpl.getInstance();
+
+ @Test
+ public void testEquals_equal() throws Exception {
+ final EqualsTemporal function = new EqualsTemporal();
+
+ // 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(true), rez);
+ }
+
+ @Test
+ public void testEquals_before() throws Exception {
+ final EqualsTemporal function = new EqualsTemporal();
+
+ // first time is before
+ 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 testEquals_after() throws Exception {
+ final EqualsTemporal function = new EqualsTemporal();
+
+ // first time is after
+ final Value[] args = new Value[2];
+ args[0] = VF.createLiteral(TIME_20.toString());
+ args[1] = VF.createLiteral(TIME_10.toString());
+ final Value rez = function.evaluate(VF, args);
+
+ assertEquals(VF.createLiteral(false), rez);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2957c75a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/TemporalFunctionsTest.java
----------------------------------------------------------------------
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/TemporalFunctionsTest.java
deleted file mode 100644
index e0dabe1..0000000
--- a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/TemporalFunctionsTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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 TemporalFunctionsTest {
- 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 testEquals_equal() throws Exception {
- final EqualsTemporal function = new EqualsTemporal();
-
- // 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(true), rez);
- }
-
- @Test
- public void testEquals_before() throws Exception {
- final EqualsTemporal function = new EqualsTemporal();
-
- // first time is before
- 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 testEquals_after() throws Exception {
- final EqualsTemporal function = new EqualsTemporal();
-
- // first time is after
- final Value[] args = new Value[2];
- args[0] = VF.createLiteral(TIME_20.toString());
- args[1] = VF.createLiteral(TIME_10.toString());
- final Value rez = function.evaluate(VF, args);
-
- assertEquals(VF.createLiteral(false), rez);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/2957c75a/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 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 @@ import org.openrdf.query.impl.MapBindingSet;
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 @@ public class TemporalFilterIT {
}
}
- // 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 @@ public class TemporalFilterIT {
// 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 @@ public class TemporalFilterIT {
// 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 @@ public class TemporalFilterIT {
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 @@ public class TemporalFilterIT {
final Value object = vf.createLiteral(time.toString());
return new StatementImpl(subject, predicate, object);
}
-}
\ No newline at end of file
+}