[ https://issues.apache.org/jira/browse/SPARK-28834?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17129209#comment-17129209 ]
Thomas Uhren commented on SPARK-28834: -------------------------------------- Any chance to get this issue resolved? > 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 > 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-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org