Ready to get started?

Learn more about the CData JDBC Driver for FedEx or download a free trial:

Download Now

Work with FedEx Data in Apache Spark Using SQL

Access and process FedEx 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 FedEx, Spark can work with live FedEx data. This article describes how to connect to and query FedEx data from a Spark shell.

The CData JDBC Driver offers unmatched performance for interacting with live FedEx data due to optimized data processing built into the driver. When you issue complex SQL queries to FedEx, the driver pushes supported SQL operations, like filters and aggregations, directly to FedEx 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 FedEx data using native data types.

Install the CData JDBC Driver for FedEx

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

Start a Spark Shell and Connect to FedEx Data

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

    There are five pieces of information needed in order to authenticate its actions with the FedEx service. This information is below.

    • Server: This controls the URL where the requests should be sent. Common testing options for this are: "https://gatewaybeta.fedex.com:443/xml", "https://wsbeta.fedex.com:443/xml", "https://gatewaybeta.fedex.com:443/web-service", and "https://wsbeta.fedex.com:443/web-service"
    • DeveloperKey: This is the identifier part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
    • Password: This is the secret part of the authentication key for the sender's identity. This value will be provided to you by FedEx after registration.
    • AccountNumber: This valid 9-digit FedEx account number is used for logging into the FedEx server.
    • MeterNumber: This value is used for submitting requests to FedEx. This value will be provided to you by FedEx after registration.
    • PrintLabelLocation: This property is required if one intends to use the GenerateLabels or GenerateReturnLabels stored procedures. This should be set to the folder location where generated labels should be stored.

    The Cache Database

    Many of the useful tasks available from FedEx require a lot of data. To ensure this data is easy to input and recall later, utilizes a cache database to make these requests. You must set the cache connection properties:

    • CacheProvider: The specific database you are using to cache with. For example, org.sqlite.JDBC.
    • CacheConnection: The connection string to be passed to the cache provider. For example, jdbc:sqlite:C:\users\username\documents\fedexcache.db

    Built-in Connection String Designer

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

    java -jar cdata.jdbc.fedex.jar

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

    scala> val fedex_df = spark.sqlContext.read.format("jdbc").option("url", "jdbc:fedex:Server='https://gatewaybeta.fedex.com:443/xml';DeveloperKey='alsdkfjpqoewiru';Password='zxczxqqtyiuowkdlkn';AccountNumber='110371337';MeterNumber='240134349'; PrintLabelLocation='C:\users\username\documents\mylabels';CacheProvider='org.sqlite.JDBC';CacheConnection='jdbc:sqlite:C:\users\username\documents\fedexcache.db';").option("dbtable","Senders").option("driver","cdata.jdbc.fedex.FedExDriver").load()
  3. Once you connect and the data is loaded you will see the table schema displayed.
  4. Register the FedEx data as a temporary table:

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

    scala> fedex_df.sqlContext.sql("SELECT FirstName, Phone FROM Senders WHERE SenderID = ab26f704-5edf-4a9f-9e4c-25").collect.foreach(println)

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

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