@@ -21,7 +21,7 @@ import java.io.File
2121import scala .util .control .NonFatal
2222
2323import org .apache .spark .sql .delta .Relocated .StreamExecution
24- import org .apache .spark .sql .delta .test .DeltaSQLCommandTest
24+ import org .apache .spark .sql .delta .test .{ DeltaSQLCommandTest , DeltaSQLTestUtils }
2525import org .apache .hadoop .fs .Path
2626import org .scalatest .concurrent .Eventually
2727import org .scalatest .concurrent .PatienceConfiguration .Timeout
@@ -30,28 +30,31 @@ import org.apache.spark.sql.streaming.{StreamTest, Trigger}
3030import org .apache .spark .sql .streaming .util .StreamManualClock
3131
3232trait DeltaSourceDeletionVectorTests extends StreamTest
33- with DeletionVectorsTestUtils {
33+ with DeletionVectorsTestUtils
34+ with DeltaSourceConnectorTrait {
35+ self : DeltaSQLTestUtils =>
3436
3537 import testImplicits ._
3638
39+ /** Execute SQL statement. Override in V2 tests to use V1 connector for write operations. */
40+ protected def executeSql (sqlText : String ): Unit = sql(sqlText)
41+
3742 test(" allow to delete files before starting a streaming query" ) {
3843 withTempDir { inputDir =>
3944 val deltaLog = DeltaLog .forTable(spark, new Path (inputDir.toURI))
4045 (0 until 5 ).foreach { i =>
4146 val v = Seq (i.toString).toDF
4247 v.write.mode(" append" ).format(" delta" ).save(deltaLog.dataPath.toString)
4348 }
44- sql (s " DELETE FROM delta.` $inputDir` " )
49+ executeSql (s " DELETE FROM delta.` $inputDir` " )
4550 (5 until 10 ).foreach { i =>
4651 val v = Seq (i.toString).toDF
4752 v.write.mode(" append" ).format(" delta" ).save(deltaLog.dataPath.toString)
4853 }
4954 deltaLog.checkpoint()
5055 assert(deltaLog.readLastCheckpointFile().nonEmpty, " this test requires a checkpoint" )
5156
52- val df = spark.readStream
53- .format(" delta" )
54- .load(inputDir.getCanonicalPath)
57+ val df = loadStreamWithOptions(inputDir.getCanonicalPath, Map .empty)
5558
5659 testStream(df)(
5760 AssertOnQuery { q =>
@@ -69,16 +72,14 @@ trait DeltaSourceDeletionVectorTests extends StreamTest
6972 val v = Seq (i.toString).toDF
7073 v.write.mode(" append" ).format(" delta" ).save(deltaLog.dataPath.toString)
7174 }
72- sql (s " DELETE FROM delta.` $inputDir` " )
75+ executeSql (s " DELETE FROM delta.` $inputDir` " )
7376 (5 until 7 ).foreach { i =>
7477 val v = Seq (i.toString).toDF
7578 v.write.mode(" append" ).format(" delta" ).save(deltaLog.dataPath.toString)
7679 }
7780 assert(deltaLog.readLastCheckpointFile().isEmpty, " this test requires no checkpoint" )
7881
79- val df = spark.readStream
80- .format(" delta" )
81- .load(inputDir.getCanonicalPath)
82+ val df = loadStreamWithOptions(inputDir.getCanonicalPath, Map .empty)
8283
8384 testStream(df)(
8485 AssertOnQuery { q =>
@@ -115,7 +116,7 @@ trait DeltaSourceDeletionVectorTests extends StreamTest
115116 Seq (i, i + 1 ).toDF().coalesce(1 ).write.format(" delta" ).mode(" append" ).save(inputDir)
116117 }
117118
118- val df = spark.readStream.format( " delta " ).options( sourceOptions.toMap).load(inputDir )
119+ val df = loadStreamWithOptions(inputDir, sourceOptions.toMap)
119120 val expectDVs = commandShouldProduceDVs.getOrElse(
120121 sqlCommand.toUpperCase().startsWith(" DELETE" ))
121122
@@ -126,7 +127,7 @@ trait DeltaSourceDeletionVectorTests extends StreamTest
126127 },
127128 CheckAnswer ((0 until 10 ): _* ),
128129 AssertOnQuery { q =>
129- sql (sqlCommand)
130+ executeSql (sqlCommand)
130131 deletionVectorsPresentIfExpected(inputDir, expectDVs)
131132 })
132133
@@ -148,7 +149,7 @@ trait DeltaSourceDeletionVectorTests extends StreamTest
148149 }
149150 val log = DeltaLog .forTable(spark, inputDir)
150151 val commitVersionBeforeDML = log.update().version
151- val df = spark.readStream.format( " delta " ).options( sourceOptions.toMap).load(inputDir )
152+ val df = loadStreamWithOptions(inputDir, sourceOptions.toMap)
152153 def expectDVsInCommand (shouldProduceDVs : Option [Boolean ], command : String ): Boolean = {
153154 shouldProduceDVs.getOrElse(command.toUpperCase().startsWith(" DELETE" ))
154155 }
@@ -177,11 +178,11 @@ trait DeltaSourceDeletionVectorTests extends StreamTest
177178 true
178179 },
179180 AssertOnQuery { q =>
180- sql (sqlCommand1)
181+ executeSql (sqlCommand1)
181182 deletionVectorsPresentIfExpected(inputDir, expectDVsInCommand1)
182183 },
183184 AssertOnQuery { q =>
184- sql (sqlCommand2)
185+ executeSql (sqlCommand2)
185186 deletionVectorsPresentIfExpected(inputDir, expectDVsInCommand2)
186187 },
187188 AssertOnQuery { q =>
@@ -416,21 +417,19 @@ trait DeltaSourceDeletionVectorTests extends StreamTest
416417 (0 until 10 ).toDF(" value" ).coalesce(1 ).write.format(" delta" ).save(path)
417418
418419 // V1: Delete row 0
419- sql (s " DELETE FROM delta.` $path` WHERE value = 0 " )
420+ executeSql (s " DELETE FROM delta.` $path` WHERE value = 0 " )
420421
421422 // V2: Delete row 1
422- sql (s " DELETE FROM delta.` $path` WHERE value = 1 " )
423+ executeSql (s " DELETE FROM delta.` $path` WHERE value = 1 " )
423424
424425 // V3: Delete row 2
425- sql (s " DELETE FROM delta.` $path` WHERE value = 2 " )
426+ executeSql (s " DELETE FROM delta.` $path` WHERE value = 2 " )
426427
427428 // Verify DVs are present
428429 assert(getFilesWithDeletionVectors(deltaLog).nonEmpty,
429430 " This test requires deletion vectors to be present" )
430431
431- val df = spark.readStream
432- .format(" delta" )
433- .load(path)
432+ val df = loadStreamWithOptions(path, Map .empty)
434433
435434 testStream(df)(
436435 // Process the initial snapshot
@@ -457,10 +456,7 @@ trait DeltaSourceDeletionVectorTests extends StreamTest
457456 // V0: 10 rows in a single file
458457 (0 until 10 ).toDF(" value" ).coalesce(1 ).write.format(" delta" ).save(path)
459458
460- val df = spark.readStream
461- .format(" delta" )
462- .options(sourceOptions.toMap)
463- .load(path)
459+ val df = loadStreamWithOptions(path, sourceOptions.toMap)
464460
465461 testStream(df)(
466462 AssertOnQuery { q =>
@@ -470,12 +466,12 @@ trait DeltaSourceDeletionVectorTests extends StreamTest
470466 CheckAnswer ((0 until 10 ): _* ),
471467 AssertOnQuery { q =>
472468 // V1: Delete row 0 - creates first DV (version 1)
473- sql (s " DELETE FROM delta.` $path` WHERE value = 0 " )
469+ executeSql (s " DELETE FROM delta.` $path` WHERE value = 0 " )
474470 true
475471 },
476472 AssertOnQuery { q =>
477473 // V2: Delete row 1 - updates DV (version 2). DV is cumulative: {0, 1}
478- sql (s " DELETE FROM delta.` $path` WHERE value = 1 " )
474+ executeSql (s " DELETE FROM delta.` $path` WHERE value = 1 " )
479475 true
480476 },
481477 AssertOnQuery { q =>
0 commit comments