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 Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  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!

Nishanth Kadiyala user avatar by
Nishanth Kadiyala
·
Apr. 01, 16 · Tutorial
Like (4)
Save
Tweet
Share
9.02K 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 , DZone MVB. See the original article here.

    Opinions expressed by DZone contributors are their own.

    Popular on DZone

    • Why Open Source Is Much More Than Just a Free Tier
    • Why It Is Important To Have an Ownership as a DevOps Engineer
    • SAST: How Code Analysis Tools Look for Security Flaws
    • Why You Should Automate Code Reviews

    Comments

    Partner Resources

    X

    ABOUT US

    • About DZone
    • Send feedback
    • Careers
    • Sitemap

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

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

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 600 Park Offices Drive
    • Suite 300
    • Durham, NC 27709
    • support@dzone.com
    • +1 (919) 678-0300

    Let's be friends: