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 JDBC Driver and data source API of Spark to integrate Salesforce data in Spark. Sai Krishna Bobba, a developer evangelist for DataDirect connectors, 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 ="jdbc").option("url","jdbc:datadirect:sforce://;").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:

  • 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.

Try Now



Nishanth Kadiyala

Nishanth Kadiyala is a Technical Marketing Manager at Progress. He got his B.Tech degree from IIT Guwahati and his MBA from UNC Chapel Hill. He has worked on several technologies including database designing, SQL querying and Cloud Computing in the past. Currently, he is committed to educating enterprises about standards based connectivity via ODBC, JDBC, ADO.NET and OData. He is also proficient with DataDirect Hybrid Connectivity Services – DataDirect Cloud and Hybrid Data Pipeline. You can stay in touch with him through Twitter.

Comments are disabled in preview mode.
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
More From Progress
Then, Now and Beyond: The Future of Back Office Software
Read More
2020 Progress Data Connectivity Report
2020 Progress Data Connectivity Report
Read More
Getting Ahead of the Hybrid Data Curve
Read More