IBM Developer Advocacy

Load JSON Data from Cloudant into dashDB

See how to create a new dashDB instance and populate it with data directly from a Cloudant account. Note: The following video is for the dashDB managed service, and does not apply to IBM dashDB Local.

What this tutorial is about

This tutorial will show you how to create a new dashDB instance and populate it with data
directly from a Cloudant account.

What you should be able to do

  • Provision a new dashDB instance from Cloudant
  • Populate the dashDB instance with data from Cloudant
  • Work with the created tables in dashDB
  • Run real-time replication from Cloudant to dashDB
  • Stop real-time replication
  • Delete the dashDB instance

What you need before you start

  • An IBM Bluemix Account. If you don’t have an account, sign up for a free account at https://bluemix.net
  • An IBM Cloudant Account. If you don’t have an account, you can sign up for a free account at https://cloudant.com
  • At least one small database in your Cloudant account. This tutorial will work with 2 databases from https://examples.cloudant.com called movies_demo and geo. You can either replicate those two databases into your own account or work with any other Cloudant database you may already have.

Step 1: Provision a dashDB instance from Cloudant

  1. Log in to your Cloudant dashboard.
  2. Optional: On the Databases tab, view the list of databases in your Cloudant account to find suitable database names, then open a database.
    database_listing_2

  3. Optional: Open and inspect individual documents in your database to understand their data and structure.

    document_geo

  4. Click the Warehousing tab.
  5. If you want to create a DB2 warehouse, then click Create a DB2 Warehouse, and complete the form.
    db2-warehouse
    1. Type the Warehouse Name.
    2. For Data Sources, type crimes.
    3. Next, specify the connection information; for example:
      • host: boston_server
      • port:50000
      • database:statistics
      • id:ablanks
      • password:password
    4. Click Create Warehouse.
  6. To create a dashDB warehouse, then click Create a dashDB Warehouse, and complete the form.

    create-warehouse-form
  7. Type your IBM id and password, and click Authenticate in Bluemix.
  8. Type the Warehouse Name.
  9. For the Data Sources, type movies-demo and geo. As you start typing, the type-ahead will list databases that match the characters you are typing.
  10. Select the location for the new warehouse: In this scenario, select Create a new dashDB instance.
  11. Check Customize Schema for both databases.
  12. Provision the new dashDB instance by clicking Create Warehouse.

    When you click Create Warehouse, two things happen:

    1. The process creates a new dashDB service in your Bluemix account.
    2. It scans both databases to understand the document structure in each database.
  13. Warehouse provisioned displays in the top left corner of the screen.
  14. On the Warehousing tab, click the warehouse link to open the warehouse configuration.
  15. Information about the new warehouse displays such as warehouse name, the list of source databases in the warehouse, the size of those databases, when they were last updated, and the current status (running).
  16. Click Customize movies-demo.

    schema-ready
    schema-editor
  17. Check/uncheck the columns to include in the warehouse.
  18. If this database contained multiple tables, you could select individual tables, or entire table hierarchies to deselect and omit from the target warehouse.
  19. The view provides some interesting statistics as well, including the number of documents that have a value for a field in the Frequency column.
  20. Change column types as you see fit.
  21. Change column length as you see fit.
  22. Click Search. The Search view allows you to find columns across table boundaries. This comes in handy when you have hundreds of columns with similar names, such as, CODE followed by a unique number (CODE_XXX). Using search, you wouldn’t have to deselect all of those columns manually.

    search-tab
  23. Click Rescan. The Rescan option provides two different discovery algorithms and a small tuning variable. You can even increase the discovery sample from the default 10,000 documents to a higher value that yields better results. Cloudant databases with mixed documents will especially benefit from the power of the Cluster algorithm. It will produce different schemas for every document type in your database and no longer just merge them all into a single set of tables. Click Cancel or Rescan.

    rescan
  24. When you are ready to use the schema you have, click Run.

  25. In this scenario, you don’t need to customize the schema for the geo database, so click Resume for that database to load the documents.
  26. When you run or resume a source database, two things happen:

    1. The process creates tables in the new dashDB database to represent these documents.
    2. It copies the data from Cloudant to dashDB.
  27. The progress indicator shows the number of documents being copied and the color-coded progress.
    • Green status indicates that Cloudant has loaded as many documents into dashDB as are currently in the source databases. Updated documents or new document revisions automatically update the corresponding records in dashDB in real-time replication.
    • Blue status indicates that there were problems either during the initial load or the ongoing replication.
  28. Click View in dashDB to launch the dashDB console.

    view-in-dashdb

Step 2: Work with the tables in your dashDB instance

  1. Click Go to your tables in the dashDB console.

    dashdb_go_to_tables
  2. Select the Schema and then the Table Name to inspect the Table Definition and view the created database tables.
    Note: Tables are created in a Schema with a name identical to the dashDB instance name. The schema is selected by default, but there are other sample schemas available in the default dashDB instance. Make sure to select the right schema to find the tables.

    dashdb_work_with_tables

  3. Select the Browse Data tab to view the data populated into the tables.

    >dashdb_work_with_tables_2

    Note: The Warehousing process may have created multiple tables for a single Cloudant database. All tables are prefixed with the capitalized database name, for example GEO_.

  4. Optional: Inspect the GEO_OVERFLOW table.

    Note: This table is created to capture warnings and exceptions that may happen during load. There is one OVERFLOW table for every source database (for example, GEO_OVERFLOW).
    dashdb_work_with_overflow

Step 3: Stop Cloudant replication, rescan, or delete the dashDB instance

  1. Log back into your Cloudant dashboard, and on the Warehousing tab, click View Warehouses.
  2. Click to open the movies-geo warehouse configuration.
  3. Stop the database load with the Stop action for the geo database.

    Note: Since the dashDB load from Cloudant is real-time replication, the load will never stop automatically. Even if all documents have long been processed, the Stop action is necessary to disconnect from the Cloudant changes feed. After stopping a database, you have the option to Rescan or Remove that database.
    warehouse_stop_cut
    rescan
    remove
  4. Stop the movies-demo database.
  5. Click the Rescan action for the geo database.

    Note: The rescan function inspects the previously discovered JSON schema and removes all tables from the dashDB instance created during the initial load. When you rescan, you can also choose to customize the schema or change the algorithm used during the rescan. Then it re-discovers the JSON schema, creates new tables, and ingests the Cloudant data.
    rescan-dialog-box
  6. Optional: Now that both databases are stopped, you have the option to Remove the warehouse which just removes the warehouse from the Cloudant dashboard, but leaves the dashDB instance intact. Or you can Delete the dashDB instance as well which will de-provision the dashDB instance and delete all data in it – even data that has been created manually or loaded outside of Cloudant.

  7. remove-warehouse
    delete-warehouse

  8. Click Resume to reload both databases.
blog comments powered by Disqus