RYA-377 Temporal Within 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/5e5d7c8e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/5e5d7c8e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/5e5d7c8e

Branch: refs/heads/master
Commit: 5e5d7c8ec2279b00ab7090e2214c333c0300ec88
Parents: cf43360
Author: Andrew Smith <smith...@gmail.com>
Authored: Fri Dec 1 14:52:00 2017 -0500
Committer: caleb <caleb.me...@parsons.com>
Committed: Tue Jan 9 15:13:01 2018 -0500

----------------------------------------------------------------------
 .../function/temporal/AfterTemporalInstant.java |  6 +-
 .../temporal/BeforeTemporalInstant.java         |  6 +-
 .../api/function/temporal/EqualsTemporal.java   | 49 -----------
 .../temporal/EqualsTemporalInstant.java         | 44 ++++++++++
 .../TemporalInstantRelationFunction.java        | 63 ++++++++++++++
 .../TemporalIntervalRelationFunction.java       | 70 ++++++++++++++++
 .../temporal/TemporalRelationFunction.java      | 65 ---------------
 .../rya/api/function/temporal/TemporalURIs.java | 23 +++++
 .../temporal/WithinTemporalInterval.java        | 45 ++++++++++
 ...f.query.algebra.evaluation.function.Function |  3 +-
 .../temporal/EqualsTemporalFunctionsTest.java   |  6 +-
 .../temporal/WithinTemporalFunctionsTest.java   | 88 ++++++++++++++++++++
 .../processors/filter/TemporalFilterIT.java     | 74 +++++++++++-----
 13 files changed, 396 insertions(+), 146 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/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
index 38c02ba..fe58e37 100644
--- 
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
@@ -29,12 +29,10 @@ 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";
-
+public class AfterTemporalInstant extends TemporalInstantRelationFunction {
     @Override
     public String getURI() {
-        return URI;
+        return TemporalURIs.AFTER;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/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
index c9f31c3..4cb12e0 100644
--- 
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
@@ -29,12 +29,10 @@ 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";
-
+public class BeforeTemporalInstant extends TemporalInstantRelationFunction {
     @Override
     public String getURI() {
-        return URI;
+        return TemporalURIs.BEFORE;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/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
deleted file mode 100644
index 07391c8..0000000
--- 
a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporal.java
+++ /dev/null
@@ -1,49 +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 java.time.ZonedDateTime;
-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.
- */
-@DefaultAnnotation(NonNull.class)
-public class EqualsTemporal extends TemporalRelationFunction {
-    private static final String URI = BASE_URI + "equals";
-
-    @Override
-    public String getURI() {
-        return URI;
-    }
-
-    @Override
-    protected boolean relation(final ZonedDateTime d1, final ZonedDateTime d2) 
{
-        Objects.requireNonNull(d1);
-        Objects.requireNonNull(d2);
-        return d1.isEqual(d2);
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporalInstant.java
----------------------------------------------------------------------
diff --git 
a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporalInstant.java
 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporalInstant.java
new file mode 100644
index 0000000..10fe40b
--- /dev/null
+++ 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/EqualsTemporalInstant.java
@@ -0,0 +1,44 @@
+/*
+ * 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 equality over time.
+ */
+@DefaultAnnotation(NonNull.class)
+public class EqualsTemporalInstant extends TemporalInstantRelationFunction {
+    @Override
+    public String getURI() {
+        return TemporalURIs.EQUALS;
+    }
+
+    @Override
+    protected boolean relation(final ZonedDateTime d1, final ZonedDateTime d2) 
{
+        Objects.requireNonNull(d1);
+        Objects.requireNonNull(d2);
+        return d1.isEqual(d2);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalInstantRelationFunction.java
----------------------------------------------------------------------
diff --git 
a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalInstantRelationFunction.java
 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalInstantRelationFunction.java
new file mode 100644
index 0000000..d622329
--- /dev/null
+++ 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalInstantRelationFunction.java
@@ -0,0 +1,63 @@
+/*
+ * 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.time.format.DateTimeParseException;
+
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.Function;
+
+import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
+import edu.umd.cs.findbugs.annotations.NonNull;
+
+/**
+ * Function for comparing 2 {@link ZonedDateTime} objects in a SPARQL filter.
+ */
+@DefaultAnnotation(NonNull.class)
+abstract class TemporalInstantRelationFunction implements Function {
+    @Override
+    public Value evaluate(final ValueFactory valueFactory, final Value... 
args) throws ValueExprEvaluationException {
+        if (args.length != 2) {
+            throw new ValueExprEvaluationException(getURI() + " requires 
exactly 2 arguments, got " + args.length);
+        }
+
+        try {
+            final ZonedDateTime date1 = 
ZonedDateTime.parse(args[0].stringValue());
+            final ZonedDateTime date2 = 
ZonedDateTime.parse(args[1].stringValue());
+            final boolean result = relation(date1, date2);
+
+            return valueFactory.createLiteral(result);
+        } catch (final DateTimeParseException e) {
+            throw new ValueExprEvaluationException("Date/Times provided must 
be of the ISO-8601 format. Example: 2007-04-05T14:30Z");
+        }
+    }
+
+    /**
+     * The comparison function to perform between 2 {@link ZonedDateTime}
+     * objects.
+     *
+     * @param d1 first {@link ZonedDateTime} to compare. (not null)
+     * @param d2 second {@link ZonedDateTime} to compare. (not null)
+     * @return The result of the comparison between {@link ZonedDateTime}s.
+     */
+    protected abstract boolean relation(ZonedDateTime d1, ZonedDateTime d2);
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalIntervalRelationFunction.java
----------------------------------------------------------------------
diff --git 
a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalIntervalRelationFunction.java
 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalIntervalRelationFunction.java
new file mode 100644
index 0000000..4a0d4bd
--- /dev/null
+++ 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalIntervalRelationFunction.java
@@ -0,0 +1,70 @@
+/*
+ * 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.time.format.DateTimeParseException;
+
+import org.openrdf.model.Value;
+import org.openrdf.model.ValueFactory;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+import org.openrdf.query.algebra.evaluation.function.Function;
+
+import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
+import edu.umd.cs.findbugs.annotations.NonNull;
+
+/**
+ * Function for comparing a {@link ZonedDateTime} with an interval of {@link 
ZonedDateTime} objects in a SPARQL filter.
+ */
+@DefaultAnnotation(NonNull.class)
+abstract class TemporalIntervalRelationFunction implements Function {
+    @Override
+    public Value evaluate(final ValueFactory valueFactory, final Value... 
args) throws ValueExprEvaluationException {
+        if (args.length != 2) {
+            throw new ValueExprEvaluationException(getURI() + " requires 
exactly 2 arguments, got " + args.length);
+        }
+
+        final String[] strInterval = args[1].stringValue().split("/");
+        if (strInterval.length != 2) {
+            throw new ValueExprEvaluationException(getURI() + " requires the 
second argument: " + args[1] + " to be 2 dates seperated by a \'/\'");
+        }
+        try {
+            final ZonedDateTime date1 = 
ZonedDateTime.parse(args[0].stringValue());
+            final ZonedDateTime[] interval = new ZonedDateTime[] {
+                    ZonedDateTime.parse(strInterval[0]),
+                    ZonedDateTime.parse(strInterval[1])
+            };
+            final boolean result = relation(date1, interval);
+
+            return valueFactory.createLiteral(result);
+        } catch (final DateTimeParseException e) {
+            throw new ValueExprEvaluationException("Date/Times provided must 
be of the ISO-8601 format. Example: 2007-04-05T14:30Z");
+        }
+    }
+
+    /**
+     * The comparison function to perform between 2 {@link ZonedDateTime}
+     * objects.
+     *
+     * @param d1 first {@link ZonedDateTime} to compare. (not null)
+     * @param interval The interval represented by 2 {@link ZonedDateTime}s. 
(not null)
+     * @return The result of the comparison between {@link ZonedDateTime}s.
+     */
+    protected abstract boolean relation(ZonedDateTime d1, ZonedDateTime[] 
interval);
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalRelationFunction.java
----------------------------------------------------------------------
diff --git 
a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalRelationFunction.java
 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalRelationFunction.java
deleted file mode 100644
index 02710d9..0000000
--- 
a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalRelationFunction.java
+++ /dev/null
@@ -1,65 +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 java.time.ZonedDateTime;
-import java.time.format.DateTimeParseException;
-
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
-import org.openrdf.query.algebra.evaluation.function.Function;
-
-import edu.umd.cs.findbugs.annotations.DefaultAnnotation;
-import edu.umd.cs.findbugs.annotations.NonNull;
-
-/**
- * Function for comparing 2 {@link ZonedDateTime} objects in a SPARQL filter.
- */
-@DefaultAnnotation(NonNull.class)
-abstract class TemporalRelationFunction implements Function {
-    public static final String BASE_URI = "http://rya.apache.org/ns/temporal/";;
-
-    @Override
-    public Value evaluate(final ValueFactory valueFactory, final Value... 
args) throws ValueExprEvaluationException {
-        if (args.length != 2) {
-            throw new ValueExprEvaluationException(getURI() + " requires 
exactly 2 arguments, got " + args.length);
-        }
-
-        try {
-            final ZonedDateTime date1 = 
ZonedDateTime.parse(args[0].stringValue());
-            final ZonedDateTime date2 = 
ZonedDateTime.parse(args[1].stringValue());
-            final boolean result = relation(date1, date2);
-
-            return valueFactory.createLiteral(result);
-        } catch (final DateTimeParseException e) {
-            throw new ValueExprEvaluationException("Date/Times provided must 
be of the ISO-8601 format. Example: 2007-04-05T14:30Z");
-        }
-    }
-
-    /**
-     * The comparison function to perform between 2 {@link ZonedDateTime}
-     * objects.
-     *
-     * @param d1 first {@link ZonedDateTime} to compare. (not null)
-     * @param d2 second {@link ZonedDateTime} to compare. (not null)
-     * @return The result of the comparison between {@link ZonedDateTime}s.
-     */
-    protected abstract boolean relation(ZonedDateTime d1, ZonedDateTime d2);
-}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalURIs.java
----------------------------------------------------------------------
diff --git 
a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalURIs.java
 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalURIs.java
new file mode 100644
index 0000000..7902a5f
--- /dev/null
+++ 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/TemporalURIs.java
@@ -0,0 +1,23 @@
+package org.apache.rya.api.function.temporal;
+
+/**
+ * Constants for the Temporal Functions used in rya.
+ */
+public class TemporalURIs {
+    /**
+     * All temporal functions have the namespace 
(<tt>http://rya.apache.org/ns/temporal#</tt>).
+     */
+    public static final String NAMESPACE = 
"http://rya.apache.org/ns/temporal#";;
+
+    /** <tt>http://rya.apache.org/ns/temporal#equals</tt> */
+    public final static String EQUALS = NAMESPACE + "equals";
+
+    /** <tt>http://rya.apache.org/ns/temporal#before</tt> */
+    public final static String BEFORE = NAMESPACE + "before";
+
+    /** <tt>http://rya.apache.org/ns/temporal#after</tt> */
+    public final static String AFTER = NAMESPACE + "after";
+
+    /** <tt>http://rya.apache.org/ns/temporal#within</tt> */
+    public final static String WITHIN = NAMESPACE + "within";
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/WithinTemporalInterval.java
----------------------------------------------------------------------
diff --git 
a/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/WithinTemporalInterval.java
 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/WithinTemporalInterval.java
new file mode 100644
index 0000000..5fc3e03
--- /dev/null
+++ 
b/common/rya.api.function/src/main/java/org/apache/rya/api/function/temporal/WithinTemporalInterval.java
@@ -0,0 +1,45 @@
+/*
+ * 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
+ * within an interval.
+ */
+@DefaultAnnotation(NonNull.class)
+public class WithinTemporalInterval extends TemporalIntervalRelationFunction {
+    @Override
+    public String getURI() {
+        return TemporalURIs.WITHIN;
+    }
+
+    @Override
+    protected boolean relation(final ZonedDateTime d1, final ZonedDateTime[] 
interval) {
+        Objects.requireNonNull(d1);
+        Objects.requireNonNull(interval);
+        return d1.isAfter(interval[0]) && d1.isBefore(interval[1]);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/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 2ec01d5..1172844 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
@@ -16,6 +16,7 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-org.apache.rya.api.function.temporal.EqualsTemporal
+org.apache.rya.api.function.temporal.EqualsTemporalInstant
 org.apache.rya.api.function.temporal.BeforeTemporalInstant
 org.apache.rya.api.function.temporal.AfterTemporalInstant
+org.apache.rya.api.function.temporal.WithinTemporalInterval

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/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
index f32904a..0d14d48 100644
--- 
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
@@ -36,7 +36,7 @@ public class EqualsTemporalFunctionsTest {
 
     @Test
     public void testEquals_equal() throws Exception {
-        final EqualsTemporal function = new EqualsTemporal();
+        final EqualsTemporalInstant function = new EqualsTemporalInstant();
 
         // 2 times equal
         final Value[] args = new Value[2];
@@ -49,7 +49,7 @@ public class EqualsTemporalFunctionsTest {
 
     @Test
     public void testEquals_before() throws Exception {
-        final EqualsTemporal function = new EqualsTemporal();
+        final EqualsTemporalInstant function = new EqualsTemporalInstant();
 
         // first time is before
         final Value[] args = new Value[2];
@@ -62,7 +62,7 @@ public class EqualsTemporalFunctionsTest {
 
     @Test
     public void testEquals_after() throws Exception {
-        final EqualsTemporal function = new EqualsTemporal();
+        final EqualsTemporalInstant function = new EqualsTemporalInstant();
 
         // first time is after
         final Value[] args = new Value[2];

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/WithinTemporalFunctionsTest.java
----------------------------------------------------------------------
diff --git 
a/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/WithinTemporalFunctionsTest.java
 
b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/WithinTemporalFunctionsTest.java
new file mode 100644
index 0000000..6dee711
--- /dev/null
+++ 
b/common/rya.api.function/src/main/test/org/apache/rya/api/function/temporal/WithinTemporalFunctionsTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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;
+import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
+
+public class WithinTemporalFunctionsTest {
+    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(expected = ValueExprEvaluationException.class)
+    public void within_NotInterval() throws Exception {
+        // correct date formats are ensured through other tests
+        final WithinTemporalInterval function = new WithinTemporalInterval();
+
+        // 2 dates are provided
+        final Value[] args = new Value[2];
+        args[0] = VF.createLiteral(TIME.toString());
+        args[1] = VF.createLiteral(TIME.toString());
+        function.evaluate(VF, args);
+    }
+
+    @Test
+    public void testWithin_beginning() throws Exception {
+        final WithinTemporalInterval function = new WithinTemporalInterval();
+
+        // 2 times equal
+        final Value[] args = new Value[2];
+        args[0] = VF.createLiteral(TIME.toString());
+        args[1] = VF.createLiteral(TIME.toString() + "/" + TIME_20.toString());
+        final Value rez = function.evaluate(VF, args);
+
+        assertEquals(VF.createLiteral(false), rez);
+    }
+
+    @Test
+    public void testWithin_within() throws Exception {
+        final WithinTemporalInterval function = new WithinTemporalInterval();
+
+        // first time is before
+        final Value[] args = new Value[2];
+        args[0] = VF.createLiteral(TIME_10.toString());
+        args[1] = VF.createLiteral(TIME.toString() + "/" + TIME_20.toString());
+        final Value rez = function.evaluate(VF, args);
+
+        assertEquals(VF.createLiteral(true), rez);
+    }
+
+    @Test
+    public void testWithin_end() throws Exception {
+        final WithinTemporalInterval function = new WithinTemporalInterval();
+
+        // first time is after
+        final Value[] args = new Value[2];
+        args[0] = VF.createLiteral(TIME_20.toString());
+        args[1] = VF.createLiteral(TIME.toString() + "/" + TIME_20.toString());
+        final Value rez = function.evaluate(VF, args);
+
+        assertEquals(VF.createLiteral(false), rez);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5e5d7c8e/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 0a2185d..22a883b 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 3 temporal functions registered, ensure that there are 3.
-        assertEquals(3, count);
+        // There are 4 temporal functions registered, ensure that there are 4.
+        assertEquals(4, count);
     }
 
     @Test
@@ -89,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, \"" + TIME.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());
 
@@ -123,12 +123,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:before(?date, \"" + TIME_10.toString() + "\")) "
-            + "}";
+                        + "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());
 
@@ -157,12 +157,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:after(?date, \"" + TIME_10.toString() + "\")) "
-            + "}";
+                        + "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());
 
@@ -180,6 +180,40 @@ public class TemporalFilterIT {
         RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, 
resultsTopic, builder, statements, expected, 
VisibilityBindingSetDeserializer.class);
     }
 
+    @Test
+    public void showWithinWorks() 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:within(?date, \"" + TIME.toString() + 
"/" + TIME_20.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_10.toString()));
+        expected.add( new VisibilityBindingSet(bs, "a") );
+
+        // Run the test.
+        RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, 
resultsTopic, builder, statements, expected, 
VisibilityBindingSetDeserializer.class);
+    }
+
     private List<VisibilityStatement> getStatements() throws Exception {
         final List<VisibilityStatement> statements = new ArrayList<>();
         statements.add(new VisibilityStatement(statement(TIME), "a"));

Reply via email to