According to the source code, the option batchsize
is used for executeBatch
method of PreparedStatement
, which is able to submit a batch of commands to the database for execution.
The key code:
val stmt = conn.prepareStatement(insertStmt)
while (iterator.hasNext) {
stmt.addBatch()
rowCount += 1
if (rowCount % batchSize == 0) {
stmt.executeBatch()
rowCount = 0
}
}
if (rowCount > 0) {
stmt.executeBatch()
}
Back to your question, it is true that there are
a batch of insert commands
But, the statement gets committed at the end
is wrong, because it is fine for only part of those inserts to execute successfully. No extra transaction requirements here. BTW, Spark will adopt the default isolation level if it is not specified.