Altering Column Families

You can alter column families, including the default column family for a table, by using the Admin.alterFamily() method in the MapR Database JSON Java API library.

Permissions Required


Here is an example of using the API to change the name of a column family:

public void alterColumnFamily(String tablePath, String familyName,
  String newFamilyName) throws DBException {
  try (Admin admin = MapRDB.newAdmin()) {

    /* Get a TableDescriptor object for the table. This object
       gives access to the column families that are in the table. */ 
    TableDescriptor tableDesc = admin.getTableDescriptor(tablePath);

    /* Get a FamilyDescriptor object for the column family to
       change the name of. /
    FamilyDescriptor familyDesc = tableDesc.getFamily(familyName);

    // Rename the column family.

    /* Call alterFamily(), passing in the path of the table,
       the original name of the column family, and the 
       FamilyDescriptor in which the new name was set. */
    admin.alterFamily(tablePath, familyName, familyDesc);

Alternative Method

You can also edit column families in JSON tables by running the command table cf edit.