Skip to content

Commit 56294cb

Browse files
Switched to JDBCOptions
1 parent 7060166 commit 56294cb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.apache.spark.internal.Logging
2727
import org.apache.spark.internal.LogKeys.SQL_TEXT
2828
import org.apache.spark.rdd.RDD
2929
import org.apache.spark.sql.catalyst.InternalRow
30-
import org.apache.spark.sql.catalyst.util.CaseInsensitiveMap
3130
import org.apache.spark.sql.connector.expressions.filter.Predicate
3231
import org.apache.spark.sql.execution.datasources.{DataSourceMetricsMixin, ExternalEngineDatasourceRDD}
3332
import org.apache.spark.sql.execution.datasources.v2.TableSampleInfo
@@ -306,8 +305,7 @@ class JDBCRDD(
306305
val inputMetrics = context.taskMetrics().inputMetrics
307306
val part = thePart.asInstanceOf[JDBCPartition]
308307
conn = getConnection(part.idx)
309-
import scala.jdk.CollectionConverters._
310-
dialect.beforeFetch(conn, CaseInsensitiveMap(options.asProperties.asScala.toMap))
308+
dialect.beforeFetch(conn, options)
311309

312310
// This executes a generic SQL statement (or PL/SQL block) before reading
313311
// the table/query via JDBC. Use this feature to initialize the database

sql/core/src/main/scala/org/apache/spark/sql/jdbc/JdbcDialects.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,20 @@ abstract class JdbcDialect extends Serializable with Logging {
342342
* @param connection The connection object
343343
* @param properties The connection properties. This is passed through from the relation.
344344
*/
345+
@deprecated("Use beforeFetch(Connection, JDBCOptions) instead", "4.0.0")
345346
def beforeFetch(connection: Connection, properties: Map[String, String]): Unit = {
346347
}
347348

349+
/**
350+
* Override connection specific properties to run before a select is made. This is in place to
351+
* allow dialects that need special treatment to optimize behavior.
352+
* @param connection The connection object
353+
* @param options The JDBC options for the connection.
354+
*/
355+
def beforeFetch(connection: Connection, options: JDBCOptions): Unit = {
356+
beforeFetch(connection, options.parameters)
357+
}
358+
348359
/**
349360
* Escape special characters in SQL string literals.
350361
* @param value The string to be escaped.

0 commit comments

Comments
 (0)