Skip to content

Commit 6d9a9be

Browse files
authored
Merge pull request #219205 from cebundy/web-pubsub-odata-ref
[Web Pub-Sub]: developmental review of odata filter syntax reference
2 parents 8599daf + cbe0b7e commit 6d9a9be

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

articles/azure-web-pubsub/reference-odata-filter.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ ms.date: 11/11/2022
1010

1111
# OData filter syntax in Azure Web PubSub service
1212

13-
In Azure Web PubSub service, the **filter** parameter specifies inclusion or exclusion criteria for the connections to send messages to. This article describes the OData syntax of **filter** and provides examples.
13+
Azure Web PubSub's **filter** parameter defines inclusion or exclusion criteria for sending messages to connections. This parameter is used in the [Send to all](/rest/api/webpubsub/dataplane/web-pub-sub/send-to-all), [Send to group](/rest/api/webpubsub/dataplane/web-pub-sub/send-to-group), and [Send to user](/rest/api/webpubsub/dataplane/web-pub-sub/send-to-user) operations.
1414

15-
The complete syntax is described in the [formal grammar](#formal-grammar).
15+
This article provides the following resources:
1616

17-
There is also a browsable [syntax diagram](https://aka.ms/awps/filter-syntax-diagram) that allows you to interactively explore the grammar and the relationships between its rules.
17+
- A description of the OData syntax of the **filter** parameter with examples.
18+
- A description of the complete [Extended Backus-Naur Form](#formal-grammar) grammar.
19+
- A browsable [syntax diagram](https://aka.ms/awps/filter-syntax-diagram) to interactively explore the syntax grammar rules.
1820

1921
## Syntax
2022

21-
A filter in the OData language is a Boolean expression, which in turn can be one of several types of expression, as shown by the following EBNF ([Extended Backus-Naur Form](https://en.wikipedia.org/wiki/Extended_Backus–Naur_form)):
23+
A filter in the OData language is boolean expression, which in turn can be one of several types of expression, as shown by the following EBNF ([Extended Backus-Naur Form](https://en.wikipedia.org/wiki/Extended_Backus–Naur_form)) description:
2224

2325
```
2426
/* Identifiers */
@@ -35,40 +37,37 @@ boolean_expression ::= logical_expression
3537
| '(' boolean_expression ')'
3638
```
3739

38-
An interactive syntax diagram is also available:
40+
An interactive syntax diagram is available at, [OData syntax diagram for Azure Web PubSub service](https://aka.ms/awps/filter-syntax-diagram).
3941

40-
> [!div class="nextstepaction"]
41-
> [OData syntax diagram for Azure Web PubSub service](https://aka.ms/awps/filter-syntax-diagram)
42-
43-
> [!NOTE]
44-
> See [formal grammar section](#formal-grammar) for the complete EBNF.
42+
For the complete EBNF, see [formal grammar section](#formal-grammar) .
4543

4644
### Identifiers
4745

48-
The filter syntax is used to filter out the connections matching the filter expression to send messages to.
49-
50-
Azure Web PubSub supports below identifiers:
46+
Using the filter syntax, you can control sending messages to connections matching the identifier criteria. Azure Web PubSub supports below identifiers:
5147

52-
| Identifier | Description | Note | Examples
53-
| --- | --- | -- | --
48+
| Identifier | Description | Note | Examples |
49+
| --- | --- |--| --
5450
| `userId` | The userId of the connection. | Case insensitive. It can be used in [string operations](#supported-operations). | `userId eq 'user1'`
5551
| `connectionId` | The connectionId of the connection. | Case insensitive. It can be used in [string operations](#supported-operations). | `connectionId ne '123'`
5652
| `groups` | The collection of groups the connection is currently in. | Case insensitive. It can be used in [collection operations](#supported-operations). | `'group1' in groups`
5753

58-
Identifiers are used to refer to the property value of a connection. Azure Web PubSub supports 3 identifiers matching the property name of the connection model. and supports identifiers `userId` and `connectionId` in string operations, supports identifier `groups` in [collection operations](#supported-operations). For example, to filter out connections with userId `user1`, we specify the filter as `userId eq 'user1'`. Read through the below sections for more samples using the filter.
54+
Identifiers refer to the property value of a connection. Azure Web PubSub supports three identifiers matching the property name of the connection model. and supports identifiers `userId` and `connectionId` in string operations, supports identifier `groups` in [collection operations](#supported-operations). For example, to filter out connections with userId `user1`, we specify the filter as `userId eq 'user1'`. Read through the below sections for more samples using the filter.
5955

6056
### Boolean expressions
6157

62-
The expression for a filter is a boolean expression. When sending messages to connections, Azure Web PubSub sends messages to connections with filter expression evaluated to `true`.
58+
The expression for a filter is a boolean expression. Azure Web PubSub sends messages to connections with filter expressions evaluated to `true`.
6359

64-
The types of Boolean expressions include:
60+
The types of boolean expressions include:
6561

66-
- Logical expressions that combine other Boolean expressions using the operators `and`, `or`, and `not`.
62+
- Logical expressions that combine other boolean expressions using the operators `and`, `or`, and `not`.
6763
- Comparison expressions, which compare fields or range variables to constant values using the operators `eq`, `ne`, `gt`, `lt`, `ge`, and `le`.
68-
- The Boolean literals `true` and `false`. These constants can be useful sometimes when programmatically generating filters, but otherwise don't tend to be used in practice.
69-
- Boolean expressions in parentheses. Using parentheses can help to explicitly determine the order of operations in a filter. For more information on the default precedence of the OData operators, see [operator precedence section](#operator-precedence).
64+
- The boolean literals `true` and `false`. These constants can be useful sometimes when programmatically generating filters, but otherwise don't tend to be used in practice.
65+
- Boolean expressions in parentheses. Using parentheses helps to explicitly determine the order of operations in a filter. For more information on the default precedence of the OData operators, see [operator precedence section](#operator-precedence).
7066

7167
### Supported operations
68+
69+
The filter syntax supports the following operations:
70+
7271
| Operator | Description | Example
7372
| --- | --- | ---
7473
| **Logical Operators**
@@ -93,14 +92,14 @@ The types of Boolean expressions include:
9392
| `string substring(string p, int startIndex)`,</br>`string substring(string p, int startIndex, int length)` | Substring of the string | `substring(userId,5,2) eq 'ab'` can match connections for user `user-ab-de`
9493
| `bool endswith(string p0, string p1)` | Check if `p0` ends with `p1` | `endswith(userId,'de')` can match connections for user `user-ab-de`
9594
| `bool startswith(string p0, string p1)` | Check if `p0` starts with `p1` | `startswith(userId,'user')` can match connections for user `user-ab-de`
96-
| `int indexof(string p0, string p1)` | Get the index of `p1` in `p0`. Returns `-1` if `p0` does not contain `p1`. | `indexof(userId,'-ab-') ge 0` can match connections for user `user-ab-de`
95+
| `int indexof(string p0, string p1)` | Get the index of `p1` in `p0`. Returns `-1` if `p0` doesn't contain `p1`. | `indexof(userId,'-ab-') ge 0` can match connections for user `user-ab-de`
9796
| `int length(string p)` | Get the length of the input string | `length(userId) gt 1` can match connections for user `user-ab-de`
9897
| **Collection Functions**
99-
| `int length(collection p)` | Get the length of the collection | `length(groups) gt 1` can match connections in 2 groups
98+
| `int length(collection p)` | Get the length of the collection | `length(groups) gt 1` can match connections in two groups
10099

101100
### Operator precedence
102101

103-
If you write a filter expression with no parentheses around its sub-expressions, Azure Web PubSub service will evaluate it according to a set of operator precedence rules. These rules are based on which operators are used to combine sub-expressions. The following table lists groups of operators in order from highest to lowest precedence:
102+
If you write a filter expression with no parentheses around its subexpressions, Azure Web PubSub service will evaluate it according to a set of operator precedence rules. These rules are based on which operators are used to combine subexpressions. The following table lists groups of operators in order from highest to lowest precedence:
104103

105104
| Group | Operator(s) |
106105
| --- | --- |
@@ -116,7 +115,7 @@ length(userId) gt 0 and length(userId) lt 3 or length(userId) gt 7 and length(us
116115
((length(userId) gt 0) and (length(userId) lt 3)) or ((length(userId) gt 7) and (length(userId) lt 10))
117116
```
118117

119-
The `not` operator has the highest precedence of all -- even higher than the comparison operators. That's why if you try to write a filter like this:
118+
The `not` operator has the highest precedence of all, even higher than the comparison operators. If you write a filter like this:
120119

121120
```odata-filter-expr
122121
not length(userId) gt 5
@@ -136,7 +135,7 @@ not (length(userId) gt 5)
136135

137136
### Filter size limitations
138137

139-
There are limits to the size and complexity of filter expressions that you can send to Azure Web PubSub service. The limits are based roughly on the number of clauses in your filter expression. A good guideline is that if you have over 100 clauses, you are at risk of exceeding the limit. We recommend designing your application in such a way that it doesn't generate filters of unbounded size.
138+
There are limits to the size and complexity of filter expressions that you can send to Azure Web PubSub service. The limits are based roughly on the number of clauses in your filter expression. A good guideline is that if you have over 100 clauses, you are at risk of exceeding the limit. To avoid exceeding the limit, design your application so that it doesn't generate filters of unbounded size.
140139

141140
## Examples
142141

@@ -164,7 +163,7 @@ There are limits to the size and complexity of filter expressions that you can s
164163

165164
## Formal grammar
166165

167-
We can describe the subset of the OData language supported by Azure Web PubSub service using an EBNF ([Extended Backus-Naur Form](https://en.wikipedia.org/wiki/Extended_Backus–Naur_form)) grammar. Rules are listed "top-down", starting with the most complex expressions, and breaking them down into more primitive expressions. At the top is the grammar rule for `$filter` that correspond to specific parameter `filter` of the Azure Azure Web PubSub service `Send*` REST APIs:
166+
We can describe the subset of the OData language supported by Azure Web PubSub service using an EBNF ([Extended Backus-Naur Form](https://en.wikipedia.org/wiki/Extended_Backus–Naur_form)) grammar. Rules are listed "top-down", starting with the most complex expressions, then breaking them down into more primitive expressions. The top is the grammar rule for `$filter` that corresponds to specific parameter `filter` of the Azure Web PubSub service `Send*` REST APIs:
168167

169168

170169
```

0 commit comments

Comments
 (0)