Skip to content

Commit 350bedf

Browse files
authored
Merge pull request #6527 from segmentio/maleman842-patch-2
Update Segment Query Language docs
2 parents f7148c4 + 431d664 commit 350bedf

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

src/api/public-api/query-language.md

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ The following tables list the query languages's available functions.
6262
| Syntax | `trait({s: String})` <br> `s` - the name of the the trait to reference |
6363
| Return Type | `ScalarExtractor` |
6464
| Description | Similar to the event operator, the trait operator is used to specify profile trait filter criteria. |
65+
| Notes | You can reference other audiences by using the audience key as the trait name. |
6566
| Example | `trait('total_spend')` |
6667

6768
| `property` | |
@@ -139,24 +140,28 @@ The following tables list the query languages's available functions.
139140
| Return Type | `Scalar` |
140141
| Example | `avg(property('spend'))` |
141142

142-
| `max` | |
143-
| ----------- | ------------------------------------------------------------------------------ |
144-
| Syntax | `max({s: EventPropertyExtractor})`<br>`s` - property to get the maximum value of |
145-
| Return Type | `Scalar` |
146-
| Example | `max(property('spend'))` |
147-
148-
| `min` | |
149-
| ----------- | ------------------------------------------------------------------------------ |
150-
| Syntax | `min({s: EventPropertyExtractor})`<br>`s` - property to get the minimum value of |
151-
| Return Type | `Scalar` |
152-
| Example | `min(property('spend'))` |
153-
154-
| `mode` | |
155-
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
156-
| Syntax | `mode({s: EventPropertyExtractor}, {d: Integer})`<br>`s` - the property to find the most frequent value of<br>`d` - minimum frequency expected |
157-
| Return Type | `Scalar` |
158-
| Description | Find the most frequent value for a given property name. |
159-
| Example | `mode(property('spend'), 2)` |
143+
| `max` | |
144+
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
145+
| Syntax | `max({s: EventPropertyExtractor})` or `max({s: EventPropertyExtractor} as type)`<br>`s` - property to get the maximum value of <br>`type` - number, string |
146+
| Return Type | `Scalar` |
147+
| Notes | If no type is passed, Segment assumes `number` as the `type` and selects the greatest value. You can override the behavior to select the max based on lexicographical ordering by specifying `as string`. |
148+
| Example | `max(property('spend'))`<br>`max(property('spend') as string)` |
149+
150+
| `min` | |
151+
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
152+
| Syntax | `min({s: EventPropertyExtractor})` or `min({s: EventPropertyExtractor} as type)`<br>`s` - property to get the minimum value of <br>`type` - number, string |
153+
| Return Type | `Scalar`
154+
|
155+
| Notes | If no type is passed, Segment assumes `number` as the `type` and selects the smallest value. You can override the behavior to select the max based on lexicographical ordering by specifying `as string`. |
156+
| Example | `min(property('spend'))`<br>`min(property('spend') as string)` |
157+
158+
| `mode` | |
159+
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
160+
| Syntax | `mode({s: EventPropertyExtractor}, {d: Integer})` or `mode({s: EventPropertyExtractor} as type, {d: Integer})`<br>`s` - the property to find the most frequent value of <br>`d` - minimum frequency expected <br>`type` - number, string, array |
161+
| Return Type | `Scalar` |
162+
| Description | Find the most frequent value for a given property name. |
163+
| Notes | If no type is passed, Segment assumes `string` as the `type` and selects the most frequent value assuming all data is a string. `number` will behave the same as `string`. `array` will also behave the same way, except when used in combination with the `$` operator where instead of treating each individual value within the array separately Segment will instead treat the whole array as a string. |
164+
| Example | `mode(property('spend'), 2)`<br>`mode(property('spend') as array, 2)` |
160165

161166
| `first` | |
162167
| ----------- | ------------------------------------------------------------------------------------------------ |
@@ -280,28 +285,28 @@ The following tables list the query languages's available functions.
280285

281286
| `within_last` | |
282287
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
283-
| Syntax | `within_last({d: Integer} {u: TimeUnit})`<br>`d` - duration value<br>u - hour(s) day(s) |
288+
| Syntax | `within_last({d: Integer} {u: TimeUnit})`<br>`d` - duration value<br>u - hour(s), day(s) |
284289
| Return Type | `Comparator` |
285290
| Description | Represents the date range between today and the past `d` days - inclusive where today represents the current date at the time Segment determines audience membership or calculates the trait. |
286291
| Example | `within_last(7 days)` |
287292

288293
| `within_next` | |
289294
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
290-
| Syntax | `within_next({d: Integer} {u: TimeUnit})`<br>`d` - duration value<br>`u` - hour(s) day(s) |
295+
| Syntax | `within_next({d: Integer} {u: TimeUnit})`<br>`d` - duration value<br>`u` - hour(s), day(s) |
291296
| Return Type | `Comparator` |
292297
| Description | Represents the date range between today and the next `d` days - inclusive where today represents the current date at the time Segment determines audience membership or calculates the trait. |
293298
| Example | `within_next(7 days)` |
294299

295300
| `before_last` | |
296301
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
297-
| Syntax | `before_last({d: Integer} {u: TimeUnit})`<br>`d` - duration value<br>u - hour(s) day(s) |
302+
| Syntax | `before_last({d: Integer} {u: TimeUnit})`<br>`d` - duration value<br>u - hour(s), day(s) |
298303
| Return Type | `Comparator` |
299304
| Description | Represents the date range between today - `d` days and any past date prior to that - inclusive where today represents the current date at the time Segment determines audience membership or calculates the trait. |
300305
| Example | `before_last(7 days)` |
301306

302307
| `after_next` | |
303308
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
304-
| Syntax | `after_next({d: Integer} {u: TimeUnit})`<br>`d` - duration value<br>u - hour(s) day(s) |
309+
| Syntax | `after_next({d: Integer} {u: TimeUnit})`<br>`d` - duration value<br>u - hour(s), day(s) |
305310
| Return Type | `Comparator` |
306311
| Description | Represents the date range between today + `d` days and any future date - inclusive where today represents the current date at the time Segment determines audience membership or calculates the trait. |
307312
| Example | `after_next(7 days)` |
@@ -498,13 +503,13 @@ event(‘Shoes Bought’).where( property(‘price’) > 100 AND property(“bra
498503
This example calculates the first-seen spend value for each user, based on all `Shoes Bought` events performed within the last 30 days:
499504

500505
```sql
501-
event(Shoes Bought).within(30 days).first(property(spend))
506+
event('Shoes Bought').within(30 days).first(property('spend'))
502507
```
503508

504509
#### Most frequent spend value
505510

506511
This example calculates the most frequent spend value for each user, based on all `Shoes Bought` events performed within the last 30 days. It only considers spend values that have a minimum frequency of `2`:
507512

508513
```sql
509-
event(Shoes Bought).within(30 days).mode(property(spend), 2)
514+
event('Shoes Bought').within(30 days).mode(property('spend'), 2)
510515
```

0 commit comments

Comments
 (0)