Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
BITEMPORAL QUERIES<br />
Querying on bitemporal data makes use of the range indexes on each of the four<br />
timestamps. Consider the following query: "What were the locations of our person of<br />
interest between January 8 and January 9 as we knew them between January 13 and<br />
January 14?" We express this query using cts:period constraints for defining time ranges:<br />
cts:search(fn:doc(), cts:and-query((<br />
cts:period-range-query(<br />
"valid",<br />
"ALN_CONTAINED_BY",<br />
cts:period(xs:dateTime("2016-01-08T00:00:00"),<br />
xs:dateTime("2016-01-09T23:59:59.99Z"))),<br />
cts:period-range-query(<br />
"system",<br />
"ALN_CONTAINED_BY",<br />
cts:period(xs:dateTime("2016-01-13T13:00:00"),<br />
xs:dateTime("2016-01-14T23:59:59.99Z"))<br />
)<br />
)))<br />
The code uses shortcuts for defining time intervals based on the relations of Allen's<br />
Interval Algebra. 12 These define all of the possible relationships between two time<br />
intervals—for example, preceding, overlapping, containing, meeting, finishing, and<br />
more. Internally, MarkLogic can break this query into the following inequalities:<br />
Valid Start 2016-01-08<br />
System Start 2016-01-13<br />
Consulting the range indexes gives us the following:<br />
Valid Start<br />
2016-01-01 1, 2, 4<br />
2016-01-08 5<br />
2016-01-10 3<br />
System Start<br />
2016-01-05 1<br />
2016-01-12 2, 3<br />
2016-01-15 4, 5<br />
Valid End<br />
2016-01-08 4<br />
2016-01-10 2<br />
∞ 1, 3, 5<br />
System End<br />
2016-01-12 1<br />
2016-01-15 2, 3<br />
2016-01-18 4, 5<br />
Figure 15: To resolve a bitemporal query, MarkLogic can perform inequality operations on the range<br />
indexes for the documents.<br />
12 MarkLogic also lets you define time relations using a set of SQL 2011 operators, which are similar to<br />
Allen's operators but less restrictive.<br />
93