Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →How to work with Confluence Data in Apache Spark using SQL
Access and process Confluence 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 Confluence, Spark can work with live Confluence data. This article describes how to connect to and query Confluence data from a Spark shell.
The CData JDBC Driver offers unmatched performance for interacting with live Confluence data due to optimized data processing built into the driver. When you issue complex SQL queries to Confluence, the driver pushes supported SQL operations, like filters and aggregations, directly to Confluence 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 Confluence data using native data types.
Install the CData JDBC Driver for Confluence
Download the CData JDBC Driver for Confluence installer, unzip the package, and run the JAR file to install the driver.
Start a Spark Shell and Connect to Confluence Data
- Open a terminal and start the Spark shell with the CData JDBC Driver for Confluence JAR file as the jars parameter:
$ spark-shell --jars /CData/CData JDBC Driver for Confluence/lib/cdata.jdbc.confluence.jar
- With the shell running, you can connect to Confluence with a JDBC URL and use the SQL Context load() function to read a table.
Obtaining an API Token
An API token is necessary for account authentication. To generate one, login to your Atlassian account and navigate to API tokens > Create API token. The generated token will be displayed.
Connect Using a Confluence Cloud Account
To connect to a Cloud account, provide the following (Note: Password has been deprecated for connecting to a Cloud Account and is now used only to connect to a Server Instance.):
- User: The user which will be used to authenticate with the Confluence server.
- APIToken: The API Token associated with the currently authenticated user.
- Url: The URL associated with your JIRA endpoint. For example, https://yoursitename.atlassian.net.
Connect Using a Confluence Server Instance
To connect to a Server instance, provide the following:
- User: The user which will be used to authenticate with the Confluence instance.
- Password: The password which will be used to authenticate with the Confluence server.
- Url: The URL associated with your JIRA endpoint. For example, https://yoursitename.atlassian.net.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Confluence JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.confluence.jar
Fill in the connection properties and copy the connection string to the clipboard.
Configure the connection to Confluence, using the connection string generated above.
scala> val confluence_df = spark.sqlContext.read.format("jdbc").option("url", "jdbc:confluence:User=admin;APIToken=myApiToken;Url=https://yoursitename.atlassian.net;Timezone=America/New_York;").option("dbtable","Pages").option("driver","cdata.jdbc.confluence.ConfluenceDriver").load()
- Once you connect and the data is loaded you will see the table schema displayed.
Register the Confluence data as a temporary table:
scala> confluence_df.registerTable("pages")
-
Perform custom SQL queries against the Data using commands like the one below:
scala> confluence_df.sqlContext.sql("SELECT Key, Name FROM Pages WHERE Id = 10000").collect.foreach(println)
You will see the results displayed in the console, similar to the following:
Using the CData JDBC Driver for Confluence in Apache Spark, you are able to perform fast and complex analytics on Confluence data, combining the power and utility of Spark with your data. Download a free, 30 day trial of any of the 200+ CData JDBC Drivers and get started today.