Skip to content

Commit

Permalink
remove brackets for staging table name in NO_DUPLICATES mode (#145)
Browse files Browse the repository at this point in the history
* Support table names with square brackets in staging table name
* Add scala test for table name within square brackets
  • Loading branch information
luxu1-ms authored Nov 8, 2021
1 parent e328e20 commit b26d953
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ ClientBin/
*.publishsettings
orleans.codegen.cs

# IntelliJ build files
spark-mssql-connector.iml

# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ object ReliableSingleInstanceStrategy extends DataIOStrategy with Logging {
appId: String,
dbtable: String,
index:Int) : String = {
// remove square brackets in db / schema / table name
val dbtableNew = dbtable.replaceAll("[\\[\\]]", "")
// Global table names in SQLServer are prefixed with ##
s"[##${appId}_${dbtable}_${index}]"
s"[##${appId}_${dbtableNew}_${index}]"
}

/**
Expand Down
20 changes: 18 additions & 2 deletions test/scala_test/src/main/scala/MasterInstanceTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ class MasterInstanceTest(testUtils:Connector_TestUtils) {
/*
* OverWrite/Append and Read (OWAR) to SQL tables using 2 part names *
*/
def test_gci__twoPartName_owar() {
val table = s"test_gci_threePartName_owar"
def test_gci_twoPartName_owar() {
val table = s"test_gci_twoPartName_owar"
val twoPartName = testUtils.createTwoPartName(table)
log.info(s"Tablename is $twoPartName \n")
val df = testUtils.create_toy_df()
Expand All @@ -437,6 +437,22 @@ class MasterInstanceTest(testUtils:Connector_TestUtils) {
testUtils.drop_test_table(twoPartName)
}

/*
* OverWrite/Append and Read (OWAR) to SQL tables using 1 part name within square brackets *
*/
def test_gci_tbNameInBracket_owar() {
val table_name = s"[test_gci_tbNameInBracket_owar]"
log.info(s"Table name is $table_name \n")
val df = testUtils.create_toy_df()
log.info("Operation Overwrite, append and read\n")
testUtils.df_write(df, SaveMode.Overwrite, table_name)
testUtils.df_write(df, SaveMode.Append, table_name)
var result = testUtils.df_read(table_name)
assert(result.count() == 2 * df.count())
log.info("test_gci_tbNameInBracket_owar : Exit")
testUtils.drop_test_table(table_name)
}

/*
* The test checks that all supported datatype can be used to create tables
* Possible SQL Server data type are described at the link below
Expand Down

0 comments on commit b26d953

Please sign in to comment.