% % Temporal Projection % % Haixun Wang, hxwang@cs.ucla.edu % % Assume that you have an emp(E#, SAL, D#, Time-Interval) % relation, sorted by E# and the start time of time % intervals, as in all Snodgrass' examples. %% database( { emp(Emp:string, Sal:integer, Dept:string, Interval:any) } ). %% export empProj1(Emp, Dept, Interval). export empProj2(Emp, Sal, Interval). export empProj(Emp, Interval). %% empProj(EmpId, coalesce)<-emp(EmpId,_,_,Interval). empProj1(EmpId, DeptId, coalesce)<-emp(EmpId,_,DeptId,Interval). empProj2(EmpId, Sal, coalesce)<-emp(EmpId,Sal,_,Interval). single(coalesce, (Start, End), (Start, End)). % in multi rule, since Date is sorted, so StartNew>=StartOld multi(coalesce, (StartNew, EndNew), (StartOld, EndOld), (Start, End))<- if (EndOld>=StartNew then Start=StartOld else Start=StartNew), if (EndNew>=EndOld then End=EndNew else End=EndOld). return(coalesce, (StartNew, EndNew), (StartOld, EndOld), (StartOld, EndOld))<- EndOld