anishshri-db commented on code in PR #45376:
URL: https://github.com/apache/spark/pull/45376#discussion_r1513594533


##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithStateWatermarkSuite.scala:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.streaming
+
+import java.sql.Timestamp
+import java.time.{Instant, LocalDateTime, ZoneId}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.ExtendedAnalysisException
+import org.apache.spark.sql.execution.streaming.{MemoryStream, StreamExecution}
+import org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider
+import org.apache.spark.sql.functions.window
+import org.apache.spark.sql.internal.SQLConf
+
+class ColumnRenamedStatefulProcessor
+  extends StatefulProcessor[String, InputEventRow, RenamedInputEventRow]
+  with Logging {
+
+  override def init(outputMode: OutputMode): Unit = { }
+
+  override def handleInputRows(key: String, inputRows: Iterator[InputEventRow],
+      timerValues: TimerValues): Iterator[RenamedInputEventRow] = {
+
+    new Iterator[RenamedInputEventRow] {
+      override def hasNext: Boolean = inputRows.hasNext
+
+      override def next(): RenamedInputEventRow = {
+        Option(inputRows.next()).map { r =>
+          RenamedInputEventRow(
+            r.key, r.eventTime, r.event
+          )
+        }.orNull
+      }
+    }
+
+  }
+
+  override def close(): Unit = { }
+}
+
+case class InputEventRow(
+    key: String,
+    eventTime: Timestamp,
+    event: String)
+
+case class RenamedInputEventRow(
+    key: String,
+    renamedEventTime: Timestamp,
+    event: String)
+
+case class OutputEventRow(
+    key: String,
+    count: Int)
+
+case class Window(
+    start: Timestamp,
+    end: Timestamp)
+
+case class AggEventRow(
+    window: Window,
+    count: Long)
+
+class TransformWithStateWatermarkSuite extends StreamTest
+  with Logging {
+  import testImplicits._
+
+  test("watermark is propagated correctly for next stateful operator" +
+    " after transformWithState") {
+    withSQLConf(SQLConf.STATE_STORE_PROVIDER_CLASS.key ->
+      classOf[RocksDBStateStoreProvider].getName) {
+      withSQLConf(SQLConf.SHUFFLE_PARTITIONS.key -> "1") {
+        val inputData = MemoryStream[InputEventRow]
+
+        val result = inputData.toDS()
+          .withWatermark("eventTime", "1 minute")
+          .groupByKey(x => x.key)
+          .transformWithState[RenamedInputEventRow](
+            new ColumnRenamedStatefulProcessor(),
+            TimeoutMode.NoTimeouts(),
+            "renamedEventTime",
+            OutputMode.Append())
+          .groupBy(window($"renamedEventTime", "1 minute"))

Review Comment:
   Can we add few more tests ? maybe one with `transformWithState` followed by 
`dropDuplicates`, `join` and `transformWithState` too ?



##########
sql/core/src/test/scala/org/apache/spark/sql/streaming/TransformWithStateWatermarkSuite.scala:
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.streaming
+
+import java.sql.Timestamp
+import java.time.{Instant, LocalDateTime, ZoneId}
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.ExtendedAnalysisException
+import org.apache.spark.sql.execution.streaming.{MemoryStream, StreamExecution}
+import org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider
+import org.apache.spark.sql.functions.window
+import org.apache.spark.sql.internal.SQLConf
+
+class ColumnRenamedStatefulProcessor
+  extends StatefulProcessor[String, InputEventRow, RenamedInputEventRow]
+  with Logging {
+
+  override def init(outputMode: OutputMode): Unit = { }
+
+  override def handleInputRows(key: String, inputRows: Iterator[InputEventRow],
+      timerValues: TimerValues): Iterator[RenamedInputEventRow] = {
+
+    new Iterator[RenamedInputEventRow] {
+      override def hasNext: Boolean = inputRows.hasNext
+
+      override def next(): RenamedInputEventRow = {
+        Option(inputRows.next()).map { r =>
+          RenamedInputEventRow(
+            r.key, r.eventTime, r.event
+          )
+        }.orNull
+      }
+    }
+
+  }
+
+  override def close(): Unit = { }
+}
+
+case class InputEventRow(
+    key: String,
+    eventTime: Timestamp,
+    event: String)
+
+case class RenamedInputEventRow(
+    key: String,
+    renamedEventTime: Timestamp,
+    event: String)
+
+case class OutputEventRow(
+    key: String,
+    count: Int)
+
+case class Window(
+    start: Timestamp,
+    end: Timestamp)
+
+case class AggEventRow(
+    window: Window,
+    count: Long)
+
+class TransformWithStateWatermarkSuite extends StreamTest
+  with Logging {
+  import testImplicits._
+
+  test("watermark is propagated correctly for next stateful operator" +
+    " after transformWithState") {
+    withSQLConf(SQLConf.STATE_STORE_PROVIDER_CLASS.key ->
+      classOf[RocksDBStateStoreProvider].getName) {
+      withSQLConf(SQLConf.SHUFFLE_PARTITIONS.key -> "1") {
+        val inputData = MemoryStream[InputEventRow]
+
+        val result = inputData.toDS()
+          .withWatermark("eventTime", "1 minute")
+          .groupByKey(x => x.key)
+          .transformWithState[RenamedInputEventRow](
+            new ColumnRenamedStatefulProcessor(),
+            TimeoutMode.NoTimeouts(),
+            "renamedEventTime",
+            OutputMode.Append())
+          .groupBy(window($"renamedEventTime", "1 minute"))

Review Comment:
   Can we add few more tests ? maybe one each with `transformWithState` 
followed by `dropDuplicates`, `join` and `transformWithState` too ?



-- 
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]

Reply via email to