@@ -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