Github user srowen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14054#discussion_r71213696
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
 ---
    @@ -158,25 +159,41 @@ object JdbcUtils extends Logging {
           rddSchema: StructType,
           nullTypes: Array[Int],
           batchSize: Int,
    -      dialect: JdbcDialect): Iterator[Byte] = {
    +      dialect: JdbcDialect,
    +      isolationLevel: Int): Iterator[Byte] = {
         require(batchSize >= 1,
           s"Invalid value `${batchSize.toString}` for parameter " +
           s"`${JdbcUtils.JDBC_BATCH_INSERT_SIZE}`. The minimum value is 1.")
     
         val conn = getConnection()
         var committed = false
    -    val supportsTransactions = try {
    -      conn.getMetaData().supportsDataManipulationTransactionsOnly() ||
    -      
conn.getMetaData().supportsDataDefinitionAndDataManipulationTransactions()
    -    } catch {
    -      case NonFatal(e) =>
    -        logWarning("Exception while detecting transaction support", e)
    -        true
    +
    +    var finalIsolationLevel = Connection.TRANSACTION_NONE
    +    if (isolationLevel != Connection.TRANSACTION_NONE) {
    +      try {
    +        val metadata = conn.getMetaData
    +        if (metadata.supportsTransactions()) {
    +          if (metadata.supportsTransactionIsolationLevel(isolationLevel))  
{
    +            finalIsolationLevel = isolationLevel
    +          } else {
    +            val defaultIsolation = metadata.getDefaultTransactionIsolation
    +            logWarning(s"Requested isolation level $isolationLevel is not 
supported; " +
    +                s"falling back to isolation level $defaultIsolation")
    +            finalIsolationLevel = defaultIsolation
    +          }
    +        } else {
    +          logWarning(s"Requested isolation level $isolationLevel, but 
transactions are unsupported")
    +        }
    +      } catch {
    +        case NonFatal(e) => logWarning("Exception while detecting 
transaction support", e)
    +      }
         }
    +    val supportsTransactions = finalIsolationLevel != 
Connection.TRANSACTION_NONE
    --- End diff --
    
    Yeah, that was sort of on purpose, in case an exception happened in 
`supportsTransactions`. But if that succeeds but for some reason 
`supportsTransactionIsolationLevel` fails, something's odd, but perhaps it's 
better to make sure it uses the default isolation in that case?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to