2

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 ?

7
  • Providing the error message would help. Commented Feb 26, 2018 at 20:54
  • @AydinK. I am not sure how to initialize it ? Commented Feb 26, 2018 at 21:01
  • Have a look here: docs.databricks.com/spark/latest/data-sources/… Commented Feb 26, 2018 at 21:03
  • Or here (chapter „Running Jdbc to other Databases“): spark.apache.org/docs/latest/… Commented Feb 26, 2018 at 21:04
  • @AydinK. I looked into them. They are using using Options but i am using the JDBCOptions. Both are different. Commented Feb 26, 2018 at 21:07

1 Answer 1

3

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")) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.