Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.

Commit ef94937

Browse files
committed
use string then convert to set
1 parent a22c30a commit ef94937

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/main/scala/com/microsoft/sqlserver/jdbc/spark/SQLServerBulkJdbcOptions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class SQLServerBulkJdbcOptions(val params: CaseInsensitiveMap[String])
7474

7575
// user input column names array to match dataframe
7676
val columnsToWrite =
77-
params.getOrElse("columnsToWrite", Array[String]()).toSet
77+
params.getOrElse("columnsToWrite", "").toString
7878

7979
// Not a feature
8080
// Only used for internally testing data idempotency

src/main/scala/com/microsoft/sqlserver/jdbc/spark/utils/BulkCopyUtils.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ object BulkCopyUtils extends Logging {
274274
* @param url: String,
275275
* @param isCaseSensitive: Boolean
276276
* @param strictSchemaCheck: Boolean
277-
* @param columnsToWrite: Set[String]
277+
* @param columnsToWrite: String
278278
*/
279279
private[spark] def matchSchemas(
280280
conn: Connection,
@@ -284,32 +284,34 @@ object BulkCopyUtils extends Logging {
284284
url: String,
285285
isCaseSensitive: Boolean,
286286
strictSchemaCheck: Boolean,
287-
columnsToWrite: Set[String]): Array[ColumnMetadata]= {
287+
columnsToWrite: String): Array[ColumnMetadata]= {
288288
val dfColCaseMap = (df.schema.fieldNames.map(item => item.toLowerCase)
289289
zip df.schema.fieldNames.toList).toMap
290290
val dfCols = df.schema
291291

292292
val tableCols = getSchema(rs, JdbcDialects.get(url))
293293
val autoCols = getAutoCols(conn, dbtable)
294294

295+
val columnsToWriteSet = columnsToWrite.split(",").toSet
296+
295297
val prefix = "Spark Dataframe and SQL Server table have differing"
296298

297299
// auto columns should not exist in df
298300
assertIfCheckEnabled(dfCols.length + autoCols.length == tableCols.length, strictSchemaCheck,
299301
s"${prefix} numbers of columns")
300302

301-
if (columnsToWrite.isEmpty()) {
303+
if (columnsToWriteSet.isEmpty()) {
302304
val result = new Array[ColumnMetadata](tableCols.length - autoCols.length)
303305
} else {
304-
val result = new Array[ColumnMetadata](columnsToWrite.size)
306+
val result = new Array[ColumnMetadata](columnsToWriteSet.size)
305307
}
306308

307309
var nonAutoColIndex = 0
308310

309311
for (i <- 0 to tableCols.length-1) {
310312
val tableColName = tableCols(i).name
311313
var dfFieldIndex = -1
312-
if (!columnsToWrite.isEmpty() && !columnsToWrite.contains(tableColName)) {
314+
if (!columnsToWriteSet.isEmpty() && !columnsToWriteSet.contains(tableColName)) {
313315
// if columnsToWrite provided, and column name not in it, skip column mapping and ColumnMetadata
314316
logDebug(s"skipping col index $i col name $tableColName, user not provided in columnsToWrite list")
315317
} else if (autoCols.contains(tableColName)) {

0 commit comments

Comments
 (0)