How to work with Talkdesk Data in Apache Spark using SQL

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Access and process Talkdesk Data in Apache Spark using the CData JDBC Driver.

Apache Spark is a fast and general engine for large-scale data processing. When paired with the CData JDBC Driver for Talkdesk, Spark can work with live Talkdesk data. This article describes how to connect to and query Talkdesk data from a Spark shell.

The CData JDBC Driver offers unmatched performance for interacting with live Talkdesk data due to optimized data processing built into the driver. When you issue complex SQL queries to Talkdesk, the driver pushes supported SQL operations, like filters and aggregations, directly to Talkdesk and utilizes the embedded SQL engine to process unsupported operations (often SQL functions and JOIN operations) client-side. With built-in dynamic metadata querying, you can work with and analyze Talkdesk data using native data types.

Install the CData JDBC Driver for Talkdesk

Download the CData JDBC Driver for Talkdesk installer, unzip the package, and run the JAR file to install the driver.

Start a Spark Shell and Connect to Talkdesk Data

  1. Open a terminal and start the Spark shell with the CData JDBC Driver for Talkdesk JAR file as the jars parameter:
    
    $ spark-shell --jars /CData/CData JDBC Driver for Talkdesk/lib/cdata.jdbc.talkdesk.jar
    
  2. With the shell running, you can connect to Talkdesk with a JDBC URL and use the SQL Context load() function to read a table.

    Talkdesk uses the OAuth 2.0 Client Credentials grant. There is no browser-based authorization step and no callback URL.

    Set the following connection properties:

    • AccountName: The name of your Talkdesk account.
    • Region: The region where your Talkdesk instance is deployed. Supported values are US (default), EU, CA, AU, UK, and FedRamp.
    • OAuthClientId: The Client Id assigned when you registered your custom OAuth application.
    • OAuthClientSecret: The Client Secret assigned to your custom OAuth application.

    Creating a Custom OAuth Application

    1. Log in to your Talkdesk account and select OAuth Clients from the navigation menu.
    2. Click Create OAuth Client and give the client a descriptive name.
    3. Set Grant Type to Client Credentials.
    4. Click Add scopes and select the scopes for the data you want to access.
    5. Click Create and copy the Client Id and Client Secret.

    When you connect, the driver automatically requests an access token from Talkdesk, caches it, and refreshes it when it expires. Make sure the scopes selected for the application match the views you plan to query, or the token request can fail.

    Built-in Connection String Designer

    For assistance in constructing the JDBC URL, use the connection string designer built into the Talkdesk JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

    
    java -jar cdata.jdbc.talkdesk.jar
    

    Fill in the connection properties and copy the connection string to the clipboard.

    Using the built-in connection string designer to generate a JDBC URL (Salesforce is shown.)

    Configure the connection to Talkdesk, using the connection string generated above.

    
    scala> val talkdesk_df = spark.sqlContext.read.format("jdbc").option("url", "jdbc:talkdesk:AccountName=myAccount;Region=US;OAuthClientId=myClientId;OAuthClientSecret=myClientSecret;").option("dbtable","Users").option("driver","cdata.jdbc.talkdesk.TalkdeskDriver").load()
    
  3. Once you connect and the data is loaded you will see the table schema displayed.
  4. Register the Talkdesk data as a temporary table:

    scala> talkdesk_df.registerTable("users")
  5. Perform custom SQL queries against the Data using commands like the one below:

    scala> talkdesk_df.sqlContext.sql("SELECT Id, Name FROM Users WHERE Active = true").collect.foreach(println)

    You will see the results displayed in the console, similar to the following:

    Data in Apache Spark (Salesforce is shown)

Using the CData JDBC Driver for Talkdesk in Apache Spark, you are able to perform fast and complex analytics on Talkdesk data, combining the power and utility of Spark with your data. Download a free, 30 day trial of any of the hundreds of CData JDBC Drivers and get started today.

Ready to get started?

Download a free trial of the Talkdesk Driver to get started:

 Download Now

Learn more:

Talkdesk Icon Talkdesk JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Talkdesk data including Accounts, Attributes, BillingAccounts, Callbacks, Campaigns, Cases, Contacts, GuardianUsers, Invoices, Products, Subscriptions, Teams, Users, Wallets, and more!