1

I have a piece of scala code that works locally

val test = "resources/test.csv"

val trainInput = spark.read
  .option("header", "true")
  .option("inferSchema", "true")
  .format("com.databricks.spark.csv")
  .load(train)
  .cache

However when i try to run it on azure, spark by submitting the job, and adjusting the following line:

val test = "wasb:///tmp/MachineLearningScala/test.csv"

It doesn't work. How do i reference files in blob storage in azure using scala? This should be straight forward.

1 Answer 1

2

If you are using sbt add this dependency to built.sbt

"org.apache.hadoop" % "hadoop-azure" % "2.7.3"

For maven add the dependency as

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-azure</artifactId>
    <version>2.7.0</version>
</dependency>

To read the files from blob storage you need to define the file system to be used in the underlying Hadoop configurations.

spark.sparkContext.hadoopConfiguration.set("fs.azure", "org.apache.hadoop.fs.azure.NativeAzureFileSystem")
spark.sparkContext.hadoopConfiguration.set("fs.azure.account.key.yourAccount.blob.core.windows.net", "yourKey ")

And read the csv file as

  val path = "wasb[s]://[email protected]"
  val dataframe = spark.read
    .option("header", "true")
    .option("inferSchema", "true")
    .csv(path + "/tmp/MachineLearningScala/test.csv")

here is the example Hope this helped!

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

1 Comment

Thanks! Thats brilliant. I will try and implement now.

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.