@@ -414,6 +414,32 @@ class Scd1BatchProcessorSuite extends QueryTest with SharedSparkSession {
414414 )
415415 }
416416
417+ test(" extendMicrobatchRowsWithCdcMetadata treats null deleteCondition results as upserts" ) {
418+ val schema = new StructType ()
419+ .add(" id" , IntegerType )
420+ .add(" seq" , LongType )
421+ .add(" is_delete" , BooleanType )
422+
423+ val batch = microbatchOf(schema)(
424+ Row (1 , 10L , null )
425+ )
426+
427+ val processor = Scd1BatchProcessor (
428+ changeArgs = ChangeArgs (
429+ keys = Seq (UnqualifiedColumnName (" id" )),
430+ sequencing = F .col(" seq" ),
431+ storedAsScdType = ScdType .Type1 ,
432+ deleteCondition = Some (F .col(" is_delete" ))
433+ ),
434+ resolvedSequencingType = LongType
435+ )
436+
437+ checkAnswer(
438+ df = processor.extendMicrobatchRowsWithCdcMetadata(batch),
439+ expectedAnswer = Row (1 , 10L , null , Row (null , 10L ))
440+ )
441+ }
442+
417443 test(" extendMicrobatchRowsWithCdcMetadata treats every row as an upsert " +
418444 " when deleteCondition is None" ) {
419445 val schema = new StructType ()
@@ -578,4 +604,42 @@ class Scd1BatchProcessorSuite extends QueryTest with SharedSparkSession {
578604 )
579605 }
580606 }
607+
608+ test(" extendMicrobatchRowsWithCdcMetadata rejects reserved CDC metadata column " +
609+ " case-insensitively" ) {
610+ withSQLConf(SQLConf .CASE_SENSITIVE .key -> " false" ) {
611+ val conflictingColumnName = Scd1BatchProcessor .cdcMetadataColName.toUpperCase
612+ val schema = new StructType ()
613+ .add(" id" , IntegerType )
614+ .add(" seq" , LongType )
615+ .add(conflictingColumnName, StringType )
616+
617+ val batch = microbatchOf(schema)(
618+ Row (1 , 10L , " user-supplied" )
619+ )
620+
621+ val processor = Scd1BatchProcessor (
622+ changeArgs = ChangeArgs (
623+ keys = Seq (UnqualifiedColumnName (" id" )),
624+ sequencing = F .col(" seq" ),
625+ storedAsScdType = ScdType .Type1
626+ ),
627+ resolvedSequencingType = LongType
628+ )
629+
630+ checkError(
631+ exception = intercept[AnalysisException ] {
632+ processor.extendMicrobatchRowsWithCdcMetadata(batch)
633+ },
634+ condition = " AUTOCDC_RESERVED_COLUMN_NAME_CONFLICT" ,
635+ sqlState = " 42710" ,
636+ parameters = Map (
637+ " caseSensitivity" -> CaseSensitivityLabels .CaseInsensitive ,
638+ " columnName" -> conflictingColumnName,
639+ " schemaName" -> " microbatch" ,
640+ " reservedColumnName" -> Scd1BatchProcessor .cdcMetadataColName
641+ )
642+ )
643+ }
644+ }
581645}
0 commit comments