Wednesday, 20 June 2018

Spark to Connect with Azure SQL DB and read Table


Introduction
In this article we are trying to connect spark with Azure SQL DB and just simply read a table.
Hope it will be interesting.

Scala Code
import com.microsoft.azure.sqldb.spark.bulkcopy.BulkCopyMetadata
import com.microsoft.azure.sqldb.spark.config.Config
import com.microsoft.azure.sqldb.spark.connect._
val url = "[Enter your url here]"
val databaseName = "[Enter your database name here]"
val dbTable = "[Enter your database table here]"
val user = "[Enter your username here]"
val password = "[Enter your password here]"

// READ FROM CONFIG
val readConfig = Config(Map(
  "url"            -> url,
  "databaseName"   -> databaseName,
  "user"           -> user,
  "password"       -> password,
  "connectTimeout" -> "5",
  "queryTimeout"   -> "5",
  "dbTable"        -> dbTable
))
val df = sqlContext.read.sqlDB(readConfig)
println("Total rows: " + df.count)
df.show()
// TRADITIONAL SYNTAX
import java.util.Properties
val properties = new Properties()
properties.put("databaseName", databaseName)
properties.put("user", user)
properties.put("password", password)
properties.put("connectTimeout", "5")
properties.put("queryTimeout", "5")
val df = sqlContext.read.sqlDB(url, dbTable, properties)
println("Total rows: " + df.count)
df.show()



Hope you like it.



Posted by: MR. JOYDEEP DAS



5 comments:

  1. Pengertian Correct Score Sbobet atau Tebak Skor adalah salah satu jenis taruhan yang sangat menguntungkan selain mix parlay. Dikarenakan perkalian Odds / Hadiah Taruhannya yang sangat besar sehingga banyak menarik perhatian para pecandu Judi Bola. Tak hanya itu, dari sistem bermain pun sangatlah gampang karena (Baca Selengkapnya Disini...)

    ReplyDelete
  2. Microsoft SQL Server 2019 Standard provides provides additional capability and improvements database features. like SQL Server database engine, SQL Server Analysis Services, SQL Server Machine Learning Services, SQL Server on Linux, and SQL Server Master Data Services. Microsoft SQL Server Standard can build rich content management applications

    ReplyDelete
  3. Nice post, Your article explain very well about removing malware from pc in windows 10. but if any chance your window got corrupted or your windows license expired. For that Digital Software Market provide you best offer in all windows 10 and can Buy Window Keys Online without and issue. We are trusted brand and we are serving our customer with genuine product. We take every measure to ensure you receive a genuine working product with authentic manufacturer license keys & with required activation instructions and provide all related technical support to ensure you have your program up and running. If after receiving your purchase an error has occurred and you are unable to activate and get the program running after following all given instructions, please contact us immediately and we will remedy the issue as per our money back guarantee.

    ReplyDelete
  4. Players spend a lot of POE Currency because of fast travel, and they hope to have their own mounts in Path of Exile. Players can actually buy POE Currency they need at POECurrency.com.

    Attached link: https://www.poecurrency.com/

    ReplyDelete