Skip to content

Commit b26d953

Browse files
authored
remove brackets for staging table name in NO_DUPLICATES mode (microsoft#145)
* Support table names with square brackets in staging table name * Add scala test for table name within square brackets
1 parent e328e20 commit b26d953

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ ClientBin/
230230
*.publishsettings
231231
orleans.codegen.cs
232232

233+
# IntelliJ build files
234+
spark-mssql-connector.iml
235+
233236
# Including strong name files can present a security risk
234237
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
235238
#*.snk

src/main/scala/com/microsoft/sqlserver/jdbc/spark/connectors/ReliableSingleInstanceStrategy.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,10 @@ object ReliableSingleInstanceStrategy extends DataIOStrategy with Logging {
181181
appId: String,
182182
dbtable: String,
183183
index:Int) : String = {
184+
// remove square brackets in db / schema / table name
185+
val dbtableNew = dbtable.replaceAll("[\\[\\]]", "")
184186
// Global table names in SQLServer are prefixed with ##
185-
s"[##${appId}_${dbtable}_${index}]"
187+
s"[##${appId}_${dbtableNew}_${index}]"
186188
}
187189

188190
/**

test/scala_test/src/main/scala/MasterInstanceTest.scala

+18-2
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ class MasterInstanceTest(testUtils:Connector_TestUtils) {
424424
/*
425425
* OverWrite/Append and Read (OWAR) to SQL tables using 2 part names *
426426
*/
427-
def test_gci__twoPartName_owar() {
428-
val table = s"test_gci_threePartName_owar"
427+
def test_gci_twoPartName_owar() {
428+
val table = s"test_gci_twoPartName_owar"
429429
val twoPartName = testUtils.createTwoPartName(table)
430430
log.info(s"Tablename is $twoPartName \n")
431431
val df = testUtils.create_toy_df()
@@ -437,6 +437,22 @@ class MasterInstanceTest(testUtils:Connector_TestUtils) {
437437
testUtils.drop_test_table(twoPartName)
438438
}
439439

440+
/*
441+
* OverWrite/Append and Read (OWAR) to SQL tables using 1 part name within square brackets *
442+
*/
443+
def test_gci_tbNameInBracket_owar() {
444+
val table_name = s"[test_gci_tbNameInBracket_owar]"
445+
log.info(s"Table name is $table_name \n")
446+
val df = testUtils.create_toy_df()
447+
log.info("Operation Overwrite, append and read\n")
448+
testUtils.df_write(df, SaveMode.Overwrite, table_name)
449+
testUtils.df_write(df, SaveMode.Append, table_name)
450+
var result = testUtils.df_read(table_name)
451+
assert(result.count() == 2 * df.count())
452+
log.info("test_gci_tbNameInBracket_owar : Exit")
453+
testUtils.drop_test_table(table_name)
454+
}
455+
440456
/*
441457
* The test checks that all supported datatype can be used to create tables
442458
* Possible SQL Server data type are described at the link below

0 commit comments

Comments
 (0)