简体   繁体   中英

Spark Jdbc connection JDBCOptions

I am trying to use the method savetable in the Spark JdbcUtils

https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JdbcUtils.scala

The defination of the method is the following. It accepts the JDBCOptions as one of the parameter.

def saveTable(
      df: DataFrame,
      tableSchema: Option[StructType],
      isCaseSensitive: Boolean,
      options: JDBCOptions)

Following is the class of the JDBCOptions

https://github.com/apache/spark/blob/master/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/jdbc/JDBCOptions.scala

While i am initializing the JDBCOptions with the url,transaction isolation level etc it is throwing errors.

Can you provide insights in initialization of the JDBCOptions

 val options :JDBCOptions = Map("url" -> "JDBCUrl")
Error Type Map doesnt conform to be JDBCOption Type

How to initialize with correct type ?

You need to wrap the Map in a new JDBCOptions(...) call

// url and dbtable are required
val options:JDBCOptions = new JDBCOptions(Map("url" -> "JDBCUrl", "dbtable" -> "foo"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM