|
1 |
| -# Check Keys and NULL values |
| 1 | +# Check keys and null values |
2 | 2 |
|
3 |
| -> Feature available on Fluent Bit >= 1.2 |
| 3 | +When working with structured messages (also known as records), there are certain cases where you might want to confirm whether a key exists, and whether its value is null or not null. |
4 | 4 |
|
5 |
| -When working with structured messages \(records\), there are certain cases where we want to know if a key exists, if it value is _null_ or have a value different than _null_. |
| 5 | +In Fluent Bit, records are a binary serialization of maps with keys and value. A value can be `null`, which is a valid data type. The following statements can be applied in Fluent Bit SQL: |
6 | 6 |
|
7 |
| -[Fluent Bit](https://fluentbit.io) internal records are a binary serialization of maps with keys and values. A value can be _null_ which is a valid data type. In our SQL language we provide the following statements that can be applied to the conditionals statements: |
| 7 | +## Check if a key value is null |
8 | 8 |
|
9 |
| -## Check if a key value IS NULL |
10 |
| - |
11 |
| -The following SQL statement can be used to retrieve all records from stream _test_ where the key called _phone_ has a _null_ value: |
| 9 | +The following statement retrieves all records from the stream `test` where the key `phone` has a value of `null`: |
12 | 10 |
|
13 | 11 | ```sql
|
14 | 12 | SELECT * FROM STREAM:test WHERE phone IS NULL;
|
15 | 13 | ```
|
16 | 14 |
|
17 |
| -## Check if a key value IS NOT NULL |
| 15 | +## Check if a key value is not null |
18 | 16 |
|
19 |
| -Similar to the example above, there are cases where we want to retrieve all records that certain key value have something different than _null_: |
| 17 | +The following statement is similar to the previous example, but instead retrieves all records from the stream `test` where the key `phone` has a non-null value: |
20 | 18 |
|
21 | 19 | ```sql
|
22 | 20 | SELECT * FROM STREAM:test WHERE phone IS NOT NULL;
|
23 | 21 | ```
|
24 | 22 |
|
25 | 23 | ## Check if a key exists
|
26 | 24 |
|
27 |
| -Another common use-case is to check if certain key exists in the record. We provide specific record functions that can be used in the conditional part of the SQL statement. The prototype of the function to check if a key exists in the record is the following: |
28 |
| - |
| 25 | +You can also confirm whether a certain key exists in a record at all, regardless of its value. Fluent Bit provides specific record functions that you can use in the condition part of the SQL statement. The following function determines whether `key` exists in a record: |
29 | 26 | ```text
|
30 | 27 | @record.contains(key)
|
31 | 28 | ```
|
32 | 29 |
|
33 |
| -The following example query all records that contains a key called _phone_: |
| 30 | +For example, the following statement retrieves all records that contain a key called `phone`: |
34 | 31 |
|
35 | 32 | ```sql
|
36 | 33 | SELECT * FROM STREAM:test WHERE @record.contains(phone);
|
37 | 34 | ```
|
38 |
| - |
0 commit comments