SanJSp commented on code in PR #55583:
URL: https://github.com/apache/spark/pull/55583#discussion_r3161101027


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/ResolveChangelogTableNetChangesSuite.scala:
##########
@@ -0,0 +1,402 @@
+/*
+ * 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.connector
+
+import java.util.Collections
+
+import org.scalatest.BeforeAndAfterEach
+
+import org.apache.spark.sql.{DataFrame, QueryTest, Row}
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.connector.catalog.{
+  ChangelogProperties, Column, Identifier, InMemoryChangelogCatalog}
+import org.apache.spark.sql.connector.catalog.Changelog.{
+  CHANGE_TYPE_DELETE, CHANGE_TYPE_INSERT, CHANGE_TYPE_UPDATE_POSTIMAGE,
+  CHANGE_TYPE_UPDATE_PREIMAGE}
+import org.apache.spark.sql.connector.expressions.Transform
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types.{LongType, StringType}
+import org.apache.spark.unsafe.types.UTF8String
+
+/**
+ * Shared test bodies for the `netChanges` deduplication mode handled by
+ * [[org.apache.spark.sql.catalyst.analysis.ResolveChangelogTable]].
+ *
+ * Concrete subclasses fix the [[computeUpdates]] flag and therefore run the
+ * entire suite twice (once with `computeUpdates = true`, once with
+ * `computeUpdates = false`). Test bodies use [[computedPreUpdateLabel]] /
+ * [[computedPostUpdateLabel]] in their expected outputs.
+ *
+ * Setup convention: every test runs against an in-memory connector configured
+ * with `containsIntermediateChanges = true` and
+ * `representsUpdateAsDeleteAndInsert = false`, which means
+ *   - netChanges is enabled (the only post-processing pass under test);
+ *   - update detection is disabled (so the test directly controls the
+ *     change_type labels reaching netChanges).
+ */
+trait ResolveChangelogTableNetChangesTestsBase
+    extends QueryTest
+    with SharedSparkSession
+    with BeforeAndAfterEach {
+
+  /**
+   * Value of the user-facing CDC option `computeUpdates` that this test run
+   * exercises. Concrete subclasses pin this to `true` or `false` so the same
+   * test bodies cover both modes via two suite classes.
+   */
+  protected def computeUpdates: Boolean
+
+  private val catalogName = "cdc_netchanges_catalog"
+  private val testTableName = "events"
+
+  override def beforeAll(): Unit = {
+    super.beforeAll()
+    spark.conf.set(
+      s"spark.sql.catalog.$catalogName",
+      classOf[InMemoryChangelogCatalog].getName)
+  }
+
+  override def beforeEach(): Unit = {
+    super.beforeEach()
+    val cat = catalog
+    if (cat.tableExists(ident)) cat.dropTable(ident)
+    cat.clearChangeRows(ident)
+    cat.createTable(
+      ident,
+      Array(
+        Column.create("id", LongType),
+        Column.create("name", StringType),
+        Column.create("row_commit_version", LongType, false)),
+      Array.empty[Transform],
+      Collections.emptyMap[String, String]())
+    cat.setChangelogProperties(ident, ChangelogProperties(
+      containsIntermediateChanges = true,
+      containsCarryoverRows = false,
+      representsUpdateAsDeleteAndInsert = false,

Review Comment:
   Done — see the new `WithUpdateDetectionSuite` (16 tests × 
`representsUpdateAsDeleteAndInsert` = true, `computeUpdates` = true).



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