Java Code Examples for org.apache.hadoop.hbase.client.TableDescriptorBuilder#modifyColumnFamily()

The following examples show how to use org.apache.hadoop.hbase.client.TableDescriptorBuilder#modifyColumnFamily() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestMasterObserverToModifyTableSchema.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testMasterObserverToModifyTableSchema() throws IOException {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TABLENAME);
  for (int i = 1; i <= 3; i++) {
    builder.setColumnFamily(
        ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf" + i)).setMaxVersions(i)
            .build());
  }
  try (Admin admin = UTIL.getAdmin()) {
    admin.createTable(builder.build());
    assertOneVersion(admin.getDescriptor(TABLENAME));

    builder.modifyColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1"))
        .setMaxVersions(Integer.MAX_VALUE).build());
    admin.modifyTable(builder.build());
    assertOneVersion(admin.getDescriptor(TABLENAME));
  }
}
 
Example 2
Source File: Action.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Apply a transform to all columns in a given table. If there are no columns in a table
 * or if the context is stopping does nothing.
 * @param tableName the table to modify
 * @param transform the modification to perform. Callers will have the
 *                  column name as a string and a column family builder available to them
 */
protected void modifyAllTableColumns(TableName tableName,
  BiConsumer<String, ColumnFamilyDescriptorBuilder> transform) throws IOException {
  HBaseTestingUtility util = this.context.getHBaseIntegrationTestingUtility();
  Admin admin = util.getAdmin();

  TableDescriptor tableDescriptor = admin.getDescriptor(tableName);
  ColumnFamilyDescriptor[] columnDescriptors = tableDescriptor.getColumnFamilies();

  if (columnDescriptors == null || columnDescriptors.length == 0) {
    return;
  }

  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
  for (ColumnFamilyDescriptor descriptor : columnDescriptors) {
    ColumnFamilyDescriptorBuilder cfd = ColumnFamilyDescriptorBuilder.newBuilder(descriptor);
    transform.accept(descriptor.getNameAsString(), cfd);
    builder.modifyColumnFamily(cfd.build());
  }

  // Don't try the modify if we're stopping
  if (this.context.isStopping()) {
    return;
  }
  admin.modifyTable(builder.build());
}
 
Example 3
Source File: UpgradeUtil.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * Synchronize column family properties using the default cf properties for a given table
 * @param tableDesc table descriptor of table to modify
 * @param defaultColFam default column family used as the baseline for property synchronization
 * @param syncedProps Map of properties to be kept in sync as read from the default column family descriptor
 * @return modified table descriptor builder
 */
private static TableDescriptorBuilder syncColFamProperties(TableDescriptor tableDesc, ColumnFamilyDescriptor defaultColFam,
        Map<String, Object> syncedProps) {
    TableDescriptorBuilder tableDescBuilder = TableDescriptorBuilder.newBuilder(tableDesc);
    // Ensure that all column families have necessary properties in sync (including local index cf if present)
    for (ColumnFamilyDescriptor currentColFam: tableDesc.getColumnFamilies()) {
        if (!currentColFam.equals(defaultColFam)) {
            ColumnFamilyDescriptorBuilder colFamDescBuilder = ColumnFamilyDescriptorBuilder.newBuilder(currentColFam);
            for (String prop: MetaDataUtil.SYNCED_DATA_TABLE_AND_INDEX_COL_FAM_PROPERTIES) {
                String existingPropVal = Bytes.toString(currentColFam.getValue(Bytes.toBytes(prop)));
                String expectedPropVal = syncedProps.get(prop).toString();
                if (existingPropVal == null || !existingPropVal.toLowerCase().equals(expectedPropVal.toLowerCase())) {
                    // Need to synchronize this property for the current column family descriptor
                    colFamDescBuilder.setValue(prop, expectedPropVal);
                }
            }
            if (!colFamDescBuilder.equals(ColumnFamilyDescriptorBuilder.newBuilder(currentColFam))) {
                tableDescBuilder.modifyColumnFamily(colFamDescBuilder.build());
            }
        }
    }
    return tableDescBuilder;
}
 
Example 4
Source File: TestMasterObserverToModifyTableSchema.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public TableDescriptor preCreateTableRegionsInfos(
    ObserverContext<MasterCoprocessorEnvironment> ctx, TableDescriptor desc)
    throws IOException {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(desc);
  for (ColumnFamilyDescriptor cfd : desc.getColumnFamilies()) {
    builder.modifyColumnFamily(
        ColumnFamilyDescriptorBuilder.newBuilder(cfd).setMaxVersions(1).build());
  }
  return builder.build();
}
 
Example 5
Source File: TestMasterObserverToModifyTableSchema.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public TableDescriptor preModifyTable(ObserverContext<MasterCoprocessorEnvironment> env,
    TableName tableName, final TableDescriptor currentDescriptor,
    final TableDescriptor newDescriptor) throws IOException {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(newDescriptor);
  for (ColumnFamilyDescriptor cfd : newDescriptor.getColumnFamilies()) {
    builder.modifyColumnFamily(
        ColumnFamilyDescriptorBuilder.newBuilder(cfd).setMaxVersions(1).build());
  }
  return builder.build();
}