|
17 | 17 | package org.apache.spark.sql.delta
|
18 | 18 |
|
19 | 19 | import java.io.File
|
| 20 | +import java.net.URI |
| 21 | +import java.util.UUID |
20 | 22 |
|
| 23 | +import org.apache.spark.sql.delta.catalog.DeltaCatalog |
| 24 | +import org.apache.spark.sql.delta.commands.{CreateDeltaTableCommand, TableCreationModes} |
21 | 25 | import org.apache.spark.sql.delta.test.DeltaSQLCommandTest
|
22 | 26 | import org.scalatest.exceptions.TestFailedException
|
23 | 27 |
|
24 | 28 | import org.apache.spark.sql.QueryTest
|
| 29 | +import org.apache.spark.sql.SaveMode |
25 | 30 | import org.apache.spark.sql.catalyst.TableIdentifier
|
| 31 | +import org.apache.spark.sql.catalyst.catalog.{CatalogStorageFormat, CatalogTable, CatalogTableType} |
26 | 32 | import org.apache.spark.sql.functions.lit
|
27 | 33 | import org.apache.spark.sql.test.SharedSparkSession
|
| 34 | +import org.apache.spark.sql.types.StructType |
28 | 35 |
|
29 | 36 | class DeltaCreateTableLikeSuite extends QueryTest
|
30 | 37 | with SharedSparkSession
|
@@ -277,6 +284,42 @@ class DeltaCreateTableLikeSuite extends QueryTest
|
277 | 284 | }
|
278 | 285 | }
|
279 | 286 |
|
| 287 | + test("concurrent create Managed Catalog table commands should not fail") { |
| 288 | + withTempDir { dir => |
| 289 | + withTable("t") { |
| 290 | + def getCatalogTable: CatalogTable = { |
| 291 | + val storage = CatalogStorageFormat.empty.copy( |
| 292 | + locationUri = Some(new URI(s"$dir/${UUID.randomUUID().toString}"))) |
| 293 | + val catalogTableTarget = CatalogTable( |
| 294 | + identifier = TableIdentifier("t"), |
| 295 | + tableType = CatalogTableType.MANAGED, |
| 296 | + storage = storage, |
| 297 | + provider = Some("delta"), |
| 298 | + schema = new StructType().add("id", "long")) |
| 299 | + new DeltaCatalog() |
| 300 | + .verifyTableAndSolidify( |
| 301 | + tableDesc = catalogTableTarget, |
| 302 | + query = None, |
| 303 | + maybeClusterBySpec = None) |
| 304 | + } |
| 305 | + CreateDeltaTableCommand( |
| 306 | + getCatalogTable, |
| 307 | + existingTableOpt = None, |
| 308 | + mode = SaveMode.Ignore, |
| 309 | + query = None, |
| 310 | + operation = TableCreationModes.Create).run(spark) |
| 311 | + assert(spark.sessionState.catalog.tableExists(TableIdentifier("t"))) |
| 312 | + CreateDeltaTableCommand( |
| 313 | + getCatalogTable, |
| 314 | + existingTableOpt = None, // Set to None to simulate concurrent table creation commands. |
| 315 | + mode = SaveMode.Ignore, |
| 316 | + query = None, |
| 317 | + operation = TableCreationModes.Create).run(spark) |
| 318 | + assert(spark.sessionState.catalog.tableExists(TableIdentifier("t"))) |
| 319 | + } |
| 320 | + } |
| 321 | + } |
| 322 | + |
280 | 323 | test("CREATE TABLE LIKE where sourceTable is a json table") {
|
281 | 324 | val srcTbl = "srcTbl"
|
282 | 325 | val targetTbl = "targetTbl"
|
|
0 commit comments