HeartSaVioR commented on code in PR #39931: URL: https://github.com/apache/spark/pull/39931#discussion_r1109097693
########## sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/WatermarkPropagator.scala: ########## @@ -0,0 +1,300 @@ +/* + * 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.spark.sql.execution.streaming + +import java.{util => jutil} + +import scala.collection.mutable + +import org.apache.spark.internal.Logging +import org.apache.spark.sql.AnalysisException +import org.apache.spark.sql.execution.SparkPlan +import org.apache.spark.sql.execution.streaming.WatermarkPropagator.DEFAULT_WATERMARK_MS +import org.apache.spark.sql.internal.SQLConf +import org.apache.spark.util.Utils + +/** + * Interface for propagating watermark. The implementation is not required to be thread-safe, + * as all methods are expected to be called from the query execution thread. + * (The guarantee may change on further improvements on Structured Streaming - update + * implementations if we change the guarantee.) + */ +sealed trait WatermarkPropagator { + /** + * Request to propagate watermark among operators based on origin watermark value. The result + * should be input watermark per stateful operator, which Spark will request the value by calling + * getInputWatermarkXXX with operator ID. + * + * It is recommended for implementation to cache the result, as Spark can request the propagation + * multiple times with the same batch ID and origin watermark value. + */ + def propagate(batchId: Long, plan: SparkPlan, originWatermark: Long): Unit + + /** Provide the calculated input watermark for late events for given stateful operator. */ + def getInputWatermarkForLateEvents(batchId: Long, stateOpId: Long): Long + + /** Provide the calculated input watermark for eviction for given stateful operator. */ + def getInputWatermarkForEviction(batchId: Long, stateOpId: Long): Long + + /** + * Request to clean up cached result on propagation. Spark will call this method when the given + * batch ID will be likely to be not re-executed. + */ + def purge(batchId: Long): Unit +} + +/** + * Do nothing. This is dummy implementation to help creating a dummy IncrementalExecution instance. + */ +object NoOpWatermarkPropagator extends WatermarkPropagator { + def propagate(batchId: Long, plan: SparkPlan, originWatermark: Long): Unit = {} + def getInputWatermarkForLateEvents(batchId: Long, stateOpId: Long): Long = Long.MinValue + def getInputWatermarkForEviction(batchId: Long, stateOpId: Long): Long = Long.MinValue + def purge(batchId: Long): Unit = {} +} + +/** + * This implementation uses a single global watermark for late events and eviction. + * + * This implementation provides the behavior before Structured Streaming supports multiple stateful + * operators. (prior to SPARK-40925) This is only used for compatibility mode. + */ +class UseSingleWatermarkPropagator extends WatermarkPropagator { Review Comment: No, that's for compatibility purpose (only when compatibility flag is turned on). PropagateWatermarkSimulator is the default implementation. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
