@@ -237,7 +237,8 @@ trait MergeIntoMetricsBase
237
237
mergeCmdFn : MergeCmd ,
238
238
expectedOpMetrics : Map [String , Int ],
239
239
testConfig : MergeTestConfiguration ,
240
- overrideExpectedOpMetrics : Seq [((Boolean , Boolean ), (String , Int ))] = Seq .empty
240
+ overrideExpectedOpMetrics : Seq [((Boolean , Boolean ), (String , Int ))] = Seq .empty,
241
+ customMetricsChecker : Option [Map [String , String ] => Unit ] = None
241
242
): Unit = {
242
243
withSQLConf(
243
244
DeltaSQLConf .DELTA_HISTORY_METRICS_ENABLED .key -> " true" ,
@@ -307,6 +308,8 @@ trait MergeIntoMetricsBase
307
308
checkOperationTimeMetricsInvariant(mergeTimeMetrics, operationMetrics)
308
309
// Check CDF metrics invariants.
309
310
checkMergeOperationCdfMetricsInvariants(operationMetrics, testConfig.cdfEnabled)
311
+ // Perform custom checks on operationMetrics.
312
+ customMetricsChecker.map(f => f(operationMetrics))
310
313
}
311
314
}
312
315
}
@@ -1002,7 +1005,6 @@ trait MergeIntoMetricsBase
1002
1005
" numTargetRowsMatchedDeleted" -> 50 ,
1003
1006
" numTargetRowsRemoved" -> - 1 ,
1004
1007
" numTargetRowsCopied" -> 10 ,
1005
- " numTargetFilesAdded" -> 2 ,
1006
1008
" numTargetFilesRemoved" -> 3
1007
1009
)
1008
1010
runMergeCmdAndTestMetrics(
@@ -1011,13 +1013,20 @@ trait MergeIntoMetricsBase
1011
1013
mergeCmdFn = mergeCmdFn,
1012
1014
expectedOpMetrics = expectedOpMetrics,
1013
1015
testConfig = testConfig,
1014
- // When cdf=true in this test we hit the corner case where there are duplicate matches with a
1015
- // delete clause and we generate duplicate cdc data. This is further detailed in
1016
- // MergeIntoCommand at the definition of isDeleteWithDuplicateMatchesAndCdc. Our fix for this
1017
- // scenario includes deduplicating the output data which reshuffles the output data.
1018
- // Thus when the table is not partitioned, the data is rewritten into 1 new file rather than 2
1019
- overrideExpectedOpMetrics = Seq (((false , true ), (" numTargetFilesAdded" , 1 )))
1020
- )
1016
+ customMetricsChecker = Some (operationMetrics => {
1017
+ val metricValue = operationMetrics(" numTargetFilesAdded" )
1018
+ (testConfig.partitioned, testConfig.cdfEnabled) match {
1019
+ // When cdf=true in this test we hit the corner case where there are duplicate matches
1020
+ // with a delete clause and we generate duplicate cdc data. This is further detailed in
1021
+ // MergeIntoCommand at the definition of isDeleteWithDuplicateMatchesAndCdc. Our fix for
1022
+ // this scenario includes deduplicating the output data which reshuffles the output data.
1023
+ // Thus when the table is not partitioned, the data is rewritten into 1 new file rather
1024
+ // than 2.
1025
+ case (false , true ) => assert(metricValue == " 1" )
1026
+ // Depending on the Spark version, for non-partitioned tables we may add 1 or 2 files.
1027
+ case (false , false ) => assert(metricValue == " 1" || metricValue == " 2" )
1028
+ case _ => assert(metricValue == " 2" )
1029
+ }}))
1021
1030
}}
1022
1031
1023
1032
// ///////////////////////////
0 commit comments