You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ws/api.md
+77-31Lines changed: 77 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,78 +12,115 @@ Bullet-BQL provides users with a friendly SQL-like API to submit queries to the
12
12
13
13
## Statement Syntax
14
14
15
-
SELECT select
16
-
FROM stream
15
+
`query` is one of
16
+
17
+
innerQuery
18
+
outerQuery
19
+
20
+
where `innerQuery` is
21
+
22
+
SELECT select FROM stream
23
+
( LATERAL VIEW lateralView )?
17
24
( WHERE expression )?
18
-
( GROUP BY expression ( , expression )* )?
25
+
( GROUP BY expressions )?
19
26
( HAVING expression )?
20
27
( ORDER BY orderBy )?
21
28
( WINDOWING window )?
22
29
( LIMIT Integer )?
23
-
';'?
24
-
25
-
where `select` is
30
+
31
+
and `outerQuery` is
26
32
33
+
SELECT select FROM ( innerQuery )
34
+
( LATERAL VIEW lateralView )?
35
+
( WHERE expression )?
36
+
( GROUP BY expressions )?
37
+
( HAVING expression )?
38
+
( ORDER BY orderBy )?
39
+
( LIMIT Integer )?
40
+
41
+
where `select` is
42
+
27
43
DISTINCT? selectItem ( , selectItem )*
28
-
44
+
29
45
and `selectItem` is one of
30
46
31
47
expression ( AS? identifier )?
48
+
tableFunction
32
49
*
33
50
34
51
and `expression` is one of
35
52
36
53
valueExpression
37
-
fieldExpression
54
+
fieldExpression ( : fieldType )?
55
+
subFieldExpression ( : fieldType )?
56
+
subSubFieldExpression ( : fieldType )?
38
57
listExpression
39
58
expression IS NULL
40
59
expression IS NOT NULL
41
60
unaryExpression
42
-
functionExpression
43
-
expression NOT? IN expression
44
-
expression RLIKE ANY? expression
45
-
expression ( * | / ) expression
61
+
functionExpression
62
+
expression ( * | / | % ) expression
46
63
expression ( + | - ) expression
47
64
expression ( < | <= | > | >= ) ( ANY | ALL )? expression
48
-
expression ( = | != ) ( ANY | ALL )? expression
65
+
expression ( = | != ) ( ANY | ALL )? expression
66
+
expression NOT? RLIKE ANY? expression
67
+
expression NOT? IN expression
68
+
expression NOT? IN ( expressions )
69
+
expressioon NOT? BETWEEN ( expression, expression )
49
70
expression AND expression
50
71
expression XOR expression
51
72
expression OR expression
52
73
( expression )
53
74
54
-
where `valueExpression` is one of Null, Boolean, Integer, Long, Float, Double, or String
75
+
and `expressions` is
76
+
77
+
expression ( , expression )*
55
78
56
-
and `fieldExpression` is one of
79
+
where `valueExpression` is one of Null, Boolean, Integer, Long, Float, Double, String, or `NOW` - a keyword that is converted to the current unix time in milliseconds
Copy file name to clipboardExpand all lines: docs/ws/examples.md
+141Lines changed: 141 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -156,6 +156,44 @@ WHERE NOT CONTAINSVALUE(data_map, 'btsg8l9b234ha')
156
156
LIMIT1;
157
157
```
158
158
159
+
### Filtering with NOW Keyword
160
+
161
+
```SQL
162
+
SELECT*
163
+
FROM STREAM(30000, TIME)
164
+
WHERE event_timestamp >= NOW
165
+
LIMIT10;
166
+
```
167
+
168
+
### BETWEEN Filter
169
+
170
+
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.
171
+
172
+
```SQL
173
+
SELECT*
174
+
FROM STREAM(30000, TIME)
175
+
WHERE heart_rate BETWEEN (70, 100)
176
+
LIMIT10;
177
+
```
178
+
179
+
```SQL
180
+
SELECT*
181
+
FROM STREAM(30000, TIME)
182
+
WHERE BETWEEN(heart_rate, 70, 100)
183
+
LIMIT10;
184
+
```
185
+
186
+
### IN Filter
187
+
188
+
This query checks to see if the field ```color``` is in the given list and returns all records for which is true.
189
+
190
+
```SQL
191
+
SELECT*
192
+
FROM STREAM(30000, TIME)
193
+
WHERE color IN ('red', 'green', 'blue')
194
+
LIMIT10;
195
+
```
196
+
159
197
### Relational Filter comparing to other fields
160
198
161
199
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.
1004
1042
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
1005
1043
the second one and possibly be ranked higher. There is no such situation in this result set.
1006
1044
1045
+
### Lateral View Explode
1046
+
1047
+
```SQL
1048
+
SELECT student, score
1049
+
FROM STREAM(30000, TIME)
1050
+
LATERAL VIEW EXPLODE(test_scores) AS (student, score)
1051
+
WHERE score >=80
1052
+
LIMIT10;
1053
+
```
1054
+
1055
+
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.
1056
+
The lateral view means the generated records are appended to the original record, though in this query, only the exploded fields have been selected.
1057
+
1058
+
```javascript
1059
+
{
1060
+
"records":[
1061
+
{
1062
+
"student":"Roger",
1063
+
"score":90
1064
+
},
1065
+
{
1066
+
"student":"Albert",
1067
+
"score":92
1068
+
},
1069
+
{
1070
+
"student":"Emily",
1071
+
"score":90
1072
+
},
1073
+
{
1074
+
"student":"Winston",
1075
+
"score":81
1076
+
},
1077
+
{
1078
+
"student":"Jeff",
1079
+
"score":95
1080
+
},
1081
+
{
1082
+
"student":"Kristen",
1083
+
"score":97
1084
+
},
1085
+
{
1086
+
"student":"Percy",
1087
+
"score":85
1088
+
},
1089
+
{
1090
+
"student":"Tyson",
1091
+
"score":80
1092
+
},
1093
+
{
1094
+
"student":"Jackie",
1095
+
"score":89
1096
+
},
1097
+
{
1098
+
"student":"Alice",
1099
+
"score":100
1100
+
}
1101
+
],
1102
+
"meta":"<EDITED OUT>"
1103
+
}
1104
+
```
1105
+
1106
+
### Multiple Lateral View Explodes
1107
+
1108
+
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```.
1109
+
This list could be exploded into a field ```test_scores``` which could the be exploded into the fields ```student``` and ```score``` as before.
1110
+
1111
+
```SQL
1112
+
SELECT student, score
1113
+
FROM STREAM(30000, TIME)
1114
+
LATERAL VIEW EXPLODE(tests) AS test_scores
1115
+
LATERAL VIEW EXPLODE(test_scores) AS (student, score)
1116
+
WHERE score >=80
1117
+
LIMIT10;
1118
+
```
1119
+
1120
+
### Outer Query
1121
+
1122
+
```SQL
1123
+
SELECTCOUNT(*)
1124
+
FROM (
1125
+
SELECT browser_name, COUNT(*)
1126
+
FROM STREAM(30000, TIME)
1127
+
GROUP BY browser_name
1128
+
HAVINGCOUNT(*) >10
1129
+
)
1130
+
```
1131
+
1132
+
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.
1133
+
Note also that the inner/main query can have a window while the outer query cannot.
1134
+
1135
+
The query above counts the number of browser names that appear more than 10 times in 30 seconds.
0 commit comments