You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "venn wu (JIRA)" <ji...@apache.org> on 2019/05/23 09:21:00 UTC

[jira] [Commented] (FLINK-11326) Allow negative offsets in window assigners

    [ https://issues.apache.org/jira/browse/FLINK-11326?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16846564#comment-16846564 ] 

venn wu commented on FLINK-11326:
---------------------------------

Affects Version 

> Allow negative offsets in window assigners
> ------------------------------------------
>
>                 Key: FLINK-11326
>                 URL: https://issues.apache.org/jira/browse/FLINK-11326
>             Project: Flink
>          Issue Type: Bug
>          Components: API / DataStream
>    Affects Versions: 1.6.3, 1.7.1
>            Reporter: TANG Wen-hui
>            Assignee: Kezhu Wang
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.8.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> According to comments, we can use offset to adjust windows to timezones other than UTC-0. For example, in China you would have to specify an offset of {{Time.hours(-8)}}. 
>  
> {code:java}
> /**
>  * Creates a new {@code TumblingEventTimeWindows} {@link WindowAssigner} that assigns
>  * elements to time windows based on the element timestamp and offset.
>  *
>  * <p>For example, if you want window a stream by hour,but window begins at the 15th minutes
>  * of each hour, you can use {@code of(Time.hours(1),Time.minutes(15))},then you will get
>  * time windows start at 0:15:00,1:15:00,2:15:00,etc.
>  *
>  * <p>Rather than that,if you are living in somewhere which is not using UTC±00:00 time,
>  * such as China which is using UTC+08:00,and you want a time window with size of one day,
>  * and window begins at every 00:00:00 of local time,you may use {@code of(Time.days(1),Time.hours(-8))}.
>  * The parameter of offset is {@code Time.hours(-8))} since UTC+08:00 is 8 hours earlier than UTC time.
>  *
>  * @param size The size of the generated windows.
>  * @param offset The offset which window start would be shifted by.
>  * @return The time policy.
>  */
> public static TumblingEventTimeWindows of(Time size, Time offset) {
>  return new TumblingEventTimeWindows(size.toMilliseconds(), offset.toMilliseconds());
> }{code}
>  
> but when offset is smaller than zero, a IllegalArgumentException will be throwed.
>  
> {code:java}
> protected TumblingEventTimeWindows(long size, long offset) {
>  if (offset < 0 || offset >= size) {
>  throw new IllegalArgumentException("TumblingEventTimeWindows parameters must satisfy 0 <= offset < size");
>  }
>  this.size = size;
>  this.offset = offset;
> }{code}
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)