Search results

    Edit on GitHub

    Filter a Stream Using The WHERE Clause

    UpSQL enables filtering a stream using the WHERE clause as in ANSI SQL.

    For the following examples, we will assume that:

    1. Three events stream into the data source heartbeat over time:
      { "user_id": 1, “device_id”: 1234, “epoch” : 1520672112456, “heart_rate” : 81}
      { "user_id": 2, “device_id”: 5567, “epoch” : 1520672112456, “heart_rate” : 79}
      { "user_id": 1, “device_id”: 1234, “epoch” : 1520672113456, “heart_rate” : 102}
      
    2. Three events stream into data source location over time:
      {“user_id”: 1, “epoch” : 1573034761, “latitude” : 28.545926, “longitude” : 31.577451}
      {“user_id”: 2, “epoch” : 1573034761, “latitude” : 44.032321, “longitude” : 1.356295}
      {“user_id”: 1, “epoch” : 1573035761, “latitude” : 28.545926, “longitude” : 31.577451}
      

    Example 1:

    The following query:

    SELECT * 
    FROM heartbeat
    WHERE heart_rate > 80
    

    Results in the following output:

    user_id device_id epoch heart_rate
    1 1234 1520672112456 81
    1 1234 1520672113456 102

    We have filtered the data source ֿֿֿheartbeat to get only the events WHERE heart_rate is bigger than 80.

    Example 2:

    The following query:

    SELECT * 
    FROM heartbeat
    WHERE heart_rate > 79 AND heart_rate < 102
    

    Results in the following output:

    user_id device_id epoch heart_rate
    1 1234 1520672112456 81

    We have filtered the data source ֿֿֿheartbeat to get only the events WHERE heart_rate is between 79 and 102.

    Example 3:

    The following query:

    SELECT * 
    FROM heartbeat
    WHERE heart_rate > 79 OR user_id = 2
    

    Results in the following output:

    user_id device_id epoch heart_rate
    1 1234 1520672112456 81
    2 5567 1520672112456 79
    1 1234 1520672113456 102

    We have filtered the data source ֿֿֿheartbeat to get only the events WHERE heart_rate is greater than 79 OR has user_id equals to 2.