diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermark.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermark.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermark.java
@@ -0,0 +1,73 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.Objects;
+
+/**
+ * The {@link BoolWatermark} represents a watermark with a boolean value and an associated
+ * identifier.
+ */
+@Experimental
+public class BoolWatermark implements Watermark {
+
+ private static final long serialVersionUID = 1L;
+
+ private final boolean value;
+
+ private final String identifier;
+
+ public BoolWatermark(boolean value, String identifier) {
+ this.value = value;
+ this.identifier = identifier;
+ }
+
+ public boolean getValue() {
+ return value;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ BoolWatermark that = (BoolWatermark) o;
+ return value == that.value && Objects.equals(identifier, that.identifier);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(value, identifier);
+ }
+
+ @Override
+ public String toString() {
+ return "BoolWatermark{" + "value=" + value + ", identifier='" + identifier + '\'' + '}';
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermarkDeclaration.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/BoolWatermarkDeclaration.java
@@ -0,0 +1,97 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.Objects;
+
+/**
+ * The {@link BoolWatermarkDeclaration} class implements the {@link WatermarkDeclaration} interface
+ * and provides additional functionality specific to boolean-type watermarks. It includes methods
+ * for obtaining combination semantics and creating new bool watermarks.
+ */
+@Experimental
+public class BoolWatermarkDeclaration implements WatermarkDeclaration {
+
+ private final String identifier;
+
+ private final WatermarkCombinationPolicy combinationPolicy;
+
+ private final WatermarkHandlingStrategy defaultHandlingStrategy;
+
+ public BoolWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicy,
+ WatermarkHandlingStrategy defaultHandlingStrategy) {
+ this.identifier = identifier;
+ this.combinationPolicy = combinationPolicy;
+ this.defaultHandlingStrategy = defaultHandlingStrategy;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /** Creates a new {@link BoolWatermark} with the specified boolean value. */
+ public BoolWatermark newWatermark(boolean val) {
+ return new BoolWatermark(val, identifier);
+ }
+
+ public WatermarkCombinationPolicy getCombinationPolicy() {
+ return combinationPolicy;
+ }
+
+ public WatermarkHandlingStrategy getDefaultHandlingStrategy() {
+ return defaultHandlingStrategy;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ BoolWatermarkDeclaration that = (BoolWatermarkDeclaration) o;
+ return Objects.equals(identifier, that.identifier)
+ && Objects.equals(combinationPolicy, that.combinationPolicy)
+ && defaultHandlingStrategy == that.defaultHandlingStrategy;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(identifier, combinationPolicy, defaultHandlingStrategy);
+ }
+
+ @Override
+ public String toString() {
+ return "BoolWatermarkDeclaration{"
+ + "identifier='"
+ + identifier
+ + '\''
+ + ", combinationPolicy="
+ + combinationPolicy
+ + ", defaultHandlingStrategy="
+ + defaultHandlingStrategy
+ + '}';
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermark.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermark.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermark.java
@@ -0,0 +1,72 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.Objects;
+
+/**
+ * The {@link LongWatermark} represents a watermark with a long value and an associated identifier.
+ */
+@Experimental
+public class LongWatermark implements Watermark {
+
+ private static final long serialVersionUID = 1L;
+
+ private final long value;
+
+ private final String identifier;
+
+ public LongWatermark(long value, String identifier) {
+ this.value = value;
+ this.identifier = identifier;
+ }
+
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ LongWatermark that = (LongWatermark) o;
+ return value == that.value && Objects.equals(identifier, that.identifier);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(value, identifier);
+ }
+
+ @Override
+ public String toString() {
+ return "LongWatermark{" + "value=" + value + ", identifier='" + identifier + '\'' + '}';
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermarkDeclaration.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/LongWatermarkDeclaration.java
@@ -0,0 +1,99 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.util.Objects;
+
+/**
+ * The {@link LongWatermarkDeclaration} class implements the {@link WatermarkDeclaration} interface
+ * and provides additional functionality specific to long-type watermarks. It includes methods for
+ * obtaining combination semantics and creating new long watermarks.
+ */
+@Experimental
+public class LongWatermarkDeclaration implements WatermarkDeclaration {
+
+ protected static final long serialVersionUID = 1L;
+
+ protected final String identifier;
+
+ protected final WatermarkCombinationPolicy combinationPolicy;
+
+ protected final WatermarkHandlingStrategy defaultHandlingStrategy;
+
+ public LongWatermarkDeclaration(
+ String identifier,
+ WatermarkCombinationPolicy combinationPolicy,
+ WatermarkHandlingStrategy defaultHandlingStrategy) {
+ this.identifier = identifier;
+ this.combinationPolicy = combinationPolicy;
+ this.defaultHandlingStrategy = defaultHandlingStrategy;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /** Creates a new {@link LongWatermark} with the specified long value. */
+ public LongWatermark newWatermark(long val) {
+ return new LongWatermark(val, identifier);
+ }
+
+ public WatermarkCombinationPolicy getCombinationPolicy() {
+ return combinationPolicy;
+ }
+
+ public WatermarkHandlingStrategy getDefaultHandlingStrategy() {
+ return defaultHandlingStrategy;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ LongWatermarkDeclaration that = (LongWatermarkDeclaration) o;
+ return Objects.equals(identifier, that.identifier)
+ && Objects.equals(combinationPolicy, that.combinationPolicy)
+ && defaultHandlingStrategy == that.defaultHandlingStrategy;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(identifier, combinationPolicy, defaultHandlingStrategy);
+ }
+
+ @Override
+ public String toString() {
+ return "LongWatermarkDeclaration{"
+ + "identifier='"
+ + identifier
+ + '\''
+ + ", combinationPolicy="
+ + combinationPolicy
+ + ", defaultHandlingStrategy="
+ + defaultHandlingStrategy
+ + '}';
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/Watermark.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/Watermark.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/Watermark.java
@@ -0,0 +1,34 @@
+/*
+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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.io.Serializable;
+
+/* * This interface represents a watermark. It will provide a unified triggering and
+ * combination mechanism for user-defined event-like things.
+ */
+@Experimental
+public interface Watermark extends Serializable {
+ /**
+ * Returns the unique identifier for this watermark.
+ *
+ * @return a {@code String} representing the unique identifier of the watermark
+ */
+ String getIdentifier();
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationFunction.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationFunction.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationFunction.java
@@ -0,0 +1,55 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.functions.Function;
+
+/**
+ * The {@link WatermarkCombinationFunction} defines the watermark's comparison/combination semantics
+ * among multiple input channels.
+ */
+@Experimental
+public interface WatermarkCombinationFunction extends Function {
+ /**
+ * The {@link BoolWatermarkCombinationFunction} enum defines the combination semantics for
+ * boolean watermarks. It includes logical operations such as {@code OR} and {@code AND}.
+ */
+ @Experimental
+ enum BoolWatermarkCombinationFunction implements WatermarkCombinationFunction {
+ /** Logical OR combination for boolean watermarks. */
+ OR,
+
+ /** Logical AND combination for boolean watermarks. */
+ AND
+ }
+
+ /**
+ * The {@link NumericWatermarkCombinationFunction} enum defines the combination semantics for
+ * numeric watermarks. It includes operations such as {@code MIN} and {@code MAX}.
+ */
+ @Experimental
+ enum NumericWatermarkCombinationFunction implements WatermarkCombinationFunction {
+ /** Minimum value combination for numeric watermarks. */
+ MIN,
+
+ /** Maximum value combination for numeric watermarks. */
+ MAX
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationPolicy.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationPolicy.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkCombinationPolicy.java
@@ -0,0 +1,79 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * The {@link WatermarkCombinationPolicy} defines when and how to the combine {@link Watermark}s.
+ *
+ *
The watermark combination process will first check the setting of {@link
+ * #combineWaitForAllChannels}. If it is set to true, the ProcessFunction must receive watermarks
+ * from all input channels before it can proceed with the combination.
+ *
+ *
The actual combination of watermarks will then be executed using the specified {@link
+ * #watermarkCombinationFunction}.
+ */
+@Experimental
+public class WatermarkCombinationPolicy implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final WatermarkCombinationFunction watermarkCombinationFunction;
+
+ // Whether the combine process should be executed after the process function receives watermarks
+ // from both upstream channels.
+ private final boolean combineWaitForAllChannels;
+
+ public WatermarkCombinationPolicy(
+ WatermarkCombinationFunction watermarkCombinationFunction,
+ boolean combineWaitForAllChannels) {
+ this.watermarkCombinationFunction = watermarkCombinationFunction;
+ this.combineWaitForAllChannels = combineWaitForAllChannels;
+ }
+
+ public WatermarkCombinationFunction getWatermarkCombinationFunction() {
+ return watermarkCombinationFunction;
+ }
+
+ public boolean isCombineWaitForAllChannels() {
+ return combineWaitForAllChannels;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ WatermarkCombinationPolicy that = (WatermarkCombinationPolicy) o;
+ return combineWaitForAllChannels == that.combineWaitForAllChannels
+ && Objects.equals(watermarkCombinationFunction, that.watermarkCombinationFunction);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(watermarkCombinationFunction, combineWaitForAllChannels);
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclaration.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclaration.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclaration.java
@@ -0,0 +1,34 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+import java.io.Serializable;
+
+/** This class represents the watermark creation and handling policy defined by the user. */
+@Experimental
+public interface WatermarkDeclaration extends Serializable {
+ /**
+ * Returns the unique identifier for this watermark.
+ *
+ * @return a {@code String} representing the unique identifier of the watermark
+ */
+ String getIdentifier();
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclarations.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclarations.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkDeclarations.java
@@ -0,0 +1,185 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.WatermarkCombinationFunction.BoolWatermarkCombinationFunction;
+import org.apache.flink.api.common.watermark.WatermarkCombinationFunction.NumericWatermarkCombinationFunction;
+
+/** The Utils class is used to create {@link WatermarkDeclaration}. */
+@Experimental
+public class WatermarkDeclarations {
+
+ public static WatermarkDeclarationBuilder newBuilder(String identifier) {
+ return new WatermarkDeclarationBuilder(identifier);
+ }
+
+ /** Builder class for {@link WatermarkDeclaration}s. */
+ @Experimental
+ public static class WatermarkDeclarationBuilder {
+
+ protected final String identifier;
+
+ WatermarkDeclarationBuilder(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public LongWatermarkDeclarationBuilder typeLong() {
+ return new LongWatermarkDeclarationBuilder(identifier);
+ }
+
+ public BoolWatermarkDeclarationBuilder typeBool() {
+ return new BoolWatermarkDeclarationBuilder(identifier);
+ }
+
+ @Experimental
+ public static class LongWatermarkDeclarationBuilder {
+ private final String identifier;
+ private boolean combineWaitForAllChannels = false;
+ private WatermarkCombinationFunction combinationFunction =
+ NumericWatermarkCombinationFunction.MIN;
+ private WatermarkHandlingStrategy defaultHandlingStrategy =
+ WatermarkHandlingStrategy.FORWARD;
+
+ public LongWatermarkDeclarationBuilder(String identifier) {
+ this.identifier = identifier;
+ }
+
+ /** Combine and propagate the maximum watermark to downstream. */
+ public LongWatermarkDeclarationBuilder combineFunctionMax() {
+ this.combinationFunction = NumericWatermarkCombinationFunction.MAX;
+ return this;
+ }
+
+ /** Combine and propagate the minimum watermark to downstream. */
+ public LongWatermarkDeclarationBuilder combineFunctionMin() {
+ this.combinationFunction = NumericWatermarkCombinationFunction.MIN;
+ return this;
+ }
+
+ /**
+ * Define whether the framework should send the {@link Watermark} to downstream tasks
+ * when the user-defined {@link Watermark} process method returns {@link
+ * WatermarkHandlingResult#PEEK}. If set to {@link WatermarkHandlingStrategy#FORWARD},
+ * the framework will send the watermark to downstream tasks. If set to {@link
+ * WatermarkHandlingStrategy#IGNORE}, the framework will not take any action.
+ */
+ public LongWatermarkDeclarationBuilder defaultHandlingStrategy(
+ WatermarkHandlingStrategy strategy) {
+ this.defaultHandlingStrategy = strategy;
+ return this;
+ }
+
+ public LongWatermarkDeclarationBuilder defaultHandlingStrategyForward() {
+ this.defaultHandlingStrategy = WatermarkHandlingStrategy.FORWARD;
+ return this;
+ }
+
+ public LongWatermarkDeclarationBuilder defaultHandlingStrategyIgnore() {
+ this.defaultHandlingStrategy = WatermarkHandlingStrategy.IGNORE;
+ return this;
+ }
+
+ /**
+ * Whether the combine process should be executed after the process function receives
+ * watermarks from both upstream channels.
+ */
+ public LongWatermarkDeclarationBuilder combineWaitForAllChannels(
+ boolean combineWaitForAllChannels) {
+ this.combineWaitForAllChannels = combineWaitForAllChannels;
+ return this;
+ }
+
+ public LongWatermarkDeclaration build() {
+ return new LongWatermarkDeclaration(
+ identifier,
+ new WatermarkCombinationPolicy(
+ this.combinationFunction, this.combineWaitForAllChannels),
+ this.defaultHandlingStrategy);
+ }
+ }
+
+ @Experimental
+ public static class BoolWatermarkDeclarationBuilder {
+ private final String identifier;
+ private boolean combineWaitForAllChannels = false;
+ private WatermarkCombinationFunction combinationFunction =
+ BoolWatermarkCombinationFunction.AND;
+ private WatermarkHandlingStrategy defaultHandlingStrategy =
+ WatermarkHandlingStrategy.FORWARD;
+
+ public BoolWatermarkDeclarationBuilder(String identifier) {
+ this.identifier = identifier;
+ }
+
+ /** Propagate the logical OR combination result of boolean watermarks downstream. */
+ public BoolWatermarkDeclarationBuilder combineFunctionOR() {
+ this.combinationFunction = BoolWatermarkCombinationFunction.OR;
+ return this;
+ }
+
+ /** Propagate the logical AND combination result of boolean watermarks downstream. */
+ public BoolWatermarkDeclarationBuilder combineFunctionAND() {
+ this.combinationFunction = BoolWatermarkCombinationFunction.AND;
+ return this;
+ }
+
+ /**
+ * Define whether the framework should send the {@link Watermark} to downstream tasks
+ * when the user-defined {@link Watermark} process method returns {@link
+ * WatermarkHandlingResult#PEEK}. If set to {@link WatermarkHandlingStrategy#FORWARD},
+ * the framework will send the watermark to downstream tasks. If set to {@link
+ * WatermarkHandlingStrategy#IGNORE}, the framework will not take any action.
+ */
+ public BoolWatermarkDeclarationBuilder defaultHandlingStrategy(
+ WatermarkHandlingStrategy strategy) {
+ this.defaultHandlingStrategy = strategy;
+ return this;
+ }
+
+ public BoolWatermarkDeclarationBuilder defaultHandlingStrategyForward() {
+ this.defaultHandlingStrategy = WatermarkHandlingStrategy.FORWARD;
+ return this;
+ }
+
+ public BoolWatermarkDeclarationBuilder defaultHandlingStrategyIgnore() {
+ this.defaultHandlingStrategy = WatermarkHandlingStrategy.IGNORE;
+ return this;
+ }
+
+ /**
+ * Whether the combine process should be executed after the process function receives
+ * watermarks from both upstream channels.
+ */
+ public BoolWatermarkDeclarationBuilder combineWaitForAllChannels(
+ boolean combineWaitForAllChannels) {
+ this.combineWaitForAllChannels = combineWaitForAllChannels;
+ return this;
+ }
+
+ public BoolWatermarkDeclaration build() {
+ return new BoolWatermarkDeclaration(
+ identifier,
+ new WatermarkCombinationPolicy(
+ this.combinationFunction, this.combineWaitForAllChannels),
+ this.defaultHandlingStrategy);
+ }
+ }
+ }
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingResult.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingResult.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingResult.java
@@ -0,0 +1,37 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+/** This class defines watermark handling result for user-defined process function. */
+@Experimental
+public enum WatermarkHandlingResult {
+ /**
+ * Process function only peek the watermark, and it's framework's responsibility to handle this
+ * watermark.
+ */
+ PEEK,
+
+ /**
+ * This watermark should be sent to downstream by process function itself. The framework does no
+ * additional processing.
+ */
+ POLL,
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingStrategy.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingStrategy.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkHandlingStrategy.java
@@ -0,0 +1,34 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+/**
+ * This class defines the framework's behavior when the user-defined {@link Watermark} process
+ * method returns {@link WatermarkHandlingResult#PEEK}.
+ */
+@Experimental
+public enum WatermarkHandlingStrategy {
+ /** The framework shouldn't take any action. */
+ IGNORE,
+
+ /** The framework should send the watermark to downstream. */
+ FORWARD,
+}
diff --git a/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkManager.java b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkManager.java
new file mode 100644
--- /dev/null
+++ b/flink-core-api/src/main/java/org/apache/flink/api/common/watermark/WatermarkManager.java
@@ -0,0 +1,36 @@
+/*
+ * 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.api.common.watermark;
+
+import org.apache.flink.annotation.Experimental;
+
+/**
+ * The {@link WatermarkManager} interface provides a mechanism to emit watermarks from a process
+ * function.
+ */
+@Experimental
+public interface WatermarkManager {
+
+ /**
+ * Emits a watermark from the process function.
+ *
+ * @param watermark the {@link Watermark} to emit.
+ */
+ void emitWatermark(Watermark watermark);
+}
diff --git a/flink-core/src/main/java/org/apache/flink/api/connector/source/Source.java b/flink-core/src/main/java/org/apache/flink/api/connector/source/Source.java
--- a/flink-core/src/main/java/org/apache/flink/api/connector/source/Source.java
+++ b/flink-core/src/main/java/org/apache/flink/api/connector/source/Source.java
@@ -19,8 +19,12 @@
package org.apache.flink.api.connector.source;
import org.apache.flink.annotation.Public;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
import org.apache.flink.core.io.SimpleVersionedSerializer;
+import java.util.Collections;
+import java.util.Set;
+
/**
* The interface for Source. It acts like a factory class that helps construct the {@link
* SplitEnumerator} and {@link SourceReader} and corresponding serializers.
@@ -83,4 +87,14 @@ SplitEnumerator restoreEnumerator(
* @return The serializer for the SplitEnumerator checkpoint.
*/
SimpleVersionedSerializer getEnumeratorCheckpointSerializer();
+
+ /**
+ * Explicitly declare watermarks upfront. Each specific watermark must be declared in this
+ * method before it can be used.
+ *
+ * @return all watermark declarations used by this application.
+ */
+ default Set extends WatermarkDeclaration> declareWatermarks() {
+ return Collections.emptySet();
+ }
}
diff --git a/flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReaderContext.java b/flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReaderContext.java
--- a/flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReaderContext.java
+++ b/flink-core/src/main/java/org/apache/flink/api/connector/source/SourceReaderContext.java
@@ -19,6 +19,7 @@
package org.apache.flink.api.connector.source;
import org.apache.flink.annotation.Public;
+import org.apache.flink.api.common.watermark.Watermark;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.metrics.groups.SourceReaderMetricGroup;
import org.apache.flink.util.UserCodeClassLoader;
@@ -76,4 +77,13 @@ public interface SourceReaderContext {
default int currentParallelism() {
throw new UnsupportedOperationException();
}
+
+ /**
+ * Send the watermark to source output.
+ *
+ *
This should only be used for datastream v2.
+ */
+ default void emitWatermark(Watermark watermark) {
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/BasePartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/BasePartitionedContext.java
new file mode 100644
--- /dev/null
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/BasePartitionedContext.java
@@ -0,0 +1,34 @@
+/*
+ * 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.datastream.api.context;
+
+import org.apache.flink.annotation.Experimental;
+
+/**
+ * On the base of {@link RuntimeContext}, {@link BasePartitionedContext} also contains all
+ * partition-wise execution information, such as getting state, registering timer, etc.
+ */
+@Experimental
+public interface BasePartitionedContext extends RuntimeContext {
+ /** Get the {@link StateManager} of this process function. */
+ StateManager getStateManager();
+
+ /** Get the {@link ProcessingTimeManager} of this process function. */
+ ProcessingTimeManager getProcessingTimeManager();
+}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/NonPartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/NonPartitionedContext.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/NonPartitionedContext.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/NonPartitionedContext.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.context;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkManager;
import org.apache.flink.datastream.api.function.ApplyPartitionFunction;
/**
@@ -32,4 +34,10 @@ public interface NonPartitionedContext extends RuntimeContext {
* non-keyed stream, it will apply to single partition.
*/
void applyToAllPartitions(ApplyPartitionFunction applyPartitionFunction) throws Exception;
+
+ /**
+ * Get {@link WatermarkManager} instance, which allow emitting a {@link Watermark} from the
+ * process function.
+ */
+ WatermarkManager getWatermarkManager();
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/PartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/PartitionedContext.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/PartitionedContext.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/PartitionedContext.java
@@ -20,15 +20,9 @@
import org.apache.flink.annotation.Experimental;
-/**
- * On the base of {@link RuntimeContext}, {@link PartitionedContext} also contains all
- * partition-wise execution information, such as getting state, registering timer, etc.
- */
+/** A {@link BasePartitionedContext} used in one output process functions. */
@Experimental
-public interface PartitionedContext extends RuntimeContext {
- /** Get the {@link StateManager} of this process function. */
- StateManager getStateManager();
-
- /** Get the {@link ProcessingTimeManager} of this process function. */
- ProcessingTimeManager getProcessingTimeManager();
+public interface PartitionedContext extends BasePartitionedContext {
+ /** Get the non-partitioned context of this process function. */
+ NonPartitionedContext getNonPartitionedContext();
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputNonPartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputNonPartitionedContext.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputNonPartitionedContext.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputNonPartitionedContext.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.context;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkManager;
import org.apache.flink.datastream.api.function.TwoOutputApplyPartitionFunction;
/**
@@ -33,4 +35,10 @@ public interface TwoOutputNonPartitionedContext extends RuntimeConte
*/
void applyToAllPartitions(TwoOutputApplyPartitionFunction applyPartitionFunction)
throws Exception;
+
+ /**
+ * Get {@link WatermarkManager} instance, which allow emitting a {@link Watermark} from the
+ * process function.
+ */
+ WatermarkManager getWatermarkManager();
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputPartitionedContext.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputPartitionedContext.java
new file mode 100644
--- /dev/null
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/context/TwoOutputPartitionedContext.java
@@ -0,0 +1,27 @@
+/*
+ * 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.datastream.api.context;
+
+import org.apache.flink.annotation.Experimental;
+
+/** A special {@link BasePartitionedContext} used in two output process functions. */
+@Experimental
+public interface TwoOutputPartitionedContext extends BasePartitionedContext {
+ TwoOutputNonPartitionedContext getNonPartitionedContext();
+}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/OneInputStreamProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/OneInputStreamProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/OneInputStreamProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/OneInputStreamProcessFunction.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.function;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
import org.apache.flink.datastream.api.common.Collector;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.PartitionedContext;
@@ -63,4 +65,10 @@ default void endInput(NonPartitionedContext ctx) {}
* @param ctx runtime context in which this function is executed.
*/
default void onProcessingTimer(long timestamp, Collector output, PartitionedContext ctx) {}
+
+ /** Callback function when receive watermark. */
+ default WatermarkHandlingResult onWatermark(
+ Watermark watermark, Collector output, NonPartitionedContext ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/ProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/ProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/ProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/ProcessFunction.java
@@ -21,6 +21,7 @@
import org.apache.flink.annotation.Experimental;
import org.apache.flink.api.common.functions.Function;
import org.apache.flink.api.common.state.StateDeclaration;
+import org.apache.flink.api.common.watermark.WatermarkDeclaration;
import java.util.Collections;
import java.util.Set;
@@ -38,6 +39,16 @@ default Set usesStates() {
return Collections.emptySet();
}
+ /**
+ * Explicitly declare watermarks upfront. Each specific watermark must be declared in this
+ * method before it can be used.
+ *
+ * @return all watermark declarations used by this application.
+ */
+ default Set extends WatermarkDeclaration> declareWatermarks() {
+ return Collections.emptySet();
+ }
+
/**
* Tear-down method for the user code. It is called after the last call to the main working
* methods (e.g. processRecord).
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputBroadcastStreamProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputBroadcastStreamProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputBroadcastStreamProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputBroadcastStreamProcessFunction.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.function;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
import org.apache.flink.datastream.api.common.Collector;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.PartitionedContext;
@@ -86,4 +88,28 @@ default void endBroadcastInput(NonPartitionedContext ctx) {}
* @param ctx runtime context in which this function is executed.
*/
default void onProcessingTimer(long timestamp, Collector output, PartitionedContext ctx) {}
+
+ /**
+ * Callback function when receive the watermark from broadcast input.
+ *
+ * @param watermark to process.
+ * @param output to emit record.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermarkFromBroadcastInput(
+ Watermark watermark, Collector output, NonPartitionedContext ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
+
+ /**
+ * Callback function when receive the watermark from non-broadcast input.
+ *
+ * @param watermark to process.
+ * @param output to emit record.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermarkFromNonBroadcastInput(
+ Watermark watermark, Collector output, NonPartitionedContext ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputNonBroadcastStreamProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputNonBroadcastStreamProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputNonBroadcastStreamProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoInputNonBroadcastStreamProcessFunction.java
@@ -19,6 +19,8 @@
package org.apache.flink.datastream.api.function;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
import org.apache.flink.datastream.api.common.Collector;
import org.apache.flink.datastream.api.context.NonPartitionedContext;
import org.apache.flink.datastream.api.context.PartitionedContext;
@@ -82,4 +84,28 @@ default void endSecondInput(NonPartitionedContext ctx) {}
* @param ctx runtime context in which this function is executed.
*/
default void onProcessingTimer(long timestamp, Collector output, PartitionedContext ctx) {}
+
+ /**
+ * Callback function when receive the watermark from the first input.
+ *
+ * @param watermark to process.
+ * @param output to emit record.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermarkFromFirstInput(
+ Watermark watermark, Collector output, NonPartitionedContext ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
+
+ /**
+ * Callback function when receive the watermark from the second input.
+ *
+ * @param watermark to process.
+ * @param output to emit record.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermarkFromSecondInput(
+ Watermark watermark, Collector output, NonPartitionedContext ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputApplyPartitionFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputApplyPartitionFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputApplyPartitionFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputApplyPartitionFunction.java
@@ -21,7 +21,7 @@
import org.apache.flink.annotation.Experimental;
import org.apache.flink.api.common.functions.Function;
import org.apache.flink.datastream.api.common.Collector;
-import org.apache.flink.datastream.api.context.PartitionedContext;
+import org.apache.flink.datastream.api.context.TwoOutputPartitionedContext;
/** A function to be applied to all partitions with two outputs. */
@FunctionalInterface
@@ -34,6 +34,9 @@ public interface TwoOutputApplyPartitionFunction extends Function {
* @param secondOutput to emit record to second output.
* @param ctx runtime context in which this function is executed.
*/
- void apply(Collector firstOutput, Collector secondOutput, PartitionedContext ctx)
+ void apply(
+ Collector firstOutput,
+ Collector secondOutput,
+ TwoOutputPartitionedContext ctx)
throws Exception;
}
diff --git a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputStreamProcessFunction.java b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputStreamProcessFunction.java
--- a/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputStreamProcessFunction.java
+++ b/flink-datastream-api/src/main/java/org/apache/flink/datastream/api/function/TwoOutputStreamProcessFunction.java
@@ -19,9 +19,11 @@
package org.apache.flink.datastream.api.function;
import org.apache.flink.annotation.Experimental;
+import org.apache.flink.api.common.watermark.Watermark;
+import org.apache.flink.api.common.watermark.WatermarkHandlingResult;
import org.apache.flink.datastream.api.common.Collector;
-import org.apache.flink.datastream.api.context.PartitionedContext;
import org.apache.flink.datastream.api.context.TwoOutputNonPartitionedContext;
+import org.apache.flink.datastream.api.context.TwoOutputPartitionedContext;
/** This contains all logical related to process and emit records to two output streams. */
@Experimental
@@ -47,7 +49,10 @@ default void open(TwoOutputNonPartitionedContext ctx) throws Excepti
* @param ctx runtime context in which this function is executed.
*/
void processRecord(
- IN record, Collector output1, Collector output2, PartitionedContext ctx)
+ IN record,
+ Collector output1,
+ Collector output2,
+ TwoOutputPartitionedContext ctx)
throws Exception;
/**
@@ -70,5 +75,21 @@ default void onProcessingTimer(
long timestamp,
Collector output1,
Collector output2,
- PartitionedContext ctx) {}
+ TwoOutputPartitionedContext ctx) {}
+
+ /**
+ * Callback function when receive the watermark from the input.
+ *
+ * @param watermark to process.
+ * @param output1 to emit data to the first output.
+ * @param output2 to emit data to the second output.
+ * @param ctx runtime context in which this function is executed.
+ */
+ default WatermarkHandlingResult onWatermark(
+ Watermark watermark,
+ Collector output1,
+ Collector output2,
+ TwoOutputNonPartitionedContext ctx) {
+ return WatermarkHandlingResult.PEEK;
+ }
}
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java
--- a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/ExecutionEnvironmentImpl.java
@@ -193,7 +193,7 @@ public ProcessConfigurableAndNonKeyedPartitionStream fromSource(
return fromSource(new WrappedSource<>(generatorSource), "Collection Source");
} else {
throw new UnsupportedOperationException(
- "Unsupported type of sink, you could use DataStreamV2SourceUtils to wrap a FLIP-27 based source.");
+ "Unsupported type of source, you could use DataStreamV2SourceUtils to wrap a FLIP-27 based source.");
}
}
diff --git a/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/AbstractPartitionedContext.java b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/AbstractPartitionedContext.java
new file mode 100644
--- /dev/null
+++ b/flink-datastream/src/main/java/org/apache/flink/datastream/impl/context/AbstractPartitionedContext.java
@@ -0,0 +1,79 @@
+/*
+ * 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.datastream.impl.context;
+
+import org.apache.flink.datastream.api.context.BasePartitionedContext;
+import org.apache.flink.datastream.api.context.JobInfo;
+import org.apache.flink.datastream.api.context.ProcessingTimeManager;
+import org.apache.flink.datastream.api.context.RuntimeContext;
+import org.apache.flink.datastream.api.context.TaskInfo;
+import org.apache.flink.metrics.MetricGroup;
+import org.apache.flink.runtime.state.v2.OperatorStateStore;
+import org.apache.flink.streaming.api.operators.StreamingRuntimeContext;
+
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+
+/** Abstract implementation class of {@link BasePartitionedContext}. */
+public abstract class AbstractPartitionedContext implements BasePartitionedContext {
+ protected final RuntimeContext context;
+
+ protected final DefaultStateManager stateManager;
+
+ protected final ProcessingTimeManager processingTimeManager;
+
+ public AbstractPartitionedContext(
+ RuntimeContext context,
+ Supplier