How to work with Sage X3 Cloud Data in Apache Spark using SQL

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
Access and process Sage X3 Cloud 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 Sage X3 Cloud, Spark can work with live Sage X3 Cloud data. This article describes how to connect to and query Sage X3 Cloud data from a Spark shell.

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

Install the CData JDBC Driver for Sage X3 Cloud

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

Start a Spark Shell and Connect to Sage X3 Cloud Data

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

    Sage X3 Cloud uses the OAuth 2.0 Client Credentials flow, and an X-API-Key is also required for API access. Set AuthScheme to OAuth and specify the following connection properties:

    • URL: The base URL of your Sage X3 Cloud instance.
    • OAuthAccessTokenUrl: The OAuth token endpoint (e.g., https://your-auth-domain/oauth/token).
    • OAuthClientId: Your OAuth application client ID.
    • OAuthClientSecret: Your OAuth application client secret.
    • Audience: The API audience value for the token request.
    • XAPIKey: The X-API-Key provided by your Sage X3 Cloud administrator.
    • Folder: The Sage X3 folder name (e.g., SEED). This folder is used as the default schema.
    • Folders (optional): A comma-separated list of Sage X3 folders (e.g., SEED,PERF). Each folder is exposed as a separate schema, so you can query across folders with the Schema.Table syntax.

    The driver obtains an access token with the Client Credentials flow and sends it with the X-API-Key on every API request. With InitiateOAuth set to GETANDREFRESH (the default), the driver acquires and refreshes the token automatically.

    Built-in Connection String Designer

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

    
    java -jar cdata.jdbc.sagex3cloud.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 Sage X3 Cloud, using the connection string generated above.

    
    scala> val sagex3cloud_df = spark.sqlContext.read.format("jdbc").option("url", "jdbc:sagex3cloud:AuthScheme=OAuth;URL=https://x3server/;OAuthAccessTokenUrl=https://auth-domain/oauth/token;OAuthClientId=your_client_id;OAuthClientSecret=your_client_secret;Audience=https://api-audience;XAPIKey=your_api_key;Folder=SEED;").option("dbtable","BPCUSTOMER").option("driver","cdata.jdbc.sagex3cloud.SageX3CloudDriver").load()
    
  3. Once you connect and the data is loaded you will see the table schema displayed.
  4. Register the Sage X3 Cloud data as a temporary table:

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

    scala> sagex3cloud_df.sqlContext.sql("SELECT BPCNUM, BPCNAM FROM BPCUSTOMER WHERE BPCNUM = MARTIN").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 Sage X3 Cloud in Apache Spark, you are able to perform fast and complex analytics on Sage X3 Cloud 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 Sage X3 Cloud Driver to get started:

 Download Now

Learn more:

Sage X3 Cloud Icon Sage X3 Cloud JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Sage X3 Cloud.