![]() |
VOOZH | about |
Apache Spark is a fast and general engine for large-scale data processing. When paired with the CData JDBC Driver for IBM Cloud Object Storage, Spark can work with live IBM Cloud Object Storage data. This article describes how to connect to and query IBM Cloud Object Storage data from a Spark shell.
The CData JDBC Driver offers unmatched performance for interacting with live IBM Cloud Object Storage data due to optimized data processing built into the driver. When you issue complex SQL queries to IBM Cloud Object Storage, the driver pushes supported SQL operations, like filters and aggregations, directly to IBM Cloud Object Storage 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 IBM Cloud Object Storage data using native data types.
Download the CData JDBC Driver for IBM Cloud Object Storage installer, unzip the package, and run the JAR file to install the driver.
$ spark-shell --jars /CData/CData JDBC Driver for IBM Cloud Object Storage/lib/cdata.jdbc.ibmcloudobjectstorage.jar
If you do not already have Cloud Object Storage in your IBM Cloud account, follow the procedure below to install an instance of SQL Query in your account:
There are certain connection properties you need to set before you can connect. You can obtain these as follows:
To connect with IBM Cloud Object Storage, you need an API Key. You can obtain this as follows:
If you have multiple accounts, specify the CloudObjectStorageCRN explicitly. To find the appropriate value, you can:
You can now set the following to connect to data:
When you connect, the connector completes the OAuth process.
For assistance in constructing the JDBC URL, use the connection string designer built into the IBM Cloud Object Storage JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.ibmcloudobjectstorage.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 IBM Cloud Object Storage, using the connection string generated above.
scala> val ibmcloudobjectstorage_df = spark.sqlContext.read.format("jdbc").option("url", "jdbc:ibmcloudobjectstorage:ApiKey=myApiKey;CloudObjectStorageCRN=MyInstanceCRN;Region=myRegion;OAuthClientId=MyOAuthClientId;OAuthClientSecret=myOAuthClientSecret;").option("dbtable","Objects").option("driver","cdata.jdbc.ibmcloudobjectstorage.IBMCloudObjectStorageDriver").load()
Register the IBM Cloud Object Storage data as a temporary table:
scala> ibmcloudobjectstorage_df.registerTable("objects")
Perform custom SQL queries against the Data using commands like the one below:
scala> ibmcloudobjectstorage_df.sqlContext.sql("SELECT Key, Etag FROM Objects WHERE Bucket = someBucket").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 IBM Cloud Object Storage in Apache Spark, you are able to perform fast and complex analytics on IBM Cloud Object Storage 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.
Download a free trial of the IBM Cloud Object Storage Driver to get started:
Download NowLearn more:
👁 IBM Cloud Object Storage IconRapidly create and deploy powerful Java applications that integrate with IBM Cloud Object Storage.