yunfengzhou-hub commented on code in PR #157: URL: https://github.com/apache/flink-ml/pull/157#discussion_r976408480
########## flink-ml-core/src/main/java/org/apache/flink/ml/common/window/TumbleWindow.java: ########## @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.common.window; + +import org.apache.flink.api.common.time.Time; + +import java.util.Objects; + +/** + * A {@link Window} that windows elements into fixed-size windows based on the timestamp of the + * elements. Windows do not overlap. + */ +public class TumbleWindow implements Window { + /** Size of this window as time interval. */ + Time timeWindowSize; + + /** Offset of this window. Windows start at time N * size + offset, where 0 is the epoch. */ + Time timeWindowOffset; + + /** Size of this window as row-count interval. */ + long countWindowSize; + + boolean isEventTime; + + private TumbleWindow() { + this.timeWindowSize = null; + this.timeWindowOffset = null; + this.isEventTime = true; + this.countWindowSize = -1; + } + + /** + * Creates a new {@link TumbleWindow}. + * + * @param size the size of the window as time interval. + */ + public static TumbleWindow over(Time size) { + return TumbleWindow.over(size, Time.milliseconds(0)); + } + + /** + * Creates a new {@link TumbleWindow}. + * + * @param size the size of the window as time interval. + * @param offset the offset of this window. + */ + public static TumbleWindow over(Time size, Time offset) { + TumbleWindow tumbleWindow = new TumbleWindow(); + tumbleWindow.timeWindowSize = size; + tumbleWindow.timeWindowOffset = offset; + return tumbleWindow; + } + + /** + * Creates a new {@link TumbleWindow}. + * + * @param size the size of the window as row-count interval. + */ + public static TumbleWindow over(long size) { + TumbleWindow tumbleWindow = new TumbleWindow(); + tumbleWindow.countWindowSize = size; + return tumbleWindow; + } + + public TumbleWindow withEventTime() { + isEventTime = true; + return this; + } + + public TumbleWindow withProcessingTime() { Review Comment: Yes. Flink Table API can check the time attribute in the designated column and use processing time accordingly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
