anew commented on code in PR #57584: URL: https://github.com/apache/spark/pull/57584#discussion_r3662068538
########## sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/graph/AutoCdcScd2SinglePipelineSuite.scala: ########## @@ -0,0 +1,191 @@ +/* + * 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.pipelines.graph + +import org.apache.spark.sql.Row +import org.apache.spark.sql.execution.streaming.runtime.MemoryStream +import org.apache.spark.sql.functions +import org.apache.spark.sql.pipelines.autocdc.{ + AutoCdcReservedNames, + ColumnSelection, + ScdType, + UnqualifiedColumnName +} +import org.apache.spark.sql.pipelines.utils.{ExecutionTest, TestGraphRegistrationContext} +import org.apache.spark.sql.test.SharedSparkSession + +/** + * End-to-end smoke tests for AutoCDC SCD Type 2 flows running within a single pipeline: one + * [[DataflowGraph]] / [[TestPipelineUpdateContext]] executes an SCD2 AutoCDC flow through the + * [[Scd2MergeStreamingWrite]] streaming write, and both the target table and the auxiliary + * table contents are asserted at the end. + * + * This exercises the full wiring landed for SCD2: the flow planner routing an SCD2 + * [[AutoCdcMergeFlow]] to [[Scd2MergeStreamingWrite]], the auxiliary-table materialization, and + * the [[org.apache.spark.sql.pipelines.autocdc.Scd2ForeachBatchHandler]] reconciliation. + */ +class AutoCdcScd2SinglePipelineSuite + extends ExecutionTest + with SharedSparkSession + with AutoCdcGraphExecutionTestMixin { + + /** The SCD2 target's `_cdc_metadata` struct value for a given recordStartAt. */ + private def scd2Meta(recordStartAt: Long): Row = Row(recordStartAt) + + /** + * DDL for an SCD2 target table with user columns `(id, name, version)` plus the framework + * columns `__START_AT` / `__END_AT` (sequencing type BIGINT) and the SCD2 `_cdc_metadata` + * struct. `version` is the sequencing column and, unless excluded via a column selection, is + * retained as an ordinary user column in the target. + */ + private def createScd2Target(table: String): Unit = { + val meta = AutoCdcReservedNames.cdcMetadataColName + spark.sql( + s"CREATE TABLE $table (" + + "id INT NOT NULL, name STRING, version BIGINT NOT NULL, " + + "__START_AT BIGINT, __END_AT BIGINT, " + + s"$meta STRUCT<__RECORD_START_AT:BIGINT> NOT NULL)" + ) + } + + test("SCD2: an upsert lands an open current record in an empty target table") { Review Comment: note: the test coverage here s not exhaustive, but it would be hard to test all possible cases in an end-to-end suite. This suite merely asserts that it works end-to-end -- 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]
