merged back documentation branch into jarodwen/doc/function_sync
diff --git a/asterix-doc/src/site/markdown/aql/AsterixAllenRelationFunctions.md b/asterix-doc/src/site/markdown/aql/AsterixAllenRelationFunctions.md
new file mode 100644
index 0000000..4367d77
--- /dev/null
+++ b/asterix-doc/src/site/markdown/aql/AsterixAllenRelationFunctions.md
@@ -0,0 +1,224 @@
+# AsterixDB Temporal Functions: Allen's Relations #
+
+## About Allen's Relations ##
+
+AsterixDB supports Allen's relations over interval types. Allen's relations are also called Allen's interval algebra. There are totally 13 base relations described by this algebra, and all of them are supported in AsterixDB (note that `interval-equals` is supported by the `=` comparison symbol so there is no extra function for it).
+
+A detailed description of Allen's relations can be found from its [wikipedia entry](http://http://en.wikipedia.org/wiki/Allen's_interval_algebra).
+
+## Allen's Relations Functions ##
+
+### interval-before, interval-after ###
+
+ * Syntax:
+
+ interval-before(interval1, interval2)
+ interval-after(interval1, interval2)
+
+ * These two functions check whether an interval happens before/after another interval.
+ * Arguments:
+ * `interval1`, `interval2`: two intervals to be compared
+ * Return Value:
+
+ A `boolean` value. Specifically, `interval-before(interval1, interval2)` is true if and only if `interval1.end < interval2.start`, and `interval-after(interval1, interval2)` is true if and only if `interval1.start > interval2.end`. If any of the two inputs is `null`, `null` is returned.
+
+ * Examples:
+
+ let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
+ let $itv2 := interval-from-date("2005-05-01", "2012-09-09")
+ return {"interval-before": interval-before($itv1, $itv2), "interval-after": interval-after($itv2, $itv1)}
+
+ * The expected result is:
+
+ { "interval-before": true, "interval-after": true }
+
+### interval-meets, interval-met-by ###
+
+ * Syntax:
+
+ interval-meets(interval1, interval2)
+ interval-met-by(interval1, interval2)
+
+ * These two functions check whether an interval meets with another interval.
+ * Arguments:
+ * `interval1`, `interval2`: two intervals to be compared
+ * Return Value:
+
+ A `boolean` value. Specifically, `interval-meets(interval1, interval2)` is true if and only if `interval1.end = interval2.start`, and `interval-met-by(interval1, interval2)` is true if and only if `interval1.start = interval2.end`. If any of the two inputs is `null`, `null` is returned.
+
+ * Examples:
+
+ let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
+ let $itv2 := interval-from-date("2005-01-01", "2012-09-09")
+ let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
+ let $itv4 := interval-from-date("2004-09-10", "2006-08-01")
+ return {"meets": interval-meets($itv1, $itv2), "metby": interval-met-by($itv3, $itv4)}
+
+ * The expected result is:
+
+ { "meets": true, "metby": true }
+
+
+### interval-overlaps, interval-overlapped-by, interval-overlapping ###
+
+ * Syntax:
+
+ interval-overlaps(interval1, interval2)
+ interval-overlapped-by(interval1, interval2)
+ interval-overlaping(interval1, interval2)
+
+ * These functions check whether two intervals overlap with each other.
+ * Arguments:
+ * `interval1`, `interval2`: two intervals to be compared
+ * Return Value:
+
+ A `boolean` value. Specifically, `interval-overlaps(interval1, interval2)` is true if and only if
+
+ interval1.start < interval2.start
+ AND interval2.end > interval1.end
+ AND interval1.end > interval2.start
+
+
+ `interval-overlapped-by(interval1, interval2)` is true if and only if
+
+ interval2.start < interval1.start
+ AND interval1.end > interval2.end
+ AND interval2.end > interval1.start
+
+
+ `interval-overlapping(interval1, interval2)` is trun if
+
+ (interval2.start >= interval1.start
+ AND interval2.start < interval1.end)
+ OR
+ (interval2.end > interval1.start
+ AND interval2.end <= interval.end)
+
+ For all these functions, if any of the two inputs is `null`, `null` is returned.
+
+ Note that `interval-overlaps` and `interval-overlapped-by` are following the Allen's relations on the definition of overlap. `interval-overlapping` is a syntax sugar for the case that the intersect of two intervals is not empty.
+
+ * Examples:
+
+ let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
+ let $itv2 := interval-from-date("2004-05-01", "2012-09-09")
+ let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
+ let $itv4 := interval-from-date("2004-09-10", "2006-12-31")
+ return {"interval-overlaps": interval-overlaps($itv1, $itv2), "interval-overlapped-by": interval-overlapped-by($itv3, $itv4), "interval-overlapping-1": interval-overlapping($itv1, $itv2), "interval-overlapping-2": interval-overlapping($itv3, $itv4)}
+
+ * The expected result is:
+
+ { "interval-overlaps": true, "interval-overlapped-by": true, "interval-overlapping-1": true, "interval-overlapping-2": true }
+
+
+### interval-starts, interval-started-by ###
+
+ * Syntax:
+
+ interval-starts(interval1, interval2)
+ interval-started-by(interval1, interval2)
+
+ * These two functions check whether one interval starts with the other interval.
+ * Arguments:
+ * `interval1`, `interval2`: two intervals to be compared
+ * Return Value:
+
+ A `boolean` value. Specifically, `interval-starts(interval1, interval2)` returns true if and only if
+
+ interval1.start = interval2.start
+ AND interval1.end <= interval2.end
+
+
+ `interval-started-by(interval1, interval2)` returns true if and only if
+
+ interval1.start = interval2.start
+ AND interval2.end <= interval1.end
+
+ For both functions, if any of the two inputs is `null`, `null` is returned.
+
+ * Examples:
+
+ let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
+ let $itv2 := interval-from-date("2000-01-01", "2012-09-09")
+ let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
+ let $itv4 := interval-from-date("2006-08-01", "2006-08-01")
+ return {"interval-starts": interval-starts($itv1, $itv2), "interval-started-by": interval-started-by($itv3, $itv4)}
+
+ * The expected result is:
+
+ { "interval-starts": true, "interval-started-by": true }
+
+
+### interval-covers, interval-covered-by ###
+
+ * Syntax:
+
+ interval-covers(interval1, interval2)
+ interval-covered-by(interval1, interval2)
+
+ * These two functions check whether one interval covers the other interval.
+ * Arguments:
+ * `interval1`, `interval2`: two intervals to be compared
+ * Return Value:
+
+ A `boolean` value. Specifically, `interval-covers(interval1, interval2)` is true if and only if
+
+ interval1.start <= interval2.start
+ AND interval2.end >= interval1.end
+
+
+ `interval-covered-by(interval1, interval2)` is true if and only if
+
+ interval2.start <= interval1.start
+ AND interval1.end >= interval2.end
+
+ For both functions, if any of the two inputs is `null`, `null` is returned.
+
+ * Examples:
+
+ let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
+ let $itv2 := interval-from-date("2000-03-01", "2004-09-09")
+ let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
+ let $itv4 := interval-from-date("2004-09-10", "2012-08-01")
+ return {"interval-covers": interval-covers($itv1, $itv2), "interval-covered-by": interval-covered-by($itv3, $itv4)}
+
+ * The expected result is:
+
+ { "interval-covers": true, "interval-covered-by": true }
+
+
+### interval-ends, interval-ended-by ###
+
+* Syntax:
+
+ interval-ends(interval1, interval2)
+ interval-ended-by(interval1, interval2)
+
+ * These two functions check whether one interval ends with the other interval.
+ * Arguments:
+ * `interval1`, `interval2`: two intervals to be compared
+ * Return Value:
+
+ A `boolean` value. Specifically, `interval-ends(interval1, interval2)` returns true if and only if
+
+ interval1.end = interval2.end
+ AND interval1.start >= interval2.start
+
+ `interval-ended-by(interval1, interval2)` returns true if and only if
+
+ interval2.end = interval1.end
+ AND interval2.start >= interval1.start
+
+ For both functions, if any of the two inputs is `null`, `null` is returned.
+
+* Examples:
+
+ let $itv1 := interval-from-date("2000-01-01", "2005-01-01")
+ let $itv2 := interval-from-date("1998-01-01", "2005-01-01")
+ let $itv3 := interval-from-date("2006-08-01", "2007-03-01")
+ let $itv4 := interval-from-date("2006-09-10", "2007-03-01")
+ return {"interval-ends": interval-ends($itv1, $itv2), "interval-ended-by": interval-ended-by($itv3, $itv4) }
+
+* The expected result is:
+
+ { "interval-ends": true, "interval-ended-by": true }
diff --git a/asterix-doc/src/site/markdown/aql/functions.md b/asterix-doc/src/site/markdown/aql/functions.md
index 72319ea..1e2c7bc 100644
--- a/asterix-doc/src/site/markdown/aql/functions.md
+++ b/asterix-doc/src/site/markdown/aql/functions.md
@@ -1380,10 +1380,10 @@
{ "datetime-interval": interval-datetime("2012-01-01T04:23:34.456Z, 2013-04-01T15:34:45.567Z") }
-### year/month/day/hour/minute/second/millisecond ###
+### get-year/month/day/hour/minute/second/millisecond ###
* Syntax:
- year/month/day/hour/minute/second/millisecond(temporal_expression)
+ get-year/month/day/hour/minute/second/millisecond(temporal_expression)
* Accessors for accessing fields in a temporal value
* Arguments:
@@ -1398,7 +1398,7 @@
let $c3 := time("12:23:34.930+07:00")
let $c4 := duration("P3Y73M632DT49H743M3948.94S")
- return {"year": year($c1), "month": month($c2), "day": day($c1), "hour": hour($c3), "min": minute($c4), "second": second($c2), "ms": millisecond($c4)}
+ return {"year": get-year($c1), "month": get-month($c2), "day": get-day($c1), "hour": get-hour($c3), "min": get-minute($c4), "second": get-second($c2), "ms": get-millisecond($c4)}
* The expected result is:
@@ -1666,6 +1666,117 @@
{ "date": date("2013-04-05"), "datetime": datetime("2013-04-05T05:28:20.000Z"), "time": time("00:00:03.748Z") }
+### subtract-date ###
+ * Syntax:
+
+ subtract-date(date_start, date_end)
+
+ * Get the duration between two dates `date_start` and `date_end`
+ * Arguments:
+ * `date_start`: the starting `date`
+ * `date_end`: the ending `date`
+ * Return Value:
+ * A `duration` value between `date_start` and `date_end`
+
+ * Example:
+
+ use dataverse TinySocial;
+
+ for $i in dataset('FacebookUser')
+ for $j in dataset('FacebookUser')
+ where $i.user-since < $j.user-since and $i.user-since > datetime("2012-01-01T00:00:00")
+ return {"id1": $i.id, "id2": $j.id, "diff": subtract-date(date-from-datetime($j.user-since), date-from-datetime($i.user-since))}
+
+
+ * The expected result is:
+
+ { "id1": 3, "id2": 1, "diff": duration("P41D") }
+ { "id1": 3, "id2": 7, "diff": duration("P28D") }
+ { "id1": 7, "id2": 1, "diff": duration("P13D") }
+
+
+### subtract-time ###
+ * Syntax:
+
+ subtract-time(time_start, time_end)
+
+ * Get the duration between two times `time_start` and `time_end`
+ * Arguments:
+ * `time_start`: the starting `time`
+ * `time_end`: the ending `time`
+ * Return Value:
+ * A `duration` value between `time_start` and `time_end`
+
+ * Example:
+
+ use dataverse TinySocial;
+
+ for $i in dataset('FacebookUser')
+ for $j in dataset('FacebookUser')
+ where $i.user-since < $j.user-since and $i.user-since > datetime("2012-01-01T00:00:00")
+ return {"id1": $i.id, "id2": $j.id, "diff": subtract-time(time-from-datetime($j.user-since), time("02:50:48.938"))}
+
+
+ * The expected result is:
+
+ { "id1": 3, "id2": 1, "diff": duration("PT7H19M11.62S") }
+ { "id1": 3, "id2": 7, "diff": duration("PT7H19M11.62S") }
+ { "id1": 7, "id2": 1, "diff": duration("PT7H19M11.62S") }
+
+
+### subtract-datetime ###
+ * Syntax:
+
+ subtract-datetime(datetime_start, datetime_end)
+
+ * Get the duration between two datetimes `datetime_start` and `datetime_end`
+ * Arguments:
+ * `datetime_start`: the starting `datetime`
+ * `datetime_end`: the ending `datetime`
+ * Return Value:
+ * A `duration` value between `datetime_start` and `datetime_end`
+
+ * Example:
+
+ use dataverse TinySocial;
+
+ for $i in dataset('FacebookUser')
+ for $j in dataset('FacebookUser')
+ where $i.user-since < $j.user-since and $i.user-since > datetime("2011-01-01T00:00:00")
+ return {"id1": $i.id, "id2": $j.id, "diff": subtract-datetime($j.user-since, $i.user-since)}
+
+
+ * The expected result is:
+
+ { "id1": 2, "id2": 1, "diff": duration("P576D") }
+ { "id1": 2, "id2": 3, "diff": duration("P535D") }
+ { "id1": 2, "id2": 7, "diff": duration("P563D") }
+ { "id1": 3, "id2": 1, "diff": duration("P41D") }
+ { "id1": 3, "id2": 7, "diff": duration("P28D") }
+ { "id1": 7, "id2": 1, "diff": duration("P13D") }
+
+### interval-start-from-date/time/datetime ###
+ * Syntax:
+
+ interval-start-from-date/time/datetime(date/time/datetime, duration)
+
+ * Construct an `interval` value by the given starting `date`/`time`/`datetime` and the `duration` that the interval lasts.
+ * Arguments:
+ * `date/time/datetime`: a `string` representing a `date`, `time` or `datetime`, or a `date`/`time`/`datetime` value, representing the starting time point.
+ * `duration`: a `string` or `duration` value representing the duration of the interval. Note that duration cannot be negative value.
+ * Return Value:
+ * An `interval` value representing the interval starting from the given time point with the length of duration.
+
+ * Example:
+
+ let $itv1 := interval-start-from-date("1984-01-01", "P1Y")
+ let $itv2 := interval-start-from-time(time("02:23:28.394"), "PT3H24M")
+ let $itv3 := interval-start-from-datetime("1999-09-09T09:09:09.999", duration("P2M30D"))
+ return {"interval1": $itv1, "interval2": $itv2, "interval3": $itv3}
+
+ * The expectecd result is:
+
+ { "interval1": interval-date("1984-01-01, 1985-01-01"), "interval2": interval-time("02:23:28.394Z, 05:47:28.394Z"), "interval3": interval-datetime("1999-09-09T09:09:09.999Z, 1999-12-09T09:09:09.999Z") }
### get-interval-start, get-interval-end ###
* Syntax: