Creating Column Families in JSON Tables

You can create column families by using either of two methods.

  • Run the command maprcli table cf create.
  • When you create a table with the Java API, use the Admin.createTable(TableDescriptor tableDescriptor) method. Add a column family to the TableDescriptor object before passing that object to the createTable() method.

Restriction

If any existing column family in a JSON table, including the default column family, uses a time-to-live that is greater than 0, you cannot create any additional column families in that table. See Setting TTL for Data in JSON Tables.

Permissions Required

The readAce and writeAce permissions on the volumes where the JSON tables are located. For information about how to set permissions on volumes, see Setting/Modifying Whole Volume ACEs.

Example

Here is an example of using the API to create two column families -- the default column family and a custom column family -- during the creation of a table:

/* Create a TableDescriptor for the table to create,
   passing in the path of the table. */
TableDescriptor tableDescriptor = MapRDB.newTableDescriptor(tablePath);

/* Create a FamilyDescriptor for the default column family.
   When you create a table with the API, you must also create
   the default column family.
   After creating the FamilyDescriptor, add it to 
   the TableDescriptor. */
FamilyDescriptor defaultfamilyDesc = MapRDB.newDefaultFamilyDescriptor();
tableDescriptor.addFamily(defaultfamilyDesc);

/* Create a FamilyDescriptor for the custom column family
   to create. The setJsonFieldPath() method specifies the field
   at which to create the column family.
   After creating the FamilyDescriptor, add it to 
   the TableDescriptor. */
FamilyDescriptor familyDescriptor = MapRDB.newFamilyDescriptor()
  .setName("CF1")
  .setJsonFieldPath("a.b");
tableDescriptor.addFamily(familyDescriptor);

// Pass the TableDescriptor to the Admin.createTable() method.
public void createJSONTable(String tablePath, TableDescriptor tableDescriptor) throws DBException {
  try (Admin admin = MapRDB.newAdmin()) {
    if (!admin.tableExists(tablePath)) {
      admin.createTable(tableDescriptor).close();
    }
  }
}