/*
 * 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.table.connector.source.abilities;

import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.api.common.eventtime.TimestampAssigner;
import org.apache.flink.api.common.eventtime.Watermark;
import org.apache.flink.api.common.eventtime.WatermarkGenerator;
import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.table.connector.source.ScanTableSource;
import org.apache.flink.table.connector.source.SourceProvider;
import org.apache.flink.table.data.RowData;

/**
 * Enables to push down watermarks into a {@link ScanTableSource}.
 *
 * <p>The concept of watermarks defines when time operations based on an event time attribute will be
 * triggered. A watermark tells operators that no elements with a timestamp older or equal to the watermark
 * timestamp should arrive at the operator. Thus, watermarks are a trade-off between latency and completeness.
 *
 * <p>Given the following SQL:
 * <pre>{@code
 *   CREATE TABLE t (i INT, ts TIMESTAMP(3), WATERMARK FOR ts AS ts - INTERVAL '5' SECOND)  // `ts` becomes a time attribute
 * }</pre>
 *
 * <p>In the above example, generated watermarks are lagging 5 seconds behind the highest seen timestamp.
 *
 * <p>For correctness, it might be necessary to perform the watermark generation as early as
 * possible in order to be close to the actual data generation within a source's data partition.
 *
 * <p>If the {@link ScanTableSource#getScanRuntimeProvider(ScanTableSource.ScanContext)} returns
 * {@link SourceProvider}, watermarks are automatically pushed into the runtime source operator
 * by the framework. So in this case, this interface is not needed to implemented.
 *
 * <p>However, if the {@link ScanTableSource} does't work with {@link SourceProvider} and this
 * interface is not implemented, watermarks are generated in a subsequent operation after the
 * source. In this case, it is recommended to implement this interface to perform the watermark
 * generation within source's data partition.
 *
 * <p>This interface provides a {@link WatermarkStrategy} that needs to be applied to a runtime
 * implementation. Most built-in Flink sources provide a way of setting the watermark generator.
 */
@PublicEvolving
public interface SupportsWatermarkPushDown {

	/**
	 * Provides {@link WatermarkStrategy} which defines how to generate {@link Watermark}s in
	 * the stream sources. The {@link WatermarkStrategy} is a builder/factory for the actual
	 * runtime implementation {@link WatermarkGenerator} that generates the watermarks and the
	 * {@link TimestampAssigner} which assigns the event time timestamps to each record.
	 */
	void applyWatermark(WatermarkStrategy<RowData> watermarkStrategy);

}

@@ -2352,18 +2352,22 @@
 ermarks 
-ar
+will b
 e automa
@@ -2439,12 +2439,9 @@
 rk. 
-So i
+I
 n th
@@ -2460,25 +2460,27 @@
 s interface 
-i
+doe
 s not needed
@@ -2477,22 +2477,23 @@
 not need
-ed
  to 
+be 
 implemen
@@ -2510,18 +2510,9 @@
  %3Cp%3E
-However, i
+I
 f th
@@ -2545,20 +2545,21 @@
 does
-'t work with
+ not return a
  %7B@l
@@ -2586,19 +2586,16 @@
 and this
-%0A *
  interfa
@@ -2599,16 +2599,19 @@
 rface is
+%0A *
  not imp
@@ -2680,19 +2680,16 @@
 fter the
-%0A *
  source.
@@ -2702,16 +2702,19 @@
 is case,
+%0A *
  it is r
@@ -2776,19 +2776,16 @@
 atermark
-%0A *
  generat
@@ -2795,32 +2795,35 @@
  within source's
+%0A *
  data partition.
@@ -2912,17 +2912,19 @@
 lied to 
-a
+the
  runtime
@@ -3105,16 +3105,18 @@
 rovides 
+a 
 %7B@link W
@@ -3206,19 +3206,29 @@
 m source
-s. 
+.%0A%09 *%0A%09 * %3Cp%3E
 The %7B@li
@@ -3284,20 +3284,16 @@
 e actual
-%0A%09 *
  runtime
@@ -3307,16 +3307,123 @@
 entation
+%0A%09 * consisting of %7B@link TimestampAssigner%7D (assigns the event-time timestamps to each record) and%0A%09 * the
  %7B@link 
@@ -3442,21 +3442,17 @@
 erator%7D 
-that 
+(
 generate
@@ -3471,101 +3471,200 @@
 arks
- and the%0A%09 * %7B@link TimestampAssigner%7D which assigns the event time timestamps to each record
+).%0A%09 *%0A%09 * %3Cp%3ENote: If necessary, the watermark strategy will contain required computed column expressions%0A%09 * and consider metadata columns (if %7B@link SupportsReadingMetadata%7D is implemented)
 .%0A%09 

Improve SupportsWatermarkPushDown JavaDocs