Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →ETL Cosmos DB in Oracle Data Integrator
This article shows how to transfer Cosmos DB data into a data warehouse using Oracle Data Integrator.
Leverage existing skills by using the JDBC standard to read and write to Cosmos DB: Through drop-in integration into ETL tools like Oracle Data Integrator (ODI), the CData JDBC Driver for Cosmos DB connects real-time Cosmos DB data to your data warehouse, business intelligence, and Big Data technologies.
JDBC connectivity enables you to work with Cosmos DB just as you would any other database in ODI. As with an RDBMS, you can use the driver to connect directly to the Cosmos DB APIs in real time instead of working with flat files.
This article walks through a JDBC-based ETL -- Cosmos DB to Oracle. After reverse engineering a data model of Cosmos DB entities, you will create a mapping and select a data loading strategy -- since the driver supports SQL-92, this last step can easily be accomplished by selecting the built-in SQL to SQL Loading Knowledge Module.
Install the Driver
To install the driver, copy the driver JAR (cdata.jdbc.cosmosdb.jar) and .lic file (cdata.jdbc.cosmosdb.lic), located in the installation folder, into the ODI appropriate directory:
- UNIX/Linux without Agent: ~/.odi/oracledi/userlib
- UNIX/Linux with Agent: ~/.odi/oracledi/userlib and $ODI_HOME/odi/agent/lib
- Windows without Agent: %APPDATA%\Roaming\odi\oracledi\userlib
- Windows with Agent: %APPDATA%\odi\oracledi\userlib and %APPDATA%\odi\agent\lib
Restart ODI to complete the installation.
Reverse Engineer a Model
Reverse engineering the model retrieves metadata about the driver's relational view of Cosmos DB data. After reverse engineering, you can query real-time Cosmos DB data and create mappings based on Cosmos DB tables.
- In ODI, connect to your repository and click New -> Model and Topology Objects.
- On the Model screen of the resulting dialog, enter the following information:
- Name: Enter CosmosDB.
- Technology: Select Generic SQL (for ODI Version 12.2+, select Microsoft SQL Server).
- Logical Schema: Enter CosmosDB.
- Context: Select Global.
- On the Data Server screen of the resulting dialog, enter the following information:
- Name: Enter CosmosDB.
- Driver List: Select Oracle JDBC Driver.
- Driver: Enter cdata.jdbc.cosmosdb.CosmosDBDriver
- URL: Enter the JDBC URL containing the connection string.
To obtain the connection string needed to connect to a Cosmos DB account using the SQL API, log in to the Azure Portal, select Azure Cosmos DB, and select your account. In the Settings section, click Connection String and set the following values:
- AccountEndpoint: The Cosmos DB account URL from the Keys blade of the Cosmos DB account
- AccountKey: In the Azure portal, navigate to the Cosmos DB service and select your Azure Cosmos DB account. From the resource menu, go to the Keys page. Find the PRIMARY KEY value and set AccountKey to this value.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Cosmos DB JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.
java -jar cdata.jdbc.cosmosdb.jar
Fill in the connection properties and copy the connection string to the clipboard.
Below is a typical connection string:
jdbc:cosmosdb:AccountEndpoint=myAccountEndpoint;AccountKey=myAccountKey;
- On the Physical Schema screen, enter the following information:
- Name: Select from the Drop Down menu.
- Database (Catalog): Enter CData.
- Owner (Schema): If you select a Schema for Cosmos DB, enter the Schema selected, otherwise enter CosmosDB.
- Database (Work Catalog): Enter CData.
- Owner (Work Schema): If you select a Schema for Cosmos DB, enter the Schema selected, otherwise enter CosmosDB.
- In the opened model click Reverse Engineer to retrieve the metadata for Cosmos DB tables.
Edit and Save Cosmos DB Data
After reverse engineering you can now work with Cosmos DB data in ODI. To edit and save Cosmos DB data, expand the Models accordion in the Designer navigator, right-click a table, and click Data. Click Refresh to pick up any changes to the data. Click Save Changes when you are finished making changes.
Create an ETL Project
Follow the steps below to create an ETL from Cosmos DB. You will load Customers entities into the sample data warehouse included in the ODI Getting Started VM.
Open SQL Developer and connect to your Oracle database. Right-click the node for your database in the Connections pane and click new SQL Worksheet.
Alternatively you can use SQLPlus. From a command prompt enter the following:
sqlplus / as sysdba
- Enter the following query to create a new target table in the sample data warehouse, which is in the ODI_DEMO schema. The following query defines a few columns that match the Customers table in Cosmos DB:
CREATE TABLE ODI_DEMO.TRG_CUSTOMERS (COMPANYNAME NUMBER(20,0),City VARCHAR2(255));
- In ODI expand the Models accordion in the Designer navigator and double-click the Sales Administration node in the ODI_DEMO folder. The model is opened in the Model Editor.
- Click Reverse Engineer. The TRG_CUSTOMERS table is added to the model.
- Right-click the Mappings node in your project and click New Mapping. Enter a name for the mapping and clear the Create Empty Dataset option. The Mapping Editor is displayed.
- Drag the TRG_CUSTOMERS table from the Sales Administration model onto the mapping.
- Drag the Customers table from the Cosmos DB model onto the mapping.
- Click the source connector point and drag to the target connector point. The Attribute Matching dialog is displayed. For this example, use the default options. The target expressions are then displayed in the properties for the target columns.
- Open the Physical tab of the Mapping Editor and click CUSTOMERS_AP in TARGET_GROUP.
- In the CUSTOMERS_AP properties, select LKM SQL to SQL (Built-In) on the Loading Knowledge Module tab.
You can then run the mapping to load Cosmos DB data into Oracle.