Java Code Examples for org.apache.hadoop.hbase.HTableDescriptor#hasFamily()

The following examples show how to use org.apache.hadoop.hbase.HTableDescriptor#hasFamily() . 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: HBaseWindowStore.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public void connect() throws IOException
{
  super.connect();
  HTableDescriptor tdesc = table.getTableDescriptor();
  if (!tdesc.hasFamily(columnFamilyBytes)) {
    HBaseAdmin admin = new HBaseAdmin(table.getConfiguration());
    admin.disableTable(table.getTableName());
    try {
      HColumnDescriptor cdesc = new HColumnDescriptor(columnFamilyBytes);
      admin.addColumn(table.getTableName(), cdesc);
    } finally {
      admin.enableTable(table.getTableName());
      admin.close();
    }
  }
}
 
Example 2
Source File: ModifyTableCommand.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Override
public boolean execute(HbaseAdminOperation hbaseAdminOperation) {
    HTableDescriptor htd = getHtd();
    HColumnDescriptor[] hcds = htd.getColumnFamilies();
    if (ArrayUtils.isEmpty(hcds)) {
        return false;
    }

    TableName tableName = htd.getTableName();
    HTableDescriptor currentHtd = hbaseAdminOperation.getTableDescriptor(tableName);

    // Filter existing column families as column family modification is not supported.
    // We could use modifyTable(HTableDescriptor) to add column families, but this deletes existing column families
    // if they are not specified in HTableDescriptor and this may be dangerous.
    // Instead, use addColumn.
    boolean changesMade = false;
    for (HColumnDescriptor hcd : hcds) {
        if (!currentHtd.hasFamily(hcd.getName())) {
            logger.info("Adding {} to {} table.", hcd, tableName);
            hbaseAdminOperation.addColumn(tableName, hcd);
            changesMade = true;
        }
    }
    return changesMade;
}
 
Example 3
Source File: SchemaTool.java    From kite with Apache License 2.0 6 votes vote down vote up
/**
 * Prepare the Table descriptor for the given entity Schema
 */
private HTableDescriptor prepareTableDescriptor(String tableName,
    String entitySchemaString) {
  HTableDescriptor descriptor = new HTableDescriptor(
      Bytes.toBytes(tableName));
  AvroEntitySchema entitySchema = parser
      .parseEntitySchema(entitySchemaString);
  Set<String> familiesToAdd = entitySchema.getColumnMappingDescriptor()
      .getRequiredColumnFamilies();
  familiesToAdd.add(new String(Constants.SYS_COL_FAMILY));
  familiesToAdd.add(new String(Constants.OBSERVABLE_COL_FAMILY));
  for (String familyToAdd : familiesToAdd) {
    if (!descriptor.hasFamily(familyToAdd.getBytes())) {
      descriptor.addFamily(new HColumnDescriptor(familyToAdd));
    }
  }
  return descriptor;
}
 
Example 4
Source File: HtdHbaseSchemaVerifier.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private boolean verifySchema(HTableDescriptor expected, HTableDescriptor actual) {
    if (!expected.getTableName().equals(actual.getTableName())) {
        return false;
    }
    for (HColumnDescriptor expectedHcd : expected.getFamilies()) {
        if (!actual.hasFamily(expectedHcd.getName())) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: SchemaTool.java    From kite with Apache License 2.0 5 votes vote down vote up
/**
 * add the column families which are not already present to the given table
 */
private void modifyTable(String tableName, HTableDescriptor newDescriptor) {
  LOG.info("Modifying table " + tableName);
  HColumnDescriptor[] newFamilies = newDescriptor.getColumnFamilies();
  try {
    List<HColumnDescriptor> columnsToAdd = Lists.newArrayList();
    HTableDescriptor currentFamilies = hbaseAdmin
        .getTableDescriptor(Bytes.toBytes(tableName));
    for (HColumnDescriptor newFamily : newFamilies) {
      if (!currentFamilies.hasFamily(newFamily.getName())) {
        columnsToAdd.add(new HColumnDescriptor(newFamily.getName()));
      }
    }
    // Add all the necessary column families
    if (!columnsToAdd.isEmpty()) {
      hbaseAdmin.disableTable(tableName);
      try {
        for (HColumnDescriptor columnToAdd : columnsToAdd) {
          hbaseAdmin.addColumn(tableName, columnToAdd);
        }
      } finally {
        hbaseAdmin.enableTable(tableName);
      }
    }
  } catch (IOException e) {
    throw new DatasetException(e);
  }
}
 
Example 6
Source File: HBaseLookupTable.java    From pxf with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if {@link #LOOKUPTABLENAME} has {@value #LOOKUPCOLUMNFAMILY}
 * family.
 *
 * @return whether lookup has expected column family name
 */
private boolean lookupHasCorrectStructure() throws IOException {
    HTableDescriptor htd = admin.getTableDescriptor(TableName.valueOf(LOOKUPTABLENAME));
    return htd.hasFamily(LOOKUPCOLUMNFAMILY);
}