Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/1792#discussion_r15840899
--- Diff: core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala ---
@@ -70,20 +70,30 @@ class JdbcRDD[T: ClassTag](
override def compute(thePart: Partition, context: TaskContext) = new
NextIterator[T] {
context.addOnCompleteCallback{ () => closeIfNeeded() }
val part = thePart.asInstanceOf[JdbcPartition]
- val conn = getConnection()
- val stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY)
+ var conn : Connection = _
+ var stmt : PreparedStatement = _
+ try {
--- End diff --
Actually as I look at this again, I think the try is not necessary.
Basically the first line in the constructor adds "closeIfNeeded" callback to
the complete callback list. Then if any exception is thrown, even during the
constructor, I think closeIfNeeded is called to close connections.
---
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]