You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "raoxunrong (Jira)" <ji...@apache.org> on 2019/08/21 10:25:00 UTC

[jira] [Created] (SPARK-28834) JDBC option "sessionInitStatement" does not executes sql statement when write data into database from dataframe

raoxunrong created SPARK-28834:
----------------------------------

             Summary: 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


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.2#803003)

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