4.7 Complex Updates as Transactions
5.1.1 Semantics of Event Queries
The declarative semantics of XChange event query language is defined as a ternary relation between event queries, answers, and the stream of incoming event messages. This approach to the semantics is a ’special’ model theoretical semantics; it is different from a model theoretic satisfaction relation usually encountered in logic programming languages because of the advanced constructs of the event query language. Following the later approach, answers to event queries would be obtained by applying substitutions to the event query. However, due to partial specifications in event queries this is not always the case. For example, by just applying a substitution (set) to an event queryeq=andthen[[eq1,eq2]]the atomic events that occur
between the events answeringeq1andeq2, respectively, are not generated, although they are contained
in the answer toeq. This is because answers to event queries contain more atomic events than actually specified through an event query’s constituent atomic event queries.
A short discussion on time points and durations is given before formalising the answers to them, the incoming event stream, and the answering relation between them. The declarative semantics of event queries has been developed together with Prof. Dr. Franc¸ois Bry and Michael Eckert: Prof. Dr. Franc¸ois Bry has supervised the development of the whole XChange project. Michael Eckert has written his master’s thesis under the double supervision of the author and Prof. Dr. Franc¸ois Bry. The declarative semantics of XChange event queries has been previously published in [76, 18]. However, the declarative semantics presented in the cited work does not cover all kinds of XChange event queries. The semantics of all event query language constructs is first defined in this thesis. The declarative semantics provide a sound basis for formal proofs of event language properties; this section ends with a formal proof of the fact that XChange legal event queries need only a bounded event stream for their evaluation (Section 5.1.1).
Time Points and Durations
A time domain(T,D)is used for interpreting time points and durations (lengths of time): Time points are interpreted as objects ofT. Durations are interpreted as objects ofD. For enhancing the readability,
in defining the declarative semantics of XChange event queries time points and durations are considered as interpreted objects (instead of using the interpretation of the syntactical representation of time points and durations, respectively). A formally more correct approach would be to consider e.g. time pointst p in the specification of event queries andI(t p)in the definition of event queries’ semantics, whereIis an interpretation function for time objects. For working with time points and durations, the following relations and conditions on the time domain(T,D)are needed for the declarative semantics presented in this section.
(i) An equality relation=for both time points and durations.
(ii) A total order<on time points;t1<t2expresses that time pointt1is before time pointt2on the time
axis. A smallest time point exists, but no greatest time point.
(iii) The time difference−between two time points;t2−t1(witht1<t2) is a duration of time.
(iv) Durations can be compared with<;w1<w2expresses thatw1is shorter thanw2.
(v) Addition+of a duration to a time point results in a time point;t2=t1+w(wheret1time point and wduration) is a time point such thatt2−t1=w.
(vi) A minimum min and a maximum max function for time points (from a set of time points return a time point that represents the minimum, maximum respectively, of them).
CHAPTER 5. SEMANTICS Event Stream
Thestream of incoming events, orevent streamfor short, is the sequence of all atomic events an XChange- aware Web site receives. An atomic eventais a data termdthat has been received at pointr∈T(the
occurrence time of the atomic event). The reception time point of events is written in superscript notation; thus,a=dr. The domain of data termsTdis defined in [125]. For the occurrence timerof an atomic event a=dr, the notationocc(a)is also used in this work for easing the readability.
Event queries are forward-looking (cf. Section 4.4.1), they do not have the ability to query events that have been received before their registration. Thus, for a given event queryeq, all atomic events received after its registration formeq’s event stream. For readability reasons,E is used for denotingeq’s event stream, instead of Eeq. From now on, each event stream used for defining the declarative semantics is considered relative to a given event query; the event query will be clear from the context.
An event streamEis a finite sequenceha1,a2, . . .aniebcontaining all atomic eventsai=diri a reactive Web site is made aware of in the time interval[b..e]. The begin and end time points of the time interval are
written in subscript notation and superscript notation, respectively. This extends the notation for atomic events where just a single time point, the occurrence time of the atomic event, is needed in representation.
The atomic events of an event stream have the following properties:
(i)r1<· · ·<rn, i.e. they are totally ordered with respect to their occurrence time, and (ii)b≤r1andrn≤e, i.e. the atomic events of an event stream lie inside the interval[b..e]. Notethat (i) corresponds to the assumption that no two atomic events happen simultaneously.
Given an event queryeq, for defining its correct semantics, the beginning time of its event stream is the time at which the event query has been registered to the system. For this work,Eis not considered as the infinite sequence of atomic events a reactive system receives after registeringeq. For evaluating an event queryeqat some point in timeteval, all events needed in the evaluation have a lower temporal bound, i.e.
eq’s registration time, and an upper temporal bound, i.e.teval. Thus, it suffices to consider a finite sequence.
Answers
As explained in Section 4.4.5, the notion of answer to an event query is twofold, i.e. is made of the sequence of all atomic events that participated to answering the event query and a substitution set for all variables with at least one defining occurrence in the event query. Formally, an answer to an event queryeqis a tuple
(s,Σ), wheresis theevent sequenceof atomic events that enabled the successful evaluation ofeqandΣthe
correspondingsubstitution set.
Event Sequences Event sequencess=ha1, . . .aniebare sequences oftemporally orderedatomic events
ai=diritogether with a beginning timeband an ending timeeof the sequence, whereb≤r1<r2<· · ·< rn≤e. Cf. Section 4.2.3, answers to atomic event queries – atomic events – have an occurrence time point, answers to composite event queries – composite events – stretch over a time interval. The notion of event sequence accommodates both cases: For atomic events the beginning and ending time of the event sequence represent a single time point, the occurrence time of the atomic event (i.e.b=e). For composite
events, the beginning timebof an event sequence represents the beginning time of the composite event, the ending timeerepresents the ending time of the composite event. Note that the time pointedenotes the time at which the other parts of a reactive rule associated to the event query are evaluated. Recall that the beginning timeband ending timeeof a composite eventc=ha1, . . .aniebare not necessarilyr1
andrn, i.e. the reception times of the first and last, respectively, atomic events that are part of the event sequence representing the composite event (an explanatory example has been given in Section 4.2.3). In the following,begin(s)andend(s)are used for denoting the beginning time and ending time, respectively, of en event sequences.
For defining the semantics of event queries, the notion ofevent subsequencesand theunion of event sequencesare used; their formalisation follow.
Event Subsequences.A subsequence relation between event sequences is represented in this work with the (round) inclusion sign(. Thus,s(s0denotes thatsis a subsequence ofs0. Formally, the subsequence
relation is defined as follows: ha1, . . .anieb(ha0
1, . . .a0mie
0
b0if and only if
5.1. DECLARATIVE SEMANTICS (i){a1, . . .an}({a01, . . .a0m}, and
(ii)b0≤bande≤e0.
The definition above states that the atomic events of a sequencesare to be found in the sequences0if
s(s0. However, an event sequencescan also be acomplete subsequenceof a sequences0, i.e.scontainsall
atomic events froms0that lie betweens’s beginning and ending time. The complete subsequence relation
between event sequencessands0is written with a squared inclusion sign,s@s0. The relation is defined as
follows:
ha1, . . .anieb@ha01, . . .a0mie 0
b0if and only if
(i){a1, . . .an}={a0i|b≤occ(a0i)≤e,1≤i≤m}, and
(ii)b0≤bande≤e0.
Notethats@s0impliess(s0. Both relations(and@are reflexive and transitive.
Union of Event Sequences.Given two event sequencessands0, the union of the event sequences is denoted
s∪s0. The results00=s∪s0is an event sequence containing all events fromsands0and stretching over a
time interval covering the intervals ofsands0. The union of event sequences is formalised for then-ary
(not just binary) case as follows: ha1, . . .anieb∪ ha01, . . .a0mie 0 b0=de f ha001, . . .a00pie 00 b00, where (i){a001, . . .a00p}={a1, . . .an} ∪ {a01, . . .a0m}, and (ii)b00≤a00 1<· · ·<a00p≤e00, and
(iii)b00=min{b,b0}ande00=max{e,e0}.
The operation∪is associative. As usual,S
1≤i≤nsiis shorthand fors1∪ · · · ∪sn.
Notethat the event streamEis an event sequence; thus, the relations defined above do apply also for relating arbitrary sequences and the event stream.
Substitution Sets The notion of substitution sets introduced here is used also for the declarative seman- tics of condition and action parts of XChange reactive rules. It is important to use the same notion of substitution sets since the components of XChange reactive rules and the head and body of deductive rules communicate through substitution sets. To accommodate with the declarative semantics of the query lan- guage Xcerpt, which is integrated into XChange, the notion of substitution sets used in [125] is adopted for this work.
Substitution.Asubstitutionmaps variable names to construct terms. As the number of variables occurring in a term is always finite, the substitution here represents a finite mapping (function); in general, a substitu- tion gives assignments forallvariable names but its description covers just those of interest (e.g. variables occurring in a term, in our case). Substitutions are denoted in this work as variable assignments instead of as functions (e.g.{X7→f{”content”},Y7→g{”some content”}}). Recall that the same denotation has been
used in the previous sections for giving the informal meaning of XChange constructs through examples. Substitutions are means for communicating event query and Web query result data to the action part of the reactive rules so as toconstructevent messages to be sent and/or to perform updates that depend on these substitutions. For constructing new data (to be sent or to be inserted) and to determine the subjacent query term of an update term, the obtained substitutions areappliedto construct terms and query terms. Applyinga substitution to a term means replacing all occurrences of variables for which an assignment is provided by the corresponding assignments; the result is a term (σ(t)denotes the term obtained by applying σ tot). However, construct terms (specifying patterns for event messages, for views over persistent data, or for data that is to be inserted) may contain grouping constructs such asallorsome(cf. Section 2.4.2 and Section 4.6), case in whichallassignments for the variables in the construct term are needed. Thus, to accommodate such requirements,substitution setsare used in this work instead of substitutions.
Substitution Set.Asubstitution setΣis a (finite) set of substitutionsσ1, . . . ,σn(denotedΣ={σ1, . . . ,σn}). In the following, upper case greek letters (likeΣ) denote substitution sets, while lower case greek letters (likeσ) denote substitutions. Like substitutions, substitution sets can beappliedto a term (query, construct, or update term) but the result is in general a set of terms (calledinstancesof the respective query, construct, or update term). The definitions of substitution and substitution set application to query terms and construct terms are given in [125], Section 7.3.2 and Section 7.3.3.Σ(t)denotes the result of applying the substitution setΣto the termt.
CHAPTER 5. SEMANTICS Maximal Substitution Set. Moreover, the correct treatment of the grouping constructallrequires also the substitution set to bemaximal. An intuitive meaning of this property has been given in Section 4.4.5 when discussing the answers to XChange event queries. For an event queryeq, a substitution setΣansweringeq ismaximal, if there exists no substitution setϒansweringeqsuch thatΣis a proper subset ofϒ. A formal definition of maximal substitution sets can be found in [125] (Section 7.3, Definition 7.1 on page 147). Restriction of a Substitution Set.Therestrictionof a substitution setΣto a set of variablesV(denotedΣ|V) is the set of substitutions ofΣfor the variables ofV, and undefined (⊥) for all other variables:
Σ|V={σ0| ∃σ∈Σ∀x.σ0(x) =σ(x)ifx∈V,σ0(x) =⊥otherwise}
Defining Occurrence of Variables.The substitution set that is communicated between rule components and that is used for formalising the semantics of these components containsonlysubstitutions for the variables having at least one defining occurrencein the (event or Web) query. Determining whether a variable occurring in the event part (or condition part) of a rule can be used in the condition and action part (or, just in the action part, respectively) of the rule or not, is realised by means of (positive or negative) polarities that are associated with each variable occurrence. Explanations of polarity of variables in XChange terms have been given in Section 4.4 and Section 4.8.4.
Answering Relation
The declarative semantics of event queries is defined as a ternary relation between event queryeq, answer
(s,Σ), and event streamE. Given an event queryeqand the streamEof incoming events received after its
registration, theanswering relationtells whether a tuple(s,Σ)is an answer toequnderE. The answering relation is denotedeq/E(s,Σ)meaning ’eqis answered by(s,Σ)underE’. Notethat the event streamE needs to be incorporated into the answering relation as the answers toeqdepend onE.
Considereqan XChange event query. The answering relation /E is defined inductively oneq: The induction base is an XChange atomic query. The induction step uses case distinction on the top-level event composition construct or temporal restriction. In the followingV denotes the set of all variables having at least one defining occurrence ineq.
Atomic Event Query Caseeqatomic event query (that is,eq∈Tq, whereTqthe set of all possible Xcerpt query terms). A tuple(s,Σ)is an answer toequnderEif and only ifscontains a single atomic eventdrof
Eandeqmatches the data termdunder all substitutions fromΣ. Formally,eq/E(s,Σ)holds iff
(i)∀x∈V,∀σ∈Σ: σ(x)is defined and respects the restrictions onx, (ii)∀t∈Σ(eq): td, and
(iii)s=hdrirr@E.
Notethat the answer to an atomic event query contains in this work a sequence of a single atomic event. Thus, answers to atomic event queries and answers to composite event queries are treated in an uniform manner. This simplify the use of the atomic event query case as the base of the inductive definition. Conjunction Caseeq=and{eq1, . . . eqn}. A tuple(s,Σ)answersequnderEif and only ifsis the union ofnevent sequences fromEthat answer the component event querieseqi. Formally,eq/E(s,Σ)holds iff
∃s1, . . .snevent sequences such that
(i)eqi/E(si,Σ),∀i: 1≤i≤n, and (ii)s=S
1≤i≤nsi.
Notethatbegin(s) =mini=1..nbegin(si)andend(s) =maxi=1..nend(si)expressing that the composite event answer toeqstretches over the time interval covering all component atomic events. Also, the re- quirement thats1, . . .sn(E(i.e. event sequences contain only atomic events fromE) is actually given by the induction base (this note applies also for the other cases of induction).
Disjunction Caseeq=or{eq1, . . . eqn}. A tuple(s,Σ)answersequnderEif and only if(s,Σ)answers
one of the component event querieseqi. Formally,eq/E(s,Σ)holds iff (i)∃i,1≤i≤n: eqi/E(s,Σ).
5.1. DECLARATIVE SEMANTICS
Temporally Ordered Conjunction In order to simplify the definition of the case temporally ordered conjunction, the variable arity construct is defined by reducing it to the binary case, both forandthenwith complete[ ]and incomplete[[ ]]specifications.
Caseeq=andthen[eq1,eq2]. A tuple(s,Σ)answersequnder the event streamEif and only ifsis the union of two event sequences fromEthat answer the component event querieseqi, where all atomic events constituting the answer toeq1happen before all atomic events constituting the answer toeq2. Formally, eq/E(s,Σ)holds iff∃s1,s2event sequences such that
(i)eqi/E(si,Σ)fori=1,2,
(ii)s=s1∪s2, and
(iii)end(s1)<begin(s2).
Notethatbegin(s) =begin(s1)andend(s) =end(s2)are comprised by the above given conditions.
Case eq=andthen[eq1,eq2,eq3, . . .eqn], n>2. For defining the case of total temporally ordered
conjunction with variable arity (orn-ary), the definition is reduced to the one given above by applying the following rewriting rule:
andthen[eq1,eq2,eq3, . . .eqn]7→andthen[eq1,andthen[eq2,eq3, . . . ,eqn]].
Caseeq=andthen[[eq1,eq2]]. A tuple(s,Σ)answersequnder the event streamEif and only ifsis the union of three event sequences fromE: two answeringeq1andeq2, respectively, and one representing a continuous extract s0 ofE containing all atomic events received between the answers toeq
1 andeq2. Notethats0is used for gathering all events received in-between and, thus, capturing the meaning of partial
specification. Formally,eq/E(s,Σ)holds iff∃s1,s0,s2event sequences such that (i)eqi/E(si,Σ)fori=1,2,
(ii)s=s1∪s0∪s2,
(iii)end(s1)≤begin(s2),
(iv)begin(s0) =end(s1)andend(s0) =begin(s2), and
(v)s0@E.
Notethat, like in the previous case,begin(s) =begin(s1)andend(s) =end(s2)are comprised by the
above given conditions.
Caseeq=andthen[[eq1,eq2,eq3, . . . ,eqn]],n>2. Like for the case of temporally ordered conjunction
with total specification, the definition ofn-ary partial temporally ordered conjunction is reduced to the one