@@ -199,6 +199,87 @@ trait DeltaSharingDataSourceDeltaSuiteBase
199
199
}
200
200
}
201
201
202
+ test(" DeltaSharingDataSource able to read data with changes" ) {
203
+ withTempDir { tempDir =>
204
+ val deltaTableName = " delta_table_change"
205
+
206
+ def test (tablePath : String , expectedCount : Int , expectedSchema : StructType ): Unit = {
207
+ assert(
208
+ expectedSchema == spark.read
209
+ .format(" deltaSharing" )
210
+ .option(" responseFormat" , " delta" )
211
+ .load(tablePath)
212
+ .schema
213
+ )
214
+
215
+ val deltaDf = spark.read.format(" delta" ).table(deltaTableName)
216
+ val sharingDf =
217
+ spark.read.format(" deltaSharing" ).option(" responseFormat" , " delta" ).load(tablePath)
218
+ checkAnswer(deltaDf, sharingDf)
219
+ assert(sharingDf.count() == expectedCount)
220
+ }
221
+
222
+ withTable(deltaTableName) {
223
+ val sharedTableName = " shared_table_change"
224
+ createTable(deltaTableName)
225
+
226
+ // test 1: insert 2 rows
227
+ sql(
228
+ s " INSERT INTO $deltaTableName" +
229
+ """ VALUES (1, "one", "2023-01-01", "2023-01-01 00:00:00"),
230
+ |(2, "two", "2023-02-02", "2023-02-02 00:00:00")""" .stripMargin
231
+ )
232
+ prepareMockedClientAndFileSystemResult(deltaTableName, sharedTableName)
233
+ prepareMockedClientGetTableVersion(deltaTableName, sharedTableName)
234
+ val expectedSchema : StructType = new StructType ()
235
+ .add(" c1" , IntegerType )
236
+ .add(" c2" , StringType )
237
+ .add(" c3" , DateType )
238
+ .add(" c4" , TimestampType )
239
+ withSQLConf(getDeltaSharingClassesSQLConf.toSeq: _* ) {
240
+ val profileFile = prepareProfileFile(tempDir)
241
+ val tableName = s " share1.default. $sharedTableName"
242
+ test(s " ${profileFile.getCanonicalPath}# $tableName" , 2 , expectedSchema)
243
+ }
244
+
245
+ // test 2: insert 2 more rows, and rename a column
246
+ spark.sql(
247
+ s """ ALTER TABLE $deltaTableName SET TBLPROPERTIES('delta.minReaderVersion' = '2',
248
+ |'delta.minWriterVersion' = '5',
249
+ |'delta.columnMapping.mode' = 'name', 'delta.enableDeletionVectors' = true) """ .stripMargin
250
+ )
251
+ sql(
252
+ s " INSERT INTO $deltaTableName" +
253
+ """ VALUES (3, "three", "2023-03-03", "2023-03-03 00:00:00"),
254
+ |(4, "four", "2023-04-04", "2023-04-04 00:00:00")""" .stripMargin
255
+ )
256
+ sql(s """ ALTER TABLE $deltaTableName RENAME COLUMN c3 TO c3rename """ )
257
+ prepareMockedClientAndFileSystemResult(deltaTableName, sharedTableName)
258
+ prepareMockedClientGetTableVersion(deltaTableName, sharedTableName)
259
+ val expectedNewSchema : StructType = new StructType ()
260
+ .add(" c1" , IntegerType )
261
+ .add(" c2" , StringType )
262
+ .add(" c3rename" , DateType )
263
+ .add(" c4" , TimestampType )
264
+ withSQLConf(getDeltaSharingClassesSQLConf.toSeq: _* ) {
265
+ val profileFile = prepareProfileFile(tempDir)
266
+ val tableName = s " share1.default. $sharedTableName"
267
+ test(s " ${profileFile.getCanonicalPath}# $tableName" , 4 , expectedNewSchema)
268
+ }
269
+
270
+ // test 3: delete 1 row
271
+ sql(s " DELETE FROM $deltaTableName WHERE c1 = 2 " )
272
+ prepareMockedClientAndFileSystemResult(deltaTableName, sharedTableName)
273
+ prepareMockedClientGetTableVersion(deltaTableName, sharedTableName)
274
+ withSQLConf(getDeltaSharingClassesSQLConf.toSeq: _* ) {
275
+ val profileFile = prepareProfileFile(tempDir)
276
+ val tableName = s " share1.default. $sharedTableName"
277
+ test(s " ${profileFile.getCanonicalPath}# $tableName" , 3 , expectedNewSchema)
278
+ }
279
+ }
280
+ }
281
+ }
282
+
202
283
test(" DeltaSharingDataSource able to auto resolve responseFormat" ) {
203
284
withTempDir { tempDir =>
204
285
val deltaTableName = " delta_table_auto"
0 commit comments