Add Count and Delta WindowPolicy
Project: http://git-wip-us.apache.org/repos/asf/flink/repo Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/bfaad37c Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/bfaad37c Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/bfaad37c Branch: refs/heads/master Commit: bfaad37c0aa8ac43a282a8c9cb2e0d64fdf22f72 Parents: 86c45bf Author: Aljoscha Krettek <[email protected]> Authored: Thu Sep 24 17:42:15 2015 +0200 Committer: Aljoscha Krettek <[email protected]> Committed: Mon Sep 28 17:04:16 2015 +0200 ---------------------------------------------------------------------- .../api/windowing/windowpolicy/Count.java | 58 +++++++++++++++++ .../api/windowing/windowpolicy/Delta.java | 68 ++++++++++++++++++++ 2 files changed, 126 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flink/blob/bfaad37c/flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowpolicy/Count.java ---------------------------------------------------------------------- diff --git a/flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowpolicy/Count.java b/flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowpolicy/Count.java new file mode 100644 index 0000000..5fb7d58 --- /dev/null +++ b/flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowpolicy/Count.java @@ -0,0 +1,58 @@ +/* + * 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.streaming.api.windowing.windowpolicy; + + +/** + * A windowing policy that generates windows based on element counts. + */ +public final class Count extends WindowPolicy { + + private static final long serialVersionUID = 3197290738634320211L; + + private long size; + + /** Instantiation only via factory method */ + private Count(long size) { + this.size = size; + } + + public long getSize() { + return size; + } + + @Override + public String toString() { + return "Count Window (" + size + ')'; + } + + // ------------------------------------------------------------------------ + // Factory + // ------------------------------------------------------------------------ + + /** + * Creates a count based windowing policy + * + * @param size The size of the generated windows. + * @return The time policy. + */ + public static Count of(long size) { + return new Count(size); + } +} http://git-wip-us.apache.org/repos/asf/flink/blob/bfaad37c/flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowpolicy/Delta.java ---------------------------------------------------------------------- diff --git a/flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowpolicy/Delta.java b/flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowpolicy/Delta.java new file mode 100644 index 0000000..4a3082c --- /dev/null +++ b/flink-staging/flink-streaming/flink-streaming-core/src/main/java/org/apache/flink/streaming/api/windowing/windowpolicy/Delta.java @@ -0,0 +1,68 @@ +/* + * 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.streaming.api.windowing.windowpolicy; + + +import org.apache.flink.streaming.api.functions.windowing.delta.DeltaFunction; + +/** + * A windowing policy that generates windows based on a delta between elements. + */ +public final class Delta<T> extends WindowPolicy { + + private static final long serialVersionUID = 3197290738634320211L; + + private DeltaFunction<T> deltaFunction; + + private double threshold; + + /** Instantiation only via factory method */ + private Delta(DeltaFunction<T> deltaFunction, double threshold) { + this.deltaFunction = deltaFunction; + this.threshold = threshold; + } + + public DeltaFunction<T> getDeltaFunction() { + return deltaFunction; + } + + public double getThreshold() { + return threshold; + } + + @Override + public String toString() { + return "Delta Window (" + deltaFunction + ", " + threshold + ')'; + } + + // ------------------------------------------------------------------------ + // Factory + // ------------------------------------------------------------------------ + + /** + * Creates a delta based windowing policy + * + * @param threshold The threshold for deltas at which to trigger windows + * @param deltaFunction The delta function + * @return The time policy. + */ + public static <T> Delta<T> of(double threshold, DeltaFunction<T> deltaFunction) { + return new Delta<T>(deltaFunction, threshold); + } +}
