0

I'm trying to use the code below.

import com.microsoft.azure.sqldb.spark.config.Config
import com.microsoft.azure.sqldb.spark.connect._

// Aquire a DataFrame collection (val collection)

val config = Config(Map(
  "url"          -> "mysqlserver.database.windows.net",
  "databaseName" -> "MyDatabase",
  "dbTable"      -> "dbo.Clients"
  "user"         -> "username",
  "password"     -> "*********"
))

import org.apache.spark.sql.SaveMode
collection.write.mode(SaveMode.Append).sqlDB(config)

The script is from this link.

https://github.com/Azure/azure-sqldb-spark

I'm running this in a databricks environment. I'm getting these errors:

command-836397363127942:5: error: object sqlDB is not a member of package com.microsoft.azure
import com.microsoft.azure.sqlDB.spark.connect._
                           ^
command-836397363127942:4: error: object sqlDB is not a member of package com.microsoft.azure
import com.microsoft.azure.sqlDB.spark.config.Config
                           ^
command-836397363127942:7: error: not found: value Config
val bulkCopyConfig = Config(Map(
                     ^
command-836397363127942:18: error: value sqlDB is not a member of org.apache.spark.sql.DataFrameWriter[org.apache.spark.sql.Row]
df.write.mode(SaveMode.Append).sqlDB(bulkCopyConfig)

I'm guessing that some kind of library is not installed correctly. I Googled for an answer, but didn't find anything useful. Any idea how to make this work? Thanks.

2
  • Have you included the connector dependency azure-sqldb-spark ? It seems it's missing Commented Dec 19, 2019 at 21:09
  • add this and try <!-- mvnrepository.com/artifact/com.microsoft.azure/… --> <dependency> <groupId>com.microsoft.azure</groupId> <artifactId>azure-sqldb-spark</artifactId> <version>1.0.2</version> </dependency> Commented Dec 20, 2019 at 5:29

3 Answers 3

1

If you are getting the sqldb error means all other support libraries already imported to your notebook and only the latest JAR with dependencies are missing.

As per the repro, I got the same error message as shown above:

enter image description here

After bit of research, I had found that you will experience this error due to missing JAR with dependencies.

To resolve this issue, you need to download the JAR file from here: https://search.maven.org/artifact/com.microsoft.azure/azure-sqldb-spark/1.0.2/jar

enter image description here

After downloaded the jar file, upload the JAR library into the cluster and install it.

Note: After installing both the libraries, make sure to restart the cluster.

enter image description here

Now, you will be able to run the command successfully.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

I think you have missed the library

  1. If your using Maven Build Add the following library in pom.xml

    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-sqldb-spark</artifactId>
        <version>1.0.2</version>
    </dependency>
    
  2. If your using SBT Build Add the following library in build.sbt

    libraryDependencies += "com.microsoft.azure" % "azure-sqldb-spark" % "1.0.2"
    

Comments

0

Have you imported and installed the library in DataBricks?

I found it easiest to import the library using Maven. See this answer: How to install a library on a databricks cluster using some command in the notebook?

Note: You need to install the Library on your cluster and then restart the cluster before you can use it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.