You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Apache Spark (Jira)" <ji...@apache.org> on 2021/05/13 12:07:00 UTC
[jira] [Assigned] (SPARK-28834) JDBC option "sessionInitStatement"
does not executes sql statement when write data into database from
dataframe
[ https://issues.apache.org/jira/browse/SPARK-28834?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Apache Spark reassigned SPARK-28834:
------------------------------------
Assignee: Apache Spark
> JDBC option "sessionInitStatement" does not executes sql statement when write data into database from dataframe
> ---------------------------------------------------------------------------------------------------------------
>
> Key: SPARK-28834
> URL: https://issues.apache.org/jira/browse/SPARK-28834
> Project: Spark
> Issue Type: Bug
> Components: Spark Core
> Affects Versions: 2.4.0
> Reporter: raoxunrong
> Assignee: Apache Spark
> Priority: Major
>
> I need to write dataframe data into database, after database session is opened to the remote DB and before starting to write data, I need to execute a custom SQL statement with option "sessionInitStatement", all i know is that "sessionInitStatement" will always executes the configured sql statement before operation.
> When write data with code below:
>
> {code:java}
> df.toDF(columns: _*).write.format("jdbc").options(
> Map(
> "url" -> db.url,
> "user" -> db.user,
> "dbtable" -> table,
> "password" -> db.password,
> JDBC_BATCH_INSERT_SIZE -> batchSize.toString,
> "sessionInitStatement" -> "set @@session.tidb_batch_insert=1;"
> )).mode(Append).save()
> {code}
>
> the sql statement "set @@session.tidb_batch_insert=1;" is never executed.
>
> If i read data from database:
> {code:java}
> reader.format("jdbc").options(
> Map(
> "url" -> dbProperties.dbUrl,
> "dbtable" -> alias(queryStatement),
> "user" -> dbProperties.userName,
> "sessionInitStatement" -> "set @@session.tidb_batch_insert=1;",
> "password" -> dbProperties.password
> )).load
> {code}
> the sql statement "set @@session.tidb_batch_insert=1;" is executed correctly.
> In my opinion, "sessionInitStatement" option should execute sql statement after database session is opened to the remote DB, no matter you read data or write data.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org