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
- Download DataDirect Salesforce Spark Connector (JDBC). For step by step installation instructions please refer our product documentation.
- Open your terminal and run the following command to start the Spark shell with Salesforce JDBC driver path as its parameter:
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.sqlContext.sql("select * from account").collect.foreach(println)
You should be able to see your result as shown below:
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.