You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/03/02 07:08:10 UTC

[GitHub] [spark] beliefer commented on a change in pull request #35696: [SPARK-38361][SQL] Factory method getConnection should take Partition as optional parameter.

beliefer commented on a change in pull request #35696:
URL: https://github.com/apache/spark/pull/35696#discussion_r817402419



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala
##########
@@ -60,9 +60,9 @@ object JdbcUtils extends Logging with SQLConfHelper {
    * @param options - JDBC options that contains url, table and other information.
    * @throws IllegalArgumentException if the driver could not open a JDBC connection.
    */
-  def createConnectionFactory(options: JDBCOptions): () => Connection = {
+  def createConnectionFactory(options: JDBCOptions): Option[Partition] => Connection = {

Review comment:
       We get the jdbc connection looks like:
   ```
   private def createConnectionFactoryByShard(options: JDBCOptions): Partition => Connection = {
       val shards = ShardOptions.create(options)
       val driverClass: String = options.driverClass
       (thePart: Partition) => {
         require(thePart.index < shards.shards.length)
         val url = shards.shards.apply(thePart.index)
         logInfo(s"Create connection for shard: $url")
         DriverRegistry.register(driverClass)
         val driver: Driver = DriverManager.getDrivers.asScala.collectFirst {
           case d: DriverWrapper if d.wrapped.getClass.getCanonicalName == driverClass => d
           case d if d.getClass.getCanonicalName == driverClass => d
         }.getOrElse {
           throw new IllegalStateException(
             s"Did not find registered driver with class $driverClass")
         }
         driver.connect(url, options.asConnectionProperties)
       }
     }
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org