jose-torres commented on code in PR #57584:
URL: https://github.com/apache/spark/pull/57584#discussion_r3663325069
##########
sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/graph/AutoCdcOutOfOrderConvergenceSuite.scala:
##########
@@ -197,11 +219,18 @@ class AutoCdcScd1OutOfOrderConvergenceSuite
runPipeline(outOfOrderCtx)
}
+ // Only the user-visible target must converge. The auxiliary tables
legitimately differ by
Review Comment:
This is fine under the assumption, which I think is correct but want to
confirm, that any auxiliary row generated at version N is guaranteed to stop
affecting results if the ingestion durably advances to some version M not too
much higher than N. (It would be a problem, to pick an exaggerated example, if
some category of auxiliary row caused different results starting at N + 1000;
then just checking consistency betwen the targets would not be enough to
confirm that the behavior is meaningfully the same.)
##########
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:
I agree with this analysis. I trust the principle that the results shouldn't
be ingestion order dependent more than I trust my ability to read through a big
pile of specific rows and intuit the correct result.
##########
sql/pipelines/src/test/scala/org/apache/spark/sql/pipelines/graph/AutoCdcOutOfOrderConvergenceSuite.scala:
##########
@@ -140,20 +146,33 @@ class AutoCdcScd1OutOfOrderConvergenceSuite
deleteCondition = Some(functions.col(isDeleteColumn) === true),
columnSelection = Some(ColumnSelection.ExcludeColumns(
Seq(UnqualifiedColumnName(isDeleteColumn))
- ))
+ )),
+ scdType = scdType
))
}
}
- private def createTargetTable(targetTable: String): Unit = {
+ /**
+ * DDL fragment for the SCD-type-specific reserved columns a target table
carries after the
+ * user-selected data columns: just the CDC metadata column for SCD1, plus
the __START_AT /
+ * __END_AT interval bounds for SCD2. The sequencing type is BIGINT here.
+ */
+ private def reservedColumnsDdl(scdType: ScdType): String = scdType match {
Review Comment:
I ultimately decided I don't care that SCD1 and SCD2 disagree on the
encapsulation boundary for the DDL, but I'm leaving this comment as a record of
the train of thought in case it jumps out at anyone.
--
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]