Home Partners Company
Spark Salesforce Connector Tutorial Using JDBC

Spark Salesforce Connector Tutorial Using JDBC

March 24, 2016 0 Comments

Apache Spark, the open source big data processing framework, was built for speed, ease and complex analytics. Learn how to access Salesforce data in Spark.

Spark has several comprehensive advantages to MapReduce technologies such as Hadoop and Storm. Spark has an advanced directed acyclic graph (DAG) pattern that supports cyclic data flows and also allows programmers to develop multi-step pipelines. Several tasks can be performed on the same data through in-memory data sharing across DAGs. Using Apache Spark, one can run up to 100 times faster in memory and that is one of the major reasons most organizations want to use Spark.

The tricky part is getting access to data stored in other applications to leverage the power of Spark. A common scenario we see is the development of sophisticated transformations in the Spark framework with cloud application data, such as Salesforce, Eloqua or Marketo. Many developers are turning to the Progress DataDirect Salesforce Spark Connector and DataSource API of Spark to integrate Salesforce data in Spark. Sai Krishna Bobba, a developer evangelist at DataDirect, created this quick tutorial below to help you get started with your connection:

Accessing Salesforce Data in Spark

spark-shell --jars /path_to_driver/sforce.jar

  • The shell will start running. At the scala prompt, establish a connection to Salesforce and read a table with SQL Context load function using the following command:

    val dataframe_salesforce = sqlContext.read.format("jdbc").option("url","jdbc:datadirect:sforce://login.salesforce.com;").option("driver","com.ddtek.jdbc.sforce.SForceDriver").option("dbtable","SFORCE.<table_name>").option("user","<Username>").option("password","<password>").option("securitytoken","<security_token>").load()

     

  • Once you are successfully authenticated the scala shell will display the schema of the table that you requested.
  • For future SQL queries, you can register the data as a temp table using the following command:
dataframe_salesforce.registerTempTable("account")

  • Now you can use dataframe to run SQL queries and access the Salesforce data using the following command:
dataframe_salesforce.sqlContext.sql("select * from account").collect.foreach(println)

You should be able to see your result as shown below:

Apache Spark

All Finished

We hope this tutorial helped you access Salesforce data and process your datasets in Spark. This demonstration is not limited to Salesforce. In fact, you can use the Spark’s DataSource API with any of the DataDirect JDBC Spark connectors or DataDirect Cloud JDBC Spark connectors to connect and integrate to over 50+ datasources including SaaS, Relational and Big data sources.

Please contact us if you have any questions and share your comments below.

Nishanth-Kadiyala

Nishanth Kadiyala

Nishanth Kadiyala is a Technical Marketing Manager at Progress. He has worked as a Software IT professional for 3 years during which he actively pursued several technologies including database designing, SQL querying and Cloud Computing. He is currently pursuing his MBA at UNC Chapel Hill and concentrating in Marketing. At UNC, he became proficient with data analytic tools such as MEXL and R. He is interested in the SaaS, Cloud and data integration technologies that are revolutionizing the world we live in.

Read next JDBC Tutorial: Extracting Database Metadata via JDBC Driver
Comments
Comments are disabled in preview mode.