-
Notifications
You must be signed in to change notification settings - Fork 6
BQL examples #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BQL examples #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,6 +156,44 @@ WHERE NOT CONTAINSVALUE(data_map, 'btsg8l9b234ha') | |
| LIMIT 1; | ||
| ``` | ||
|
|
||
| ### Filtering with NOW Keyword | ||
|
|
||
| ```SQL | ||
| SELECT * | ||
| FROM STREAM(30000, TIME) | ||
| WHERE event_timestamp >= NOW | ||
| LIMIT 10; | ||
| ``` | ||
|
|
||
| ### BETWEEN Filter | ||
|
|
||
| This query checks to see if the field ```heart_rate``` is in-between 70 and 100 inclusive and returns all records for which this is true. The ```BETWEEN``` operator can be written in two ways as shown below. | ||
|
|
||
| ```SQL | ||
| SELECT * | ||
| FROM STREAM(30000, TIME) | ||
| WHERE heart_rate BETWEEN (70, 100) | ||
| LIMIT 10; | ||
| ``` | ||
|
|
||
| ```SQL | ||
| SELECT * | ||
| FROM STREAM(30000, TIME) | ||
| WHERE BETWEEN(heart_rate, 70, 100) | ||
| LIMIT 10; | ||
| ``` | ||
|
|
||
| ### IN Filter | ||
|
|
||
| This query checks to see if the field ```color``` is in the given list and returns all records for which is true. | ||
|
|
||
| ```SQL | ||
| SELECT * | ||
| FROM STREAM(30000, TIME) | ||
| WHERE color IN ('red', 'green', 'blue') | ||
| LIMIT 10; | ||
| ``` | ||
|
|
||
| ### Relational Filter comparing to other fields | ||
|
|
||
| Instead of comparing to static, constant values, you may use the extended values notation and set ```kind``` to ```FIELD``` to compare to other fields within the same record. The following query returns the first record for which the ```id``` field is set to the ```uid``` field. | ||
|
|
@@ -1004,6 +1042,109 @@ subtract 24 from it, you get the lower bound of the true count. | |
| Note that this also means the order of the items could be off. If two items had ```Count``` within 24 of each other, it is possible that the higher one *may* actually have had a true count *lower* than | ||
| the second one and possibly be ranked higher. There is no such situation in this result set. | ||
|
|
||
| ### Lateral View Explode | ||
|
|
||
| ```SQL | ||
| SELECT student, score | ||
| FROM STREAM(30000, TIME) | ||
| LATERAL VIEW EXPLODE(test_scores) AS (student, score) | ||
| WHERE score >= 80 | ||
| LIMIT 10; | ||
| ``` | ||
|
|
||
| This query explodes the map ```test_scores``` to the fields ```student``` and ```score```. This effectively generates a record with a key field and value field for each entry in the exploded map. | ||
| The lateral view means the generated records are appended to the original record, though in this query, only the exploded fields have been selected. | ||
|
|
||
| ```javascript | ||
| { | ||
| "records":[ | ||
| { | ||
| "student": "Roger", | ||
| "score": 90 | ||
| }, | ||
| { | ||
| "student": "Albert", | ||
| "score": 92 | ||
| }, | ||
| { | ||
| "student": "Emily", | ||
| "score": 90 | ||
| }, | ||
| { | ||
| "student": "Winston", | ||
| "score": 81 | ||
| }, | ||
| { | ||
| "student": "Jeff", | ||
| "score": 95 | ||
| }, | ||
| { | ||
| "student": "Kristen", | ||
| "score": 97 | ||
| }, | ||
| { | ||
| "student": "Percy", | ||
| "score": 85 | ||
| }, | ||
| { | ||
| "student": "Tyson", | ||
| "score": 80 | ||
| }, | ||
| { | ||
| "student": "Jackie", | ||
| "score": 89 | ||
| }, | ||
| { | ||
| "student": "Alice", | ||
| "score": 100 | ||
| } | ||
| ], | ||
| "meta": "<EDITED OUT>" | ||
| } | ||
| ``` | ||
|
|
||
| ### Multiple Lateral View Explodes | ||
|
|
||
| Multiple lateral view explodes can also be chained in the same query. For instance, using the above example, instead of the map ```test_scores```, there is the list of maps ```tests```. | ||
| This list could be exploded into a field ```test_scores``` which could the be exploded into the fields ```student``` and ```score``` as before. | ||
|
|
||
| ```SQL | ||
| SELECT student, score | ||
| FROM STREAM(30000, TIME) | ||
| LATERAL VIEW EXPLODE(tests) AS test_scores | ||
| LATERAL VIEW EXPLODE(test_scores) AS (student, score) | ||
| WHERE score >= 80 | ||
| LIMIT 10; | ||
| ``` | ||
|
|
||
| ### Outer Query | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mention what can't be done here
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what you mean
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Windowing only I guess
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's there under the query. 👀
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh must have missed it |
||
|
|
||
| ```SQL | ||
| SELECT COUNT(*) | ||
| FROM ( | ||
| SELECT browser_name, COUNT(*) | ||
| FROM STREAM(30000, TIME) | ||
| GROUP BY browser_name | ||
| HAVING COUNT(*) > 10 | ||
| ) | ||
| ``` | ||
|
|
||
| This query has an inner query wrapped by an outer query. Note that the inner query selects from ```STREAM``` and is thus the main query while the outer query selects from the inner query. | ||
| Note also that the inner/main query can have a window while the outer query cannot. | ||
|
|
||
| The query above counts the number of browser names that appear more than 10 times in 30 seconds. | ||
|
|
||
| ```javascript | ||
| { | ||
| "records":[ | ||
| { | ||
| "COUNT(*)": 6 | ||
| } | ||
| ], | ||
| "meta": "<EDITED OUT>" | ||
| } | ||
| ``` | ||
|
|
||
| ### Window - Tumbling Group-By | ||
|
|
||
| ```SQL | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an example for multiple lateral view explodes