18
18
from typing import Iterable , Tuple , Dict
19
19
20
20
from pyflink .common import Configuration
21
- from pyflink .common .time import Duration
21
+ from pyflink .common .time import Time
22
22
from pyflink .common .typeinfo import Types
23
23
from pyflink .common .watermark_strategy import WatermarkStrategy , TimestampAssigner
24
24
from pyflink .datastream .data_stream import DataStream
@@ -59,7 +59,7 @@ def test_event_time_tumbling_window(self):
59
59
.with_timestamp_assigner (SecondColumnTimestampAssigner ())
60
60
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
61
61
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
62
- .window (TumblingEventTimeWindows .of (Duration . of_millis (5 ))) \
62
+ .window (TumblingEventTimeWindows .of (Time . milliseconds (5 ))) \
63
63
.process (CountWindowProcessFunction (),
64
64
Types .TUPLE ([Types .STRING (), Types .LONG (), Types .LONG (), Types .INT ()])) \
65
65
.add_sink (self .test_sink )
@@ -94,7 +94,7 @@ def test_event_time_sliding_window(self):
94
94
95
95
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
96
96
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
97
- .window (SlidingEventTimeWindows .of (Duration . of_millis (5 ), Duration . of_millis (2 ))) \
97
+ .window (SlidingEventTimeWindows .of (Time . milliseconds (5 ), Time . milliseconds (2 ))) \
98
98
.process (CountWindowProcessFunction (),
99
99
Types .TUPLE ([Types .STRING (), Types .LONG (), Types .LONG (), Types .INT ()])) \
100
100
.add_sink (self .test_sink )
@@ -128,7 +128,7 @@ def test_event_time_session_window(self):
128
128
129
129
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
130
130
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
131
- .window (EventTimeSessionWindows .with_gap (Duration . of_millis (5 ))) \
131
+ .window (EventTimeSessionWindows .with_gap (Time . milliseconds (5 ))) \
132
132
.process (CountWindowProcessFunction (),
133
133
Types .TUPLE ([Types .STRING (), Types .LONG (), Types .LONG (), Types .INT ()])) \
134
134
.add_sink (self .test_sink )
@@ -166,7 +166,7 @@ def test_window_reduce_passthrough(self):
166
166
.with_timestamp_assigner (SecondColumnTimestampAssigner ())
167
167
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
168
168
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
169
- .window (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
169
+ .window (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
170
170
.reduce (lambda a , b : (b [0 ], a [1 ] + b [1 ]),
171
171
output_type = Types .TUPLE ([Types .STRING (), Types .INT ()])) \
172
172
.add_sink (self .test_sink )
@@ -194,7 +194,7 @@ def process(self, key, context: ProcessWindowFunction.Context,
194
194
195
195
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
196
196
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
197
- .window (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
197
+ .window (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
198
198
.reduce (lambda a , b : (b [0 ], a [1 ] + b [1 ]),
199
199
window_function = MyProcessFunction (),
200
200
output_type = Types .STRING ()) \
@@ -243,7 +243,7 @@ def merge(self, acc_a: Tuple[str, Dict[int, int]], acc_b: Tuple[str, Dict[int, i
243
243
244
244
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
245
245
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
246
- .window (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
246
+ .window (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
247
247
.aggregate (MyAggregateFunction (),
248
248
output_type = Types .TUPLE ([Types .STRING (), Types .INT ()])) \
249
249
.add_sink (self .test_sink )
@@ -276,7 +276,7 @@ def merge(self, acc_a: Tuple[int, str], acc_b: Tuple[int, str]):
276
276
277
277
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
278
278
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
279
- .window (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
279
+ .window (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
280
280
.aggregate (MyAggregateFunction (),
281
281
accumulator_type = Types .TUPLE ([Types .INT (), Types .STRING ()]),
282
282
output_type = Types .TUPLE ([Types .STRING (), Types .INT ()])) \
@@ -317,7 +317,7 @@ def process(self, key: str, context: ProcessWindowFunction.Context,
317
317
318
318
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
319
319
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
320
- .window (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
320
+ .window (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
321
321
.aggregate (MyAggregateFunction (),
322
322
window_function = MyProcessWindowFunction (),
323
323
accumulator_type = Types .TUPLE ([Types .INT (), Types .STRING ()]),
@@ -341,7 +341,7 @@ def test_session_window_late_merge(self):
341
341
.with_timestamp_assigner (SecondColumnTimestampAssigner ())
342
342
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
343
343
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
344
- .window (EventTimeSessionWindows .with_gap (Duration . of_millis (5 ))) \
344
+ .window (EventTimeSessionWindows .with_gap (Time . milliseconds (5 ))) \
345
345
.process (CountWindowProcessFunction (),
346
346
Types .TUPLE ([Types .STRING (), Types .LONG (), Types .LONG (), Types .INT ()])) \
347
347
.add_sink (self .test_sink )
@@ -360,7 +360,7 @@ def test_event_time_session_window_with_purging_trigger(self):
360
360
361
361
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
362
362
.key_by (lambda x : x [0 ], key_type = Types .STRING ()) \
363
- .window (EventTimeSessionWindows .with_gap (Duration . of_millis (3 ))) \
363
+ .window (EventTimeSessionWindows .with_gap (Time . milliseconds (3 ))) \
364
364
.trigger (PurgingTrigger .of (EventTimeTrigger .create ())) \
365
365
.process (CountWindowProcessFunction (),
366
366
Types .TUPLE ([Types .STRING (), Types .LONG (), Types .LONG (), Types .INT ()])) \
@@ -408,7 +408,7 @@ def test_event_time_tumbling_window_all(self):
408
408
.with_timestamp_assigner (SecondColumnTimestampAssigner ())
409
409
410
410
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
411
- .window_all (TumblingEventTimeWindows .of (Duration . of_millis (5 ))) \
411
+ .window_all (TumblingEventTimeWindows .of (Time . milliseconds (5 ))) \
412
412
.process (CountAllWindowProcessFunction (),
413
413
Types .TUPLE ([Types .LONG (), Types .LONG (), Types .INT ()])) \
414
414
.add_sink (self .test_sink )
@@ -426,7 +426,7 @@ def test_window_all_reduce(self):
426
426
watermark_strategy = WatermarkStrategy .for_monotonous_timestamps () \
427
427
.with_timestamp_assigner (SecondColumnTimestampAssigner ())
428
428
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
429
- .window_all (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
429
+ .window_all (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
430
430
.reduce (lambda a , b : (a [0 ], a [1 ] + b [1 ]),
431
431
output_type = Types .TUPLE ([Types .STRING (), Types .INT ()])) \
432
432
.add_sink (self .test_sink )
@@ -454,7 +454,7 @@ def process(self, context: 'ProcessAllWindowFunction.Context',
454
454
)
455
455
456
456
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
457
- .window_all (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
457
+ .window_all (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
458
458
.reduce (lambda a , b : (a [0 ], a [1 ] + b [1 ]),
459
459
window_function = MyProcessFunction (),
460
460
output_type = Types .STRING ()) \
@@ -501,7 +501,7 @@ def merge(self, acc_a: Tuple[str, Dict[int, int]], acc_b: Tuple[str, Dict[int, i
501
501
return acc_a [0 ], new_number_map
502
502
503
503
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
504
- .window_all (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
504
+ .window_all (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
505
505
.aggregate (MyAggregateFunction (),
506
506
output_type = Types .TUPLE ([Types .STRING (), Types .INT ()])) \
507
507
.add_sink (self .test_sink )
@@ -540,7 +540,7 @@ def process(self, context: ProcessAllWindowFunction.Context,
540
540
yield "key {} timestamp sum {}" .format (agg_result [0 ], agg_result [1 ])
541
541
542
542
data_stream .assign_timestamps_and_watermarks (watermark_strategy ) \
543
- .window_all (EventTimeSessionWindows .with_gap (Duration . of_millis (2 ))) \
543
+ .window_all (EventTimeSessionWindows .with_gap (Time . milliseconds (2 ))) \
544
544
.aggregate (MyAggregateFunction (),
545
545
window_function = MyProcessWindowFunction (),
546
546
accumulator_type = Types .TUPLE ([Types .INT (), Types .STRING ()]),
@@ -573,7 +573,7 @@ def test_side_output_late_data(self):
573
573
type_info = Types .ROW ([Types .STRING (), Types .INT ()]))
574
574
ds2 = ds1 .assign_timestamps_and_watermarks (watermark_strategy ) \
575
575
.key_by (lambda e : e [0 ]) \
576
- .window (TumblingEventTimeWindows .of (Duration . of_millis (5 ))) \
576
+ .window (TumblingEventTimeWindows .of (Time . milliseconds (5 ))) \
577
577
.allowed_lateness (0 ) \
578
578
.side_output_late_data (tag ) \
579
579
.process (CountWindowProcessFunction (),
@@ -619,7 +619,7 @@ def extract_timestamp(self, value: tuple, record_timestamp: int) -> int:
619
619
ds .key_by (
620
620
lambda x : (x [0 ], x [1 ], x [2 ])
621
621
).window (
622
- TumblingEventTimeWindows .of (Duration . of_minutes (1 ))
622
+ TumblingEventTimeWindows .of (Time . minutes (1 ))
623
623
).reduce (
624
624
lambda x , y : (x [0 ], x [1 ], x [2 ], x [3 ] + y [3 ]),
625
625
output_type = Types .TUPLE ([Types .LONG (), Types .STRING (), Types .STRING (), Types .INT ()])
0 commit comments