The predicate for this relationship, as it holds between two time periods expressed as pairs of dates using the closed-open con-vention, is: eff_beg_dt 1 > eff_beg_dt 2 AND eff_beg_dt 1
Trang 1The inverse of this relationship is: P2 [overlaps1] P1 In the superscripted relationship, the first time period is the later one The predicate for this relationship, as it holds between two time periods expressed as pairs of dates using the closed-open con-vention, is:
(eff_beg_dt 1 > eff_beg_dt 2 ) AND (eff_beg_dt 1 < eff_end_dt 2 ) AND (eff_end_dt 1 > eff_end_dt 2 )
It says that P1 starts after P2 starts and before P2 ends, and ends after P2ends
Consider the following request for information: which policies began before the Diabetes Management Wellness Pro-gram for 2009, and ended while that proPro-gram was still going on? The SQL written to fulfill this request is:
SELECT * FROM V_Allen_Example WHERE pol_eff_beg_dt < wp_eff_beg_dt AND pol_epis_end_dt > wp_eff_beg_dt AND pol_epis_end_dt < wp_epis_end_dt
P1[intersects] P2 This not an Allen relationship It is the node in our taxonomy
of Allen relationships which includes the [starts], [starts1], [finishes], [finishes1], [during], [during1], [equals], [overlaps] and [overlaps1] relationships In other words, it combines the [overlaps] relationships with the [fills] relationships
In the non-superscripted relationship, the first time period is the earlier one The predicate for this relationship, as it holds between two time periods expressed as pairs of dates using the closed-open convention, is:
(eff_beg_dt 1 <¼ eff_beg_dt 2 ) AND (eff_end_dt 1 > eff_beg_dt 2 )
It says that P1starts no later than P2starts, and ends after P2
starts The idea behind it is that it includes every relationship in which P1and P2 have at least one clock tick in common and in which P1is the earlier time period
The limiting case is that in which P1ends at the same time
P2 starts So let P1 be [4/15/2010 – 5/13/2010] and let P2 be [5/12/2010 – 9/18/2010] The clock tick they share is 5/12/2010 The inverse of this relationship is: P1 [intersects1] P2 The first time period in this non-superscripted relationship is the later one The predicate for this relationship, as it holds between
Trang 2two time periods expressed as pairs of dates using the
closed-open convention, is:
(eff_beg_dt 1 >¼ eff_beg_dt 2 )
AND (eff_beg_dt 1 < eff_end_dt 2 )
It says that P2starts no later than P1starts, and ends after P1
starts The idea behind it is that it includes every relationship in
which P1and P2 have at least one clock tick in common and in
which P1is the earlier time period
All pairs of time periods that share at least one clock tick
sat-isfy one or the other of these two predicates So the predicate
that expresses the truth condition for all time periods that share
at least one clock tick is:
((eff_beg_dt 1 < eff_end_dt 2 )
AND (eff_end_dt 1 > eff_beg_dt 2 ))
It says that either one of the clock ticks in P1is also in P2or that
one of the clock ticks in P2is also in P1 The idea behind it is that it
covers all the cases where two time periods have at least one clock
tick in common, regardless of which is the later time period
It is interesting to look at this relationship in terms of what
falls outside its scope For any two relationships that share at
| -|
| -|
Equals | -|
| -|
Intersects Overlaps Fills Occupies Starts Finishes During | -|
| -|
Aligns | -|
| -|
| -|
| -|
Time Period Relationships Along a Common Timeline
Figure 14.10 P1[intersects] P2
Trang 3least one clock tick, neither ends before the other begins Other-wise, they could not share a clock tick Looking at [includes] in terms of what falls outside its scope, we can express it as follows: NOT(eff_end_dt 1 <¼ eff_beg_dt 2 ) AND NOT(eff_beg_dt 1
>¼ eff_end_dt 2 ) And for those who like as few NOTs as possible, a logical rule (one of the transformation rules known as the De Morgan’s equi-valences) gives us the following predicate:
NOT((eff_end_dt 1 <¼ eff_beg_dt 2 ) OR (eff_beg_dt 1
>¼ eff_end_dt 2 ))
In other words, if two things are both not true, then it isn’t true that either of them is true! On such profundities are the rules of logic constructed
Consider the following request for information: which policies share any clock tick with the Diabetes Management Wellness Program for 2009?
The SQL written to fulfill this request is:
SELECT * FROM V_Allen_Example WHERE pol_eff_beg_dt < wp_epis_end_dt AND pol_epis_end_dt > wp_eff_beg_dt Notice how this SQL is much simpler than the OR’d collection
of all of the conditions that make up the leaf nodes of its Allen relationships
P1[before] P2
This is a pair of relationships, one the inverse of the other
In the non-superscripted relationship, the first time period is the earlier one
Time Period Relationships Along a Common Timeline
Excludes
Before
| -| | -|
Figure 14.11 P1[before] P2
Trang 4The predicate for this relationship, as it holds between two
time periods expressed as pairs of dates using the closed-open
convention, is:
(eff_end_dt 1 < eff_beg_dt 2 )
It says that after P1ends, there is at least one clock tick before
P2 begins For example, consider the case where eff_end_dt1 is
5/13/2014 and eff_beg_dt2 is 5/14/2014 Because of the
closed-open convention, the last clock tick in P1 is 5/12/2014, and so
there is one clock tick gap between the two time periods, that
clock tick being 5/13/2014
The inverse of this relationship is: P1 [before1] P2 In the
superscripted relationship, the first time period is the later one
The predicate for this relationship, as it holds between two time
periods expressed as pairs of dates using the closed-open
convention, is:
(eff_beg_dt 1 > eff_end_dt 2 )
It says that before P1 begins, there is at least one clock tick
after P2 ends For example, consider the case where eff_beg_dt1
is 5/14/2014 and eff_end_dt2 is 5/13/2014 Because of the
closed-open convention, the last clock tick in P2 is 5/12/2014,
and so there is one clock tick gap between the two time periods,
that clock tick being 5/13/2014
Throughout this book, if it isn’t important which time period
comes first, we will simply say that the two time periods are
non-contiguous
This is a particularly useful pair of relationships because they
distinguish episodes of the same object from one another
Two adjacent versions—versions of an object with no other
ver-sion of the same object between them—belong to different
episodes just in case the earlier one is [before] the later one
Of two adjacent episodes of the same object, one is [before]
the other, and the other is [before1] the former
Consider the following request for information: which
policies ended at least one date before the Diabetes
Manage-ment Wellness Program for 2009 began?
The SQL written to fulfill this request is:
SELECT * FROM V_Allen_Example
WHERE pol_epis_end_dt < wp_eff_beg_dt
P1[meets] P2
This is a pair of relationships, one the inverse of the other
In the non-superscripted relationship, the first time period is
the earlier one
Trang 5The predicate for this relationship, as it holds between two time periods expressed as pairs of dates using the closed-open convention, is:
(eff_end_dt 1 ¼ eff_beg_dt 2 )
It says that after P1ends, P2begins on the very next clock tick There is no clock tick gap between them Say that both dates are 5/13/2004 This means that the last clock tick in P1is 5/12/2004 and the first clock tick in P2 is 5/13/2004, and so there are no clock ticks between the two time periods
The inverse of this relationship is: P2[meets1] P1 In the super-scripted relationship, the first time period is the later one The pred-icate for this relationship, as it holds between two time periods expressed as pairs of dates using the closed-open convention, is: (eff_beg_dt 1 ¼ eff_end_dt 2 )
It says that before P1 begins, P2 ends on the previous clock tick There is no clock tick gap between them
This is a particularly useful relationship because it defines a collection of versions of the same object that belong to the same episode Every adjacent pair of versions of the same object that
do not share any clock ticks, i.e in which neither includes the other, and which also do not have a single clock tick between them, belong to the same episode The earlier version of the pair meets the later one; the later version is met by the earlier one Throughout this book, if it isn’t important which of two time periods that meet come first, we will simply say that the two time periods are contiguous
Consider the following request for information: which policies ended immediately before the Diabetes Management Wellness Program for 2009 began?
Time Period Relationships Along a Common Timeline
Excludes
| -| -|
Meets
Figure 14.12 P1[meets] P2
Trang 6The SQL written to fulfill this request is:
SELECT * FROM V_Allen_Example
WHERE pol_epis_end_dt ¼ wp_eff_beg_dt
P1[excludes] P2
This not an Allen relationship It is the node in our taxonomy
of Allen relationships which includes the [before], [before1],
[meets] and [meets1] relationships
In the non-superscripted relationship, the first time period is
the earlier one The predicate for this relationship, as it holds
between two time periods expressed as pairs of dates using the
closed-open convention, is:
(eff_end_dt 1 <¼ eff_beg_dt 2 )
It says that P2starts either immediately after the end of P1, or
later than that The idea behind it is that it includes every
rela-tionship in which P1 and P2 have no clock ticks in common
and in which P1is the earlier time period
The inverse of this relationship is: P1[excludes1] P2 The first
time period in this non-superscripted relationship is the later
one The predicate for this relationship, as it holds between
two time periods expressed as pairs of dates using the
closed-open convention, is:
(eff_beg_dt 1 >¼ eff_end_dt 2 )
It says that P2ends either immediately before the start of P1,
or earlier than that The idea behind it is that it includes every
relationship in which P1and P2have no clock ticks in common
and in which P1is the later time period
All pairs of time periods that share no clock ticks satisfy one
or the other of these two predicates So the predicate that
Time Period Relationships
Along a Common Timeline
Excludes
Before Meets
| -| | -| | -| -|
Figure 14.13 P1[excludes] P2
Trang 7designates all and only those time periods that share no clock ticks is:
(eff-end-dt 1 <¼ eff-beg-dt 2 ) OR (eff-beg-dt 1 >¼ eff-end-dt 2 )
It says that either P2 starts after P1 ends or ends before P2
starts The idea behind it is that regardless of which time period comes first, they share no clock ticks
It should be the case that two time periods [exclude] one another if and only if they do not [intersect] one another If so, then if we put a NOT in front of the predicate for the [intersects] relationship, we should get a predicate which expresses the [excludes] relationship.2Putting a NOT in front of the [intersects] relationship, we get:
NOT((eff_beg_dt 1 < eff_end_dt 2 ) AND (eff_end_dt 1 > eff_beg_dt 2 )) This is a statement of the form NOT(X AND Y) The first thing
we will do is transform it, according to the De Morgan’s rules, into (NOT-X OR NOT-Y) This gives us:
NOT(eff_beg_dt 1 < eff_end_dt 2 )
OR NOT(eff_end_dt 1 > eff_beg_dt 2 ) Next, we can replace NOT(eff_beg_dt1 < eff_end_dt2) with (eff_beg_dt1>¼ eff_end_dt2), and NOT(eff_end_dt1> eff_beg_dt2) with (eff_end_dt1<¼ eff_beg_dt2) This gives us:
(eff_beg_dt 1 >¼eff_end_dt 2 ) OR (eff_end_dt 1 <¼ eff_beg_dt 2 ) Finally, by transposing the two predicates, we get:
(eff_end_dt 1 <¼ eff_beg_dt 2 ) OR (eff_beg_dt 1 >¼ eff_end_dt 2 ) And this is indeed the predicate for the [excludes] relation-ship, demonstrating that [excludes] is indeed logically equivalent
to NOT[intersects]
Consider the following request for information: which policies either ended before the Diabetes Management Wellness Program for 2009 began, or began after that program ended? The SQL written to fulfill this request is:
SELECT * FROM V_Allen_Example WHERE (pol_epis_end_dt <¼ wp_eff_beg_dt
OR pol_eff_beg_dt >¼ wp_epis_end_dt)
2 Since, at the time we are writing this paragraph, we haven’t done this, it is an excellent way of finding out if we have made any logical mistakes so far.
Trang 8Point in Time to Period of Time Queries
A point in time is a period of time that includes only one
clock tick Thus, using the closed-open convention, a point in
time, T1, is identical to the period of time [T1– T2] where T2 is
the next clock tick after T1 The only difference is in the notation
In the following discussions, we will use the simpler notation,
T1, for the point in time
In this section, we consider periods of time that are longer
than a single clock tick Periods of time that are one clock tick
in length are points in time, and we consider Allen relationships
between two points in time later
Given that P1is longer than a single clock tick, it may or may
not share a clock tick with T1 If it does, then T1 [occupies] P1
Otherwise, either one is [before] the other, or else they [meet]
In Asserted Versioning databases, all temporal periods are
delimited with the same point in time granularities When
compar-ing time periods to time periods, the logic in the AVF does not
depend on the granularity of the clock ticks used in temporal
parameters, as long as all of them are the same The clock ticks
could be months (as they are in the examples throughout this book),
days, seconds or microseconds of any size As we noted in Chapter 3,
the AVF can carry out its temporal logic without caring about
granularity specifically because of the closed-open convention
However, when comparing a point in time to a period of time,
we must be aware of the granularity of the clock tick, and must
often either add a clock tick to a point or period in time, or
sub-tract a clock tick from a point or period in time Consequently,
we need to specify the clock tick duration used in the specific
implementation to correctly perform this arithmetic We will
use “fCTD”, standing for “clock tick duration”, as the name of a
function that converts an integer into that integer number of
clock ticks of the correct granularity So, for example, in:
eff_end_dt – fCTD(1)
f CTD takes on the value of one clock tick If the granularity is a
month, as it is in most of the examples in this book, the result will
be to subtract one month from the effective end date If the
gran-ularity is a millisecond-level timestamp, it will subtract one
milli-second from that date The fCTD function determines the
granularity for a specific Asserted Versioning database from the
miscellaneous metadata table, shown as Figure 8.7 in Chapter 8
Different DBMSs use different date formats for date literals
It is also dependent on the default language and the date format
currently set These formats are shown inFigure 14.14
Trang 9We used the USA format in parts of the book, so we will assume that the default date format in our sample DBMS is the same
Different DBMSs use different syntax for date arithmetic SQL Server would use something like this:
AND DATEADD(DAY, -1, pol.eff_end_dt) > ‘07/15/2010’
where DAY is the granularity (which can also be abbreviated as
DD or D), while DB2 might use:
AND (pol.eff_end_dt - 1 DAY) > ‘07/15/2010’
with the reserved word DAY indicating the granularity We will use the T-SQL format for our examples, and will assume our clock tick granularity is one month, to keep it in synch with the examples used in the book However, in real-world databases, the granularity would more likely be a day, a second
or a microsecond This fCTD translation could be built into a reusable database function as part of the framework based on metadata
T1[starts] P1
This is a pair of relationships, one the inverse of the other In the non-superscripted relationship, the first time period is the point in time, i.e the single clock-tick time period.Figure 14.15 shows this relationship, and its place in our taxonomy The two dashed lines in the illustration graphically represent T1 and P1, with T1being the upper dashed line
The predicate for this relationship, as it holds between a period of time expressed as a pair of dates using the closed-open convention, and a point in time, is:
(T 1 ¼ eff_beg_dt)
It says that T1starts at P1 Consider the following request for information: which policies begin on the same date as the 2009 Diabetes Manage-ment Wellness Program?
ISO yyyy-mm-dd 2010-09-25
09/25/2010 25.09.2010 2010-09-25
mm/dd/yyyy dd.mm.yyyy yyyy-mm-dd
USA EUR JIS
Figure 14.14 Date Formats for Date Literals
Trang 10The SQL written to fulfill this request is:
SELECT * FROM V_Allen_Example
WHERE pol_eff_beg_dt ¼ wp_eff_beg_dt
T1[finishes] P1
This is a pair of relationships, one the inverse of the other In
the non-superscripted relationship, the first time period is the
point in time, i.e the single clock-tick time period.Figure 14.16
shows this relationship, and its place in our taxonomy The two
dashed lines in the illustration graphically represent T1 and P1,
with T1being the upper dashed line
The predicate for this relationship, as it holds between a
period of time expressed as a pair of dates using the closed-open
convention, and a point in time, is:
(T 1 ¼ eff_end_dt – fCTD(1))
Since the effective end date of a time period is the next clock
tick after the last clock tick in that time period, this predicate
says that P1ends on the clock tick that is T1
Fills
Occupies
Aligns
Starts
|-|
| -|
Intersects
Time Period Relationships Along a Common Timeline
Figure 14.15 T1[starts] P1