Stream Query Repository: Queries from a Military Logistics Application (CQL Queries)

Queries in CQL

We had to make certain assumptions in writing the following queries. We have not expressed all the queries in CQL since some of these were not clear to the authors at the time of writing.
  1. Center of Mass Query: Report the center-of-mass for a platoon of soldiers every time it moves by 10 meters.

    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
    

    Comments: center-of-mass is a user-defined relational-aggregate for computing the center-of-mass. We consider the latest position report by each platform for computing the center-of-mass within the last 5 minutes. So if a platform has not reported its position in the last 5 minutes, it is not considered for the center-of-mass computation. Query Q1 continuously streams the center-of-mass and query Q2 streams the new center-of-mass every time it moves by 10 meters. delta_compr is a user-defined windowed-aggregate (see link for another example of delta compression).

  2. Object Sighting Query: Report every time three observations are received from three different sources within a five minute interval of each other and the reported positions differ by not more than ten meters from each other.

    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
    

    Comments: ObservationStream is the derived stream of all observations from all sources. The object sighting query is written using the derived observation stream. The object sighting query checks for each observation (specified using the Now window) if there were two other observations in the last 5 minutes that satisfy the distance criteria. We use the user-defined function distance to compute the distance between two observations.

  3. Boundary Crossing Query: Report when at least 40 soldiers have crossed a specified boundary.

    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
    

    Comments: SoldierPositionStream is the derived stream of positions of soldiers. The subquery in the From clause of the boundary crossing query computes the distinct number of soldiers who have ever crossed the boundary. This subquery uses a user-defined boolean function hasCrossed to check if a position is beyond the boundary. Note that the above query counts every soldier who has ever crossed the boundary, even if he crosses back subsequently. Therefore, it is possible that there are less than 40 soldiers beyond the boundary at the logical instant the query returns true. The following query reports the first instant when at least 40 people are simultaneously beyond the boundary.

    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
    


  4. Front Line Query: Periodically compute the front line of a platoon.

  5. Fratricide Situation Query: Report whenever a tank is within 1000 meters of a friendly platform and the turret is pointed within 20 degrees of the platform.

    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
            
    

    Comments: We assume that the reports used to detect a fratricide situation must be within 10 minutes of each other. Among the reports within the last 10 minutes, we consider only the latest report. angle(turretOrientation, latitude1, longitude1, latitude2, longitude2) is a user-defined function that takes the turret orientation of the tank and the positions of the two platforms as input and returns the separation degree between the turret and the second platform. Further, since there is no other relevant information in the schema, we assume that two platforms are friendly if they belong to the same platoon.

  6. Platform Report Query: Maintain a summary of the latest information available for each tank and update it 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
    

    Comments: We assume that the summary information for a tank consists of its position, fuel status, and ammunition status. Every ten minutes, query Q1 streams the latest fuel status, query Q2 streams the ammunition status, and query Q3 streams the latest position, respectively, for each tank. Query Q4 uses partitioned windows to maintain the latest available information for each tank.

  7. Probabilistic Enemy Tracking Query: Determine the approximate probability that multiple enemy vehicle positions reported are actually the same vehicle.

  8. Prediction Query: Based on the history of movement of a specified platform, determine the likelihood of the platform crossing a specified border within a specified period of time.

  9. Platoon SITREP Query: Roll up the summary status computed for each platform into a situation report for the platoon.

  10. Platoon Trail Query: Draw a trail for a particular platform over the past 4 hours.

  11. Target Monitoring Query: For a specified list of enemy targets, maintain the best possible weapon system that can destroy the target. The system should respond in real-time to a command to fire at any target in the specified list. Targets have priorities associated with them.

  12. Continuous Guidance Query: For a particular vehicle that is driving towards its destination, alert the commander on obstacles that can cause delays. Obstacles include weather warnings, threat of the route coming under indirect fire, etc.

  13. Multi-sensor Fusion Query: Combine directional (e.g., infra-red-triggered sensors) and omni-directional (e.g., seismic-triggered and magnetic-triggered sensors) unattended ground sensor streams with dissimilar indexes.

Last modified: Dec 2 2002. Please send comments and questions to shivnath@stanford.edu