Skip to content

Commit f255256

Browse files
authored
Fix missing imports in Windowing docs (#574)
Closes #398
1 parent c994f48 commit f255256

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

docs/windowing.md

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,27 @@ To use a different timestamp in window aggregations, you need to provide a
4040

4141
A timestamp extractor is a callable object accepting these positional arguments:
4242

43-
- Message value
44-
- Message headers
45-
- Kafka message timestamp in milliseconds
46-
- Kafka timestamp type:
47-
- "0" - timestamp not available,
48-
- "1" - "create time" (specified by a producer)
49-
- "2" - "log-append time" (when the broker received a message)
43+
1. Message value
44+
2. Message headers
45+
3. Kafka message timestamp in milliseconds
46+
4. Kafka timestamp type.
47+
48+
Kafka timestamp type can have these values:
49+
50+
* `0` - timestamp not available,
51+
* `1` - "create time" (specified by a producer)
52+
* `2` - "log-append time" (when the broker received a message)
5053

5154
Timestamp extractor must always return timestamp **as an integer in milliseconds**.
5255

5356
Example:
5457

5558
```python
59+
from quixstreams import Application
60+
from quixstreams.models import TimestampType
61+
from typing import Any, Optional, List, Tuple
62+
63+
# Create an Application
5664
app = Application(...)
5765

5866

@@ -71,6 +79,12 @@ def custom_ts_extractor(
7179
# Passing the timestamp extractor to the topic.
7280
# The window functions will now use the extracted timestamp instead of the Kafka timestamp.
7381
topic = app.topic("input-topic", timestamp_extractor=custom_ts_extractor)
82+
83+
# Create a StreamingDataFrame and keep processing
84+
sdf = app.dataframe(topic)
85+
86+
if __name__ == '__main__':
87+
app.run()
7488
```
7589

7690
### Timestamps of the aggregation results
@@ -80,8 +94,11 @@ Since version 2.6, all windowed aggregations always set timestamps equal to the
8094
**Example:**
8195

8296
```python
97+
from quixstreams import Application
8398
from datetime import timedelta
8499

100+
app = Application(...)
101+
85102
sdf = app.dataframe(...)
86103

87104
# Input:
@@ -167,6 +184,11 @@ Here is how to do it using tumbling windows:
167184

168185
```python
169186
from datetime import timedelta
187+
from quixstreams import Application
188+
189+
app = Application(...)
190+
sdf = app.dataframe(...)
191+
170192

171193
sdf = (
172194
# Extract "temperature" value from the message
@@ -251,7 +273,10 @@ Expected output:
251273

252274
```python
253275
from datetime import timedelta
276+
from quixstreams import Application
254277

278+
app = Application(...)
279+
sdf = app.dataframe(...)
255280

256281
sdf = (
257282
# Extract "temperature" value from the message
@@ -324,7 +349,9 @@ Here is how you can do that with `reduce()`:
324349

325350
```python
326351
from datetime import timedelta
352+
from quixstreams import Application
327353

354+
app = Application(...)
328355
sdf = app.dataframe(...)
329356

330357

@@ -397,7 +424,9 @@ Count all received events over a 10-minute tumbling window.
397424

398425
```python
399426
from datetime import timedelta
427+
from quixstreams import Application
400428

429+
app = Application(...)
401430
sdf = app.dataframe(...)
402431

403432

@@ -435,7 +464,9 @@ Imagine you receive the temperature data from the sensor, and you need to calcul
435464

436465
```python
437466
from datetime import timedelta
467+
from quixstreams import Application
438468

469+
app = Application(...)
439470
sdf = app.dataframe(...)
440471

441472
# Input:
@@ -475,6 +506,12 @@ Since it is rather generic, you may need to transform it into your own schema.
475506
Here is how you can do that:
476507

477508
```python
509+
from datetime import timedelta
510+
from quixstreams import Application
511+
512+
app = Application(...)
513+
sdf = app.dataframe(...)
514+
478515
sdf = (
479516
# Define a tumbling window of 10 minutes
480517
sdf.tumbling_window(timedelta(minutes=10))
@@ -520,8 +557,9 @@ Example:
520557

521558
```python
522559
from datetime import timedelta
560+
from quixstreams import Application
523561

524-
562+
app = Application(...)
525563
sdf = app.dataframe(...)
526564

527565
# Define a 1 hour tumbling window with a grace period of 10 seconds.
@@ -549,8 +587,9 @@ To emit results for each processed message in the stream, use the following API:
549587

550588
```python
551589
from datetime import timedelta
590+
from quixstreams import Application
552591

553-
592+
app = Application(...)
554593
sdf = app.dataframe(...)
555594

556595
# Calculate a sum of values over a window of 10 seconds
@@ -576,8 +615,9 @@ Here is how to emit results only once for each window interval after it's closed
576615

577616
```python
578617
from datetime import timedelta
618+
from quixstreams import Application
579619

580-
620+
app = Application(...)
581621
sdf = app.dataframe(...)
582622

583623
# Calculate a sum of values over a window of 10 seconds

0 commit comments

Comments
 (0)