Ready to get started?

Learn more about the CData JDBC Driver for SQL Analysis Services or download a free trial:

Download Now

Work with SQL Analysis Services Data in Apache Spark Using SQL

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

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

Install the CData JDBC Driver for SQL Analysis Services

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

Start a Spark Shell and Connect to SQL Analysis Services Data

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

    To connect, provide authentication and set the Url property to a valid SQL Server Analysis Services endpoint. You can connect to SQL Server Analysis Services instances hosted over HTTP with XMLA access. See the Microsoft documentation to configure HTTP access to SQL Server Analysis Services.

    To secure connections and authenticate, set the corresponding connection properties, below. The data provider supports the major authentication schemes, including HTTP and Windows, as well as SSL/TLS.

    • HTTP Authentication

      Set AuthScheme to "Basic" or "Digest" and set User and Password. Specify other authentication values in CustomHeaders.

    • Windows (NTLM)

      Set the Windows User and Password and set AuthScheme to "NTLM".

    • Kerberos and Kerberos Delegation

      To authenticate with Kerberos, set AuthScheme to NEGOTIATE. To use Kerberos delegation, set AuthScheme to KERBEROSDELEGATION. If needed, provide the User, Password, and KerberosSPN. By default, the data provider attempts to communicate with the SPN at the specified Url.

    • SSL/TLS:

      By default, the data provider attempts to negotiate SSL/TLS by checking the server's certificate against the system's trusted certificate store. To specify another certificate, see the SSLServerCert property for the available formats.

    You can then access any cube as a relational table: When you connect the data provider retrieves SSAS metadata and dynamically updates the table schemas. Instead of retrieving metadata every connection, you can set the CacheLocation property to automatically cache to a simple file-based store.

    See the Getting Started section of the CData documentation, under Retrieving Analysis Services Data, to execute SQL-92 queries to the cubes.

    Built-in Connection String Designer

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

    java -jar cdata.jdbc.ssas.jar

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

    scala> val ssas_df = spark.sqlContext.read.format("jdbc").option("url", "jdbc:ssas:User=myuseraccount;Password=mypassword;URL=http://localhost/OLAP/msmdpump.dll;").option("dbtable","Adventure_Works").option("driver","cdata.jdbc.ssas.SSASDriver").load()
  3. Once you connect and the data is loaded you will see the table schema displayed.
  4. Register the SQL Analysis Services data as a temporary table:

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

    scala> ssas_df.sqlContext.sql("SELECT Fiscal_Year, Sales_Amount FROM Adventure_Works WHERE Fiscal_Year = FY 2008").collect.foreach(println)

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

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