Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,4 +513,14 @@ class OracleIntegrationSuite extends DockerJDBCIntegrationSuite with SharedSpark
""".stripMargin.replaceAll("\n", " "))
assert(sql("select id, d, t from queryOption").collect.toSet == expectedResult)
}

test("sessionInitStatement for write path") {
val df1 = sparkContext.parallelize(Seq(("foo"))).toDF("x")
val tableName = "SPARK-28834"
val writeProps = new Properties()
writeProps.setProperty("sessionInitStatement",
"CREATE TABLE IF NOT EXISTS " + tableName + " (id number(10) NOT NULL)")
df1.write.jdbc(jdbcUrl, tableName + "op", writeProps)
assert(spark.read.jdbc(jdbcUrl, tableName, new Properties()).collect().isEmpty)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@ object JdbcUtils extends Logging {
val conn = getConnection()
var committed = false

options.sessionInitStatement.foreach { sql =>
val statement = conn.prepareStatement(sql)
logInfo(s"Executing sessionInitStatement: $sql")
try {
statement.setQueryTimeout(options.queryTimeout)
statement.execute()
} finally {
statement.close()
}
}

var finalIsolationLevel = Connection.TRANSACTION_NONE
if (isolationLevel != Connection.TRANSACTION_NONE) {
try {
Expand Down