@Override public Boolean run() throws IOException { return table.getTableDescriptor().hasFamily(columnFamily); } })) {
hcd.setValue(e.getKey().getLocalPart(), e.getValue().toString()); if (htd.hasFamily(hcd.getName())) { admin.modifyColumnFamily(name, hcd); } else {
@Override public void start() throws IOException { this.connection = ConnectionFactory.createConnection(hbaseConf); try(Admin admin = connection.getAdmin()) { if (!admin.tableExists(hbaseTableName)) { HTableDescriptor desc = new HTableDescriptor(hbaseTableName); desc.addFamily(new HColumnDescriptor(FAMILY).setMaxVersions(1)); admin.createTable(desc); } else { HTableDescriptor desc = admin.getTableDescriptor(hbaseTableName); if (!desc.hasFamily(FAMILY)) { throw new DrillRuntimeException("The HBase table " + hbaseTableName + " specified as persistent store exists but does not contain column family: " + (Bytes.toString(FAMILY))); } } } this.hbaseTable = connection.getTable(hbaseTableName); }
if (!tableDesc.hasFamily(colMap.familyNameBytes)) { throw new MetaException("Column Family " + colMap.familyName + " is not defined in hbase table " + tableName);
private void validateSnapshotRestore() throws IOException { try { UTIL.getAdmin().enableTable(snapshotTableName); HTableDescriptor currentHTD = UTIL.getAdmin().getTableDescriptor(snapshotTableName); assertTrue(currentHTD.hasFamily(CF1)); assertTrue(currentHTD.hasFamily(CF2)); assertFalse(currentHTD.hasFamily(CF3)); assertFalse(currentHTD.hasFamily(CF4)); assertEquals(currentHTD.getFamiliesKeys().size(), snapshotHTD.getFamiliesKeys().size()); SnapshotTestingUtils.verifyRowCount(UTIL, snapshotTableName, rowCountCF1 + rowCountCF2); } finally { UTIL.getAdmin().disableTable(snapshotTableName); } } }
/** * Add metadata, and verify that this only affects one table */ private void runTestSnapshotMetadataChangesIndependent() throws Exception { // Add a new column family to the original table byte[] TEST_FAM_2 = Bytes.toBytes("fam2"); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAM_2); admin.disableTable(originalTableName); admin.addColumnFamily(originalTableName, hcd); // Verify that it is not in the snapshot admin.enableTable(originalTableName); UTIL.waitTableAvailable(originalTableName); // get a description of the cloned table // get a list of its families // assert that the family is there HTableDescriptor originalTableDescriptor = originalTable.getTableDescriptor(); HTableDescriptor clonedTableDescriptor = admin.getTableDescriptor(cloneTableName); Assert.assertTrue("The original family was not found. There is something wrong. ", originalTableDescriptor.hasFamily(TEST_FAM)); Assert.assertTrue("The original family was not found in the clone. There is something wrong. ", clonedTableDescriptor.hasFamily(TEST_FAM)); Assert.assertTrue("The new family was not found. ", originalTableDescriptor.hasFamily(TEST_FAM_2)); Assert.assertTrue("The new family was not found. ", !clonedTableDescriptor.hasFamily(TEST_FAM_2)); }
try { t = conn.getTable(TableName.valueOf(tableName)); return t.getTableDescriptor().hasFamily(columnFamily); } finally { if (t != null) {
/** * Verify the presence of a column family in the schema path of the hbase table or whether the schema path is * the row key column. * * @param columns List of the selected columns * @param hTableDesc HTableDescriptor of HBase/MapR-DB_binary table (consists the details about that table) * @throws DrillRuntimeException if column family does not exist, or is not row_key column. */ public static void verifyColumns(List<SchemaPath> columns, HTableDescriptor hTableDesc) { if (Utilities.isStarQuery(columns)) { return; } for (SchemaPath column : columns) { if (!(column.equals(DrillHBaseConstants.ROW_KEY_PATH) || hTableDesc.hasFamily(HBaseUtils.getBytes(column.getRootSegment().getPath())))) { DrillRuntimeException.format("The column family '%s' does not exist in HBase table: %s .", column.getRootSegment().getPath(), hTableDesc.getNameAsString()); } } }
if (htd.hasFamily(hcd.getName())) { htd.modifyFamily(hcd); } else {
if (htd.hasFamily(hcd.getName())) { htd.modifyFamily(hcd); } else {
SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF1addition, CF1); HTableDescriptor currentHTD = admin.getTableDescriptor(snapshotTableName); assertTrue(currentHTD.hasFamily(CF1)); assertFalse(currentHTD.hasFamily(CF2)); assertTrue(currentHTD.hasFamily(CF3)); assertTrue(currentHTD.hasFamily(CF4)); assertNotEquals(currentHTD.getFamiliesKeys().size(), snapshotHTD.getFamiliesKeys().size()); SnapshotTestingUtils.verifyRowCount(
/** * Checks to see if table contains the given column family * @param columnFamily The column family name * @return boolean * @throws IOException */ private boolean columnFamilyExists(final String columnFamily) throws IOException { return this.table.getTableDescriptor().hasFamily(Bytes.toBytes(columnFamily)); }
if (!htd.hasFamily(family)) { htd.addFamily(new HColumnDescriptor(family));
/** * Adds the column family and set properties. * * @param tableDescriptor * the table descriptor * @param colFamilyName * the sec table */ private void addColumnFamilyAndSetProperties(HTableDescriptor tableDescriptor, String colFamilyName) { if (!tableDescriptor.hasFamily(colFamilyName.getBytes())) { HColumnDescriptor hColumnDescriptor = getColumnDescriptor(colFamilyName); tableDescriptor.addFamily(hColumnDescriptor); setExternalProperties(tableDescriptor.getNameAsString(), hColumnDescriptor); } }
/** * Assert schema. * * @throws IOException * Signals that an I/O exception has occurred. */ private void assertSchema() throws IOException { EntityManagerFactory emf = Persistence.createEntityManagerFactory(HBASE_PU, propertyMap); EntityManager em = emf.createEntityManager(); try { admin.getNamespaceDescriptor(SCHEMA); Assert.assertTrue(true); } catch (NamespaceNotFoundException e) { Assert.assertTrue(false); } Assert.assertTrue(admin.isTableAvailable(TABLE_1)); Assert.assertTrue(admin.isTableAvailable(TABLE_2)); HTableDescriptor descriptor = admin.getTableDescriptor(TableName.valueOf(TABLE_1)); Assert.assertTrue(descriptor.hasFamily("USER_HBASE".getBytes())); descriptor = admin.getTableDescriptor(TableName.valueOf(TABLE_2)); Assert.assertTrue(descriptor.hasFamily("PRODUCT_HBASE".getBytes())); em.close(); emf.close(); }
byte [] hasColumnFamily(final HTableDescriptor htd, final byte [] cf) throws InvalidFamilyOperationException { if (!htd.hasFamily(cf)) { throw new InvalidFamilyOperationException("Column family '" + Bytes.toString(cf) + "' does not exist"); } return cf; }
byte [] hasColumnFamily(final HTableDescriptor htd, final byte [] cf) throws InvalidFamilyOperationException { if (!htd.hasFamily(cf)) { throw new InvalidFamilyOperationException("Column family '" + Bytes.toString(cf) + "' does not exist"); } return cf; }