DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • File Systems <> Database: Full Circle
  • How Trustworthy Is Big Data?
  • Enhancing Avro With Semantic Metadata Using Logical Types
  • A Deep Dive into Apache Doris Indexes

Trending

  • A Scalable Framework for Enterprise Salesforce Optimization: Turning Outcomes Into an Operating System
  • Building a Skill-Based Agentic Reviewer with Claude Code: A Practical Guide Using Skills.MD, MCP Servers, Tools, and Tasks
  • Spring AI Advisors: Chat Memory, Token Tracking, and Message Logging
  • Stateless JWT Auth Microservice Architecture With Spring Boot 3 and Redis Sentinel
  1. DZone
  2. Data Engineering
  3. Big Data
  4. Spark Salesforce Connector Tutorial Using JDBC

Spark Salesforce Connector Tutorial Using JDBC

We have a quick look at leveraging Apache Spark to access data in Salesforce via its JDBC connector. Come see how it's done!

By 
Nishanth Kadiyala user avatar
Nishanth Kadiyala
·
Apr. 01, 16 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
10.9K Views

Join the DZone community and get the full member experience.

Join For Free

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

    Big data Connector (mathematics) Database

    Published at DZone with permission of . See the original article here.

    Opinions expressed by DZone contributors are their own.

    Related

    • File Systems <> Database: Full Circle
    • How Trustworthy Is Big Data?
    • Enhancing Avro With Semantic Metadata Using Logical Types
    • A Deep Dive into Apache Doris Indexes

    Partner Resources

    ×

    Comments

    The likes didn't load as expected. Please refresh the page and try again.

    • RSS
    • X
    • Facebook

    ABOUT US

    • About DZone
    • Support and feedback
    • Community research

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

    • Article Submission Guidelines
    • Become a Contributor
    • Core Program
    • Visit the Writers' Zone

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 3343 Perimeter Hill Drive
    • Suite 215
    • Nashville, TN 37211
    • [email protected]

    Let's be friends:

    • RSS
    • X
    • Facebook