Skip to content

Commit a63a1b3

Browse files
committed
Add a configuration for batch size.
1 parent 1a474e9 commit a63a1b3

File tree

1 file changed

+5
-3
lines changed
  • sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc

1 file changed

+5
-3
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ object JdbcUtils extends Logging {
8888
table: String,
8989
iterator: Iterator[Row],
9090
rddSchema: StructType,
91-
nullTypes: Array[Int]): Iterator[Byte] = {
91+
nullTypes: Array[Int],
92+
batchSize: Int): Iterator[Byte] = {
9293
val conn = getConnection()
9394
var committed = false
9495
try {
@@ -125,7 +126,7 @@ object JdbcUtils extends Logging {
125126
}
126127
stmt.addBatch()
127128
rowCount += 1
128-
if (rowCount % 10000 == 0) {
129+
if (rowCount % batchSize == 0) {
129130
stmt.executeBatch()
130131
rowCount = 0
131132
}
@@ -220,8 +221,9 @@ object JdbcUtils extends Logging {
220221
val rddSchema = df.schema
221222
val driver: String = DriverRegistry.getDriverClassName(url)
222223
val getConnection: () => Connection = JDBCRDD.getConnector(driver, url, properties)
224+
val batchSize = properties.getProperty("jdbc.batchsize", "1000").toInt
223225
df.foreachPartition { iterator =>
224-
savePartition(getConnection, table, iterator, rddSchema, nullTypes)
226+
savePartition(getConnection, table, iterator, rddSchema, nullTypes, batchSize)
225227
}
226228
}
227229

0 commit comments

Comments
 (0)