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: data-explorer/kusto/query/scan-operator.md
+50-7Lines changed: 50 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: scan operator
3
3
description: Learn how to use the scan operator to scan data, match, and build sequences based on the predicates.
4
4
ms.reviewer: alexans
5
5
ms.topic: reference
6
-
ms.date: 01/22/2025
6
+
ms.date: 05/30/2025
7
7
---
8
8
# scan operator
9
9
@@ -71,7 +71,7 @@ Each input record is evaluated against all of the steps in reverse order, from t
71
71
72
72
***Check 2:** If the state of *s_k* has an active sequence or *s_k* is the first step, and *r* meets the *Condition* of *s_k*, then a match occurs. The match leads to the following actions:
73
73
1. The assignments of *s_k* are calculated and extend *r*.
74
-
2. The values that represent *s_k* in the state of *s_k* are replaced with the values of the extended *r*.
74
+
1. The values that represent *s_k* in the state of *s_k* are replaced with the values of the extended *r*.
75
75
1. If *s_k* is defined as `output=all`, the extended *r* is added to the output.
76
76
1. If *s_k* is the first step, a new sequence begins and the match ID increases by `1`. This only affects the output when `with_match_id` is used.
77
77
@@ -82,7 +82,7 @@ For a detailed example of this logic, see the [scan logic walkthrough](#scan-log
82
82
## Examples
83
83
84
84
The example in this section shows how to use the syntax to help you get started.
Calculate the session start time, end time, and duration for each user's session using the `scan` operator. A session is defined as a period between a user's login and the subsequent logout. By combining `partition` and `scan` with `output=none` and `output=all`, this pattern ensures that a **single row is returned per session** (i.e., per login/logout pair), rather than a row per event.
236
+
237
+
The logic works by:
238
+
239
+
* In step s1: Capturing the login timestamp using a scan step with `output=none`
240
+
* In step s2: Emitting a row only when a matching logout is found using `output=all`
241
+
242
+
:::moniker range="azure-data-explorer"
243
+
> [!div class="nextstepaction"]
244
+
> <ahref="https://dataexplorer.azure.com/clusters/help/databases/Samples?query=H4sIAAAAAAAAA41Sz2%2BCMBS%2Bk%2FA%2FvHiCBA0tkmkNO7nDkh29LTtUbLALFkIfLib74%2FdAoWYuTjhA%2B74fr19fqRDeqsK%2BHJVBCxnsJNK7LVWw0QdlUR5qQXsKaRVBa1XzuhbaYAQ9ZXOqlbDYaFOEvvfue0DPgA94zOfTOJ3yBcQLwVLBkzACFsGkrAptJtFdfBIThfD8IfxSsFjwJ8Inj%2BAZ7%2FTnqeunavEugRFaJNw19B8hETwVbOk66gi%2B97HyPRe5732DrRqE7emSbgRj8l2xlg1q1JWBPcU%2Bo6zJqzhlRqI%2BKkeD4NzKIDaKgLQ5nGtklUsDO5WXslEQUL1BAe5%2BldldL62ylpzXLXnSV0C3bWtpQvjSuB8se1tUNVgGdMa6xcxURgk3IpBlw51A9gy9Lw3b2OPqtxAfhGRZ%2FqHTJXktZNms%2F%2B1PcC18c4brIkxH4qUBmuGwD72pPlWO44048RvBH%2FdgF3BCAwAA"target="_blank">Run the query</a>
245
+
::: moniker-end
246
+
247
+
```kusto
248
+
let LogsEvents = datatable(Timestamp:datetime, userID:int, EventType:string)
Find all sequences of events between the event `Start` and the event `Stop` that occur within 5 minutes. Assign a match ID for each sequence.
@@ -369,7 +413,7 @@ The "X" indicates that a specific field is irrelevant for that step.
369
413
This section follows the [matching logic](#matching-logic) through each record of the `Events` table, explaining the transformation of the state and output at each step.
370
414
371
415
> [!NOTE]
372
-
> An input record is evaluated against the steps in reverse order, from the last step (`s3`) to the first step (`s1`).
416
+
> An input record is evaluated against the steps in reverse order, from the last step (`s3`) to the first step (`s1`).
373
417
374
418
#### Record 1
375
419
@@ -431,7 +475,7 @@ This section follows the [matching logic](#matching-logic) through each record o
431
475
|s2|0|00:01:00|"Start"|00:02:00|"B"|X|X|
432
476
|s3||||||||
433
477
434
-
#### Record 4
478
+
#### Record 4
435
479
436
480
|Ts|Event|
437
481
|---|---|
@@ -463,7 +507,6 @@ This section follows the [matching logic](#matching-logic) through each record o
463
507
*`s2`: **Check 1** isn't passed because the state of `s1` is empty, and **Check 2** isn't passed because `s2` lacks an active sequence.
464
508
*`s1`: **Check 1** is irrelevant because there's no previous step. **Check 2** isn't passed because the record doesn't meet the condition of `Event == "Start"`.
@@ -502,7 +545,7 @@ This section follows the [matching logic](#matching-logic) through each record o
502
545
503
546
*`s3`: **Check 1** isn't passed because the state of `s2` is empty, and **Check 2** isn't passed because it doesn't meet the condition of `Event == "Stop"`.
504
547
*`s2`: **Check 1** isn't passed because the state of `s1` is empty, and **Check 2** isn't passed because `s2` lacks an active sequence.
505
-
*`s1`: **Check 1** isn't passed because there's no previous step. it passes **Check 2** because it meets the condition of `Event == "Start"`. This match initiates a new sequence in `s1` with a new `m_id`. **Record 7** and its `m_id` (`1`) are added to the state and the output.
548
+
*`s1`: **Check 1** isn't passed because there's no previous step. it passes **Check 2** because it meets the condition of `Event == "Start"`. This match initiates a new sequence in `s1` with a new `m_id`. **Record 7** and its `m_id` (`1`) are added to the state and the output.
0 commit comments