PlatformSpec(PRN /* platform reference number */,
type /* type of the platform */,
platoonId /* platoon to which belongs */);
PlatformPositionReport(PRN /* platform reference number */,
latitude /* latitude of current position */,
longitude /* longitude of current position */,
timestamp /* time of measurement */);
PlatformStatusReport(PRN /* platform reference number */,
type /* identifies what is being measured,
e.g., SPEED, FUEL-STATUS */,
value /* the measured value */,
timestamp /* time of measurement */);
RFSensorPositionReport(PRN /* PRN of reporting platform */,
latitude /* latitude of current position of
observed platform */,
longitude /* longitude of current position of
observed platform */,
speed /* speed of observed platform */
timestamp /* time of observation */);
MagneticSensorPositionReport(PRN /* PRN of reporting platform */,
latitude /* latitude of current position of
observed platform */,
longitude /* longitude of current position of
observed platform */,
direction /* direction of movement of
observed platform */
timestamp /* time of observation */);
RadarSensorPositionReport(PRN /* PRN of reporting platform */,
latitude /* latitude of current position of
observed platform */,
longitude /* longitude of current position of
observed platform */,
timestamp /* time of observation */);
InfraredTriggeredSensorReport (vfindex /* video-frame index */,
coords /* "heat/position coordinates" */,
timestamp /* time of observation */);
MagneticTriggeredSensorReport (dpindex /* delta-permeability index */,
comp /* "composition" */,
timestamp /* time of observation */);
SeismicTriggeredSensorReport (dindex /* distance index */,
range /* "range" */,
timestamp /* time of observation */);
WeatherAlert(latitudeL, /* latitude of the lower left corner of the location */
longitudeL, /* longitude of the lower left corner of the location */
latitudeR, /* latitude of the upper right corner of the location */
longitudeR, /* longitude of the upper right corner of the location */
type /* type of weather---RAIN, SNOW, etc. */,
amount /* value in inches per hour */,
timestamp /* time when reported weather is expected */);
aggregate center_of_mass(iPRN, iLatitude, iLongitude):(oLatitude, oLongitude){
table memo(PRN, latitude, longtitude); /* Current positions of platforms */
table counter(c int) memory as values(0); /* # of platforms in the platoon */
table result(rLatitude, rLongitude) as values(0,0);
table lastResult(lastLatitude, lastLongitude) as values(0,0);
initialize:iterate:{
/* Update result by subtracting the old values and adding the new ones */
update memo, result, counter
set rLatitude = (rLatitude * c - latitude + iLatitude) / c,
rLongitude = (rLongitude * c - longtitude + iLongitude) / c,
latitude = iLatitude,
longtitude = iLongitude
where iPRN = PRN;
/* Adding the new platforms into the result */
insert into memo values(iPRN, iLatitude, iLongitude)
where SQLCODE > 0;
update result, counter
set rLatitude = (rLatitude * c + iLatitude) / (c+1),
rLongitude = (rLongitude * c + iLongitude) / (c+1),
c = c + 1
where SQLCODE = 0;
insert into return
select rLatitude, rLongitude
from result, lastResult
where dist(rLatitude, rLongtitude, lastLatitude, lastLongitude) < 10;
update lastResult, result
set lastLatitude = rLatitude, lastLongitude = rLongitude;
}
};
select center_of_mass(PRN, latitude, longitude)
from PlatformPositionReport
where platoonID = 10;
Q1: Select Istream(center-of-mass(R1.latitude, R1.longitude) as com)
From PlatformSpec P, PlatformPositionReport [Range 5 Minute] R1
Where P.platoonID = 10 and P.PRN = R1.PRN and
R1.timestamp >= All (Select timestamp
From PlatformPositionReport
[Range 5 Minute] R2
Where R2.PRN = R1.PRN)
Q2: Select Istream(delta_compr(com)
From Q1
select *
from RFSensorPositionReport O1,
MagneticSensorPositionReport
over (range 5 minute preceding O1 range 5 minute following O1) O2,
RadarSensorPositionReport
over(range 5 minute preceding O1 range 5 minute following O1) O3
where ABS(O2.timestamp, O3.timestamp) < 5 minute
and distance(O1.latitude,O1.longitude,O2.latitude,O2.longitude) <= 10
and distance(O1.latitude,O1.longitude,O3.latitude,O3.longitude) <= 10
and distance(O2.latitude,O2.longitude,O3.latitude,O3.longitude) <= 10;
ObservationStream:
(Select PRN, latitude, longitude
From RFSensorPositionReport)
Union
(Select PRN, latitude, longitude
From MagneticSensorPositionReport)
Union
(Select PRN, latitude, longitude
From RadarSensorPositionReport)
ObjectSightingStream:
Select Rstream(*)
From ObservationStream [Now] O1,
ObservationStream [Range 5 Minute] O2,
ObservationStream [Range 5 Minute] O3
Where O1.PRN <> O2.PRN and O1.PRN <> O3.PRN and O2.PRN <> O3.PRN
and distance(O1.latitude,O1.longitude,O2.latitude,O2.longitude) <= 10
and distance(O1.latitude,O1.longitude,O3.latitude,O3.longitude) <= 10
and distance(O2.latitude,O2.longitude,O3.latitude,O3.longitude) <= 10
aggregate online_count_distinct(iKey, latitude, longitude):(oCount int){
table memo(key);
table counter(c int) memory as values(0);
initialize:iterate:{
insert into memo values(iKey)
where hasCrossed(latitude,longitude,500,600,550,650) and
not exists (select key from memo where key = iKey);
update counter
set c = c + 1
where SQLCODE = 0;
delete from memo
where hasReturned(latitude,longitude,500,600,550,650) and
exists (select key from memo where key = iKey);
update counter
set c = c - 1
where SQLCODE = 0;
insert into return
select c from counter
}
};
select 'At least 40 soldiers have crossed a specified boundary!'
from PlatformPositionReport as R, PlatformSpecs as S
where S.type = 'SOLDIER' and S.PRN = R.PRN
having online_count_distinct(R.PRN) >= 40;
SoldierPositionStream:
Select R.PRN as PRN, R.latitude as latitude, R.longitude as longitude
From PlatformPositionReport [Now] as R, PlatformSpecs as S
Where S.type = 'SOLDIER' and S.PRN = R.PRN
BoundaryCrossing:
Select True
From (Select Count (Distinct PRN) as num
From SoldierPositionStream
Where hasCrossed(latitude,longitude,500,600,550,650))
Where num >= 40
Select True
From (Select Count (Distinct (P.PRN)) as num
From PlatformPositionReport [Partition By PRN Rows 1] as P,
PlatformSpecs as S
Where P.PRN = S.PRN and S.type = 'SOLDIER' and
hasCrossed(latitude,longitude,500,600,550,650))
Where num >= 40
aggregate top_k(iValue, k int):{
table memo(value) memory;
initialize:iterate:{
insert into memo values(iValue)
where exists (select value from memo
where iValue >=value) or
(select count(value) from memo) < k;
delete from memo
where value = (select min(value) from memo) and
(select count(value) from memo) > k;
}
time:{
insert into return
select * from memo;
}
};
select top_k(latitude, 10)
over (slide 1)
from PlatformPositionReport
where platoonID = 10;
/* maintain a table of current platforms' status */
table CurrentPlatformStatus(PRN, type, value);
insert into CurrentPlatformStatus C
select R.PRN, R.latitude, R.longitude, R.value
from PlatformStatusReport R
where not exists (select PRN from C
where C.PRN = R.PRN);
update CurrentPlatformStatus C, PlatformStatusReport R
set C.value = R.value, C.type = R.type
where C.PRN = R.PRN;
select *
from PlatformPositionReport P, PlatformSpecs PS, PlatformSpecs TS,
CurrentPlatformStatus R,
PlatformPositionReport T
over (range 10 minute preceding P range 10 minute following P)
where T.PRN = TS.PRN and TS.type = 'TANK'
and T.PRN = C.PRN and C.type = 'TURRET-ORIENTATION'
and P.PRN = PS.PRN and TS.platoonID = PS.platoonID
and distance(T.latitude, T.longitude, P.latitude, P.longitude) <= 1000
and angle(C.value, T.latitude, T.longitude, P.latitude, P.longitude) <=20;
Q1: Select *
From PlatformPositionReport [Range 10 Minute] R1
Where R1.timestamp >= All (Select timestamp
From PlatformPositionReport
[Range 10 Minute] R2
Where R2.PRN = R1.PRN)
Q2: Select *
From PlatformStatusReport [Range 10 Minute] R1
Where R1.timestamp >= All (Select timestamp
From PlatformStatusReport
[Range 10 Minute] R2
Where R2.PRN = R1.PRN)
Q3: Select Istream(R1.PRN, R1.latitude, R1.longitude,
R2.PRN, R2.latitude, R2.longitude)
From PlatformSpecs S1, Q1 R1, Q1 R2, Q2 T, PlatformSpecs S2
Where S1.PRN = R1.PRN and S1.type = 'TANK' and R1.PRN != R2.PRN
and S2.PRN = R2.PRN and S1.platoonID = S2.platoonID
and distance(R1.latitude,R1.longitude,R2.latitude,R2.longitude) <= 1000
and T.PRN = R1.PRN and T.type = 'TURRET-ORIENTATION' and
angle(T.value,R1.latitude,R1.longitude,R2.latitude,R2.longitude) <= 20
table TankSummary (PRN, latitude, longitude, fuel, ammo);
insert into TankSummary TS, PlatformSpecs S
select R.PRN, -1, -1, R.value, -1
from PlatformStatusReport R
where R.PRN = S.PRN and S.type = 'TANK' and R.type = 'FUEL-STATUS'
and not exists (select PRN from TS
where TS.PRN = R.PRN);
update TankSummary TS, PlatformSpecs S,
PlatformStatusReport R
set TS.fuel = R.value
where TS.PRN = S.PRN and S.type = 'TANK'
and TS.PRN = R.PRN and R.type = 'FUEL-STATUS';
insert into TankSummary TS, PlatformSpecs S
select R.PRN, -1, -1, -1, R.value
from PlatformStatusReport R
where R.PRN = S.PRN and S.type = 'TANK' and R.type = AMMO-STATUS'
and not exists (select PRN from TS
where TS.PRN = R.PRN);
update TankSummary TS, PlatformSpecs S,
PlatformStatusReport R
set TS.ammo = R.value
where TS.PRN = S.PRN and S.type = 'TANK'
and TS.PRN = R.PRN and R.type = AMMO-STATUS';
insert into TankSummary TS, PlatformSpecs S
select R.PRN, R.latitude, R.longitude, -1, -1
from PlatformPositionReport R
where R.PRN = S.PRN and S.type = 'TANK'
and not exists (select PRN from TS
where TS.PRN = R.PRN);
update TankSummary TS, PlatformSpecs S,
PlatformPositionReport R
set TS.latitude = R.latitude, TS.longitude = R.longitude
where TS.PRN = S.PRN and S.type = 'TANK' and TS.PRN = R.PRN;
Comments: We could add a window "over (range 10 minute slide 10 minute)" onto the stream PlatformStatusReport and PlatformPosistionReport, to "update every 10 minute". But it would be more effecient to update for every coming tuple, in which case we don't need to go back to query the window. Therefore we decide to update "TankSummary" table in this way. Users can output the result every 10 minutes.
Q1: Select Rstream(R1.PRN PRN, R1.value fuelStatus)
From PlatformStatusReport [Range 10 Minute
Slide 10 Minute] R1,
PlatformSpecs S
Where R1.type = 'FUEL-STATUS' and S.PRN = R1.PRN and S.type = 'TANK'
and R1.timestamp >= All (Select timestamp
From PlatformStatusReport
[Range 10 Minute] R2
Where R2.PRN = R1.PRN and
R2.type = 'FUEL-STATUS')
Q2: Select Rstream(R1.PRN PRN, R1.value ammoStatus)
From PlatformStatusReport [Range 10 Minute
Slide 10 Minute] R1,
PlatformSpecs S
Where R1.type = 'AMMO-STATUS' and S.PRN = R1.PRN and S.type = 'TANK'
and R1.timestamp >= All (Select timestamp
From PlatformStatusReport
[Range 10 Minute] R2
Where R2.PRN = R1.PRN and
R2.type = 'AMMO-STATUS')
Q3: Select Rstream(R1.PRN PRN, R1.latitude latitude, R1.longitude longitude)
From PlatformPositionReport [Range 10 Minute
Slide 10 Minute] R1,
PlatformSpecs S
Where S.PRN = R1.PRN and S.type = 'TANK' and
R1.timestamp >= ALL (Select timestamp
From PlatformPositionReport
[Range 10 Minute] R2
Where R2.PRN = R1.PRN)
Q4: Select *
From Q1 [Partition By PRN Rows 1],
Q2 [Partition By PRN Rows 1],
Q3 [Partition By PRN Rows 1]
Where Q1.PRN = Q2.PRN and Q2.PRN = Q3.PRN
Stanford Stream Query Repository, http://www-db.stanford.edu/stream/sqr/cql/milmon.html
Aurora Project, http://www.cs.brown.edu/research/aurora/