Search in sources :

Example 11 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.

the class TestDeleteMobTable method createTableDescriptor.

private TableDescriptor createTableDescriptor(TableName tableName, boolean hasMob) {
    ColumnFamilyDescriptorBuilder builder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILY);
    if (hasMob) {
        builder.setMobEnabled(true);
        builder.setMobThreshold(0);
    }
    return TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(builder.build()).build();
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)

Example 12 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.

the class TestThriftConnection method createTable.

private TableDescriptor createTable(Admin admin, String tableName) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName));
    ColumnFamilyDescriptorBuilder familyABuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYA);
    familyABuilder.setMaxVersions(3);
    ColumnFamilyDescriptorBuilder familyBBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYB);
    familyBBuilder.setMaxVersions(3);
    ColumnFamilyDescriptorBuilder familyCBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYC);
    familyCBuilder.setMaxVersions(3);
    builder.setColumnFamily(familyABuilder.build());
    builder.setColumnFamily(familyBBuilder.build());
    builder.setColumnFamily(familyCBuilder.build());
    TableDescriptor tableDescriptor = builder.build();
    admin.createTable(tableDescriptor);
    try (Table table = TEST_UTIL.getConnection().getTable(TableName.valueOf(tableName))) {
        Put put = new Put(ROW_1);
        put.addColumn(FAMILYA, QUALIFIER_1, TS_2, VALUE_1);
        table.put(put);
        put = new Put(ROW_2);
        put.addColumn(FAMILYA, QUALIFIER_1, TS_1, VALUE_1);
        put.addColumn(FAMILYA, QUALIFIER_1, TS_2, VALUE_2);
        put.addColumn(FAMILYB, QUALIFIER_2, TS_2, VALUE_2);
        table.put(put);
    }
    return tableDescriptor;
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Put(org.apache.hadoop.hbase.client.Put)

Example 13 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.

the class TestThriftConnection method testThriftAdmin.

private void testThriftAdmin(Connection connection, String namespace, String table) throws Exception {
    try (Admin admin = connection.getAdmin()) {
        // create name space
        NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create(namespace).build();
        namespaceDescriptor.setConfiguration("key1", "value1");
        namespaceDescriptor.setConfiguration("key2", "value2");
        admin.createNamespace(namespaceDescriptor);
        // list namespace
        NamespaceDescriptor[] namespaceDescriptors = admin.listNamespaceDescriptors();
        boolean found = false;
        for (NamespaceDescriptor nd : namespaceDescriptors) {
            if (nd.getName().equals(namespace)) {
                found = true;
                break;
            }
        }
        assertTrue(found);
        // modify namesapce
        namespaceDescriptor.setConfiguration("kye3", "value3");
        admin.modifyNamespace(namespaceDescriptor);
        // get namespace
        NamespaceDescriptor namespaceDescriptorReturned = admin.getNamespaceDescriptor(namespace);
        assertTrue(namespaceDescriptorReturned.getConfiguration().size() == 3);
        // create table
        TableDescriptor tableDescriptor = createTable(admin, table);
        // modify table
        TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableDescriptor);
        builder.setDurability(Durability.ASYNC_WAL);
        admin.modifyTable(builder.build());
        // modify column family
        ColumnFamilyDescriptor familyA = tableDescriptor.getColumnFamily(FAMILYA);
        ColumnFamilyDescriptorBuilder familyABuilder = ColumnFamilyDescriptorBuilder.newBuilder(familyA);
        familyABuilder.setInMemory(true);
        admin.modifyColumnFamily(tableDescriptor.getTableName(), familyABuilder.build());
        // add column family
        ColumnFamilyDescriptorBuilder familyDBuilder = ColumnFamilyDescriptorBuilder.newBuilder(FAMILYD);
        familyDBuilder.setDataBlockEncoding(DataBlockEncoding.PREFIX);
        admin.addColumnFamily(tableDescriptor.getTableName(), familyDBuilder.build());
        // get table descriptor
        TableDescriptor tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
        assertTrue(tableDescriptorReturned.getColumnFamilies().length == 4);
        assertTrue(tableDescriptorReturned.getDurability() == Durability.ASYNC_WAL);
        ColumnFamilyDescriptor columnFamilyADescriptor1Returned = tableDescriptorReturned.getColumnFamily(FAMILYA);
        assertTrue(columnFamilyADescriptor1Returned.isInMemory() == true);
        // delete column family
        admin.deleteColumnFamily(tableDescriptor.getTableName(), FAMILYA);
        tableDescriptorReturned = admin.getDescriptor(tableDescriptor.getTableName());
        assertTrue(tableDescriptorReturned.getColumnFamilies().length == 3);
        // disable table
        admin.disableTable(tableDescriptor.getTableName());
        assertTrue(admin.isTableDisabled(tableDescriptor.getTableName()));
        // enable table
        admin.enableTable(tableDescriptor.getTableName());
        assertTrue(admin.isTableEnabled(tableDescriptor.getTableName()));
        assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
        // truncate table
        admin.disableTable(tableDescriptor.getTableName());
        admin.truncateTable(tableDescriptor.getTableName(), true);
        assertTrue(admin.isTableAvailable(tableDescriptor.getTableName()));
        // delete table
        admin.disableTable(tableDescriptor.getTableName());
        admin.deleteTable(tableDescriptor.getTableName());
        assertFalse(admin.tableExists(tableDescriptor.getTableName()));
        // delete namespace
        admin.deleteNamespace(namespace);
        namespaceDescriptors = admin.listNamespaceDescriptors();
        // should have 2 namespace, default and hbase
        found = false;
        for (NamespaceDescriptor nd : namespaceDescriptors) {
            if (nd.getName().equals(namespace)) {
                found = true;
                break;
            }
        }
        assertTrue(found == false);
    }
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 14 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.

the class HBaseTestingUtil method createTable.

public Table createTable(TableName tableName, byte[][] families, int numVersions, int blockSize, String cpName) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    for (byte[] family : families) {
        ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family).setMaxVersions(numVersions).setBlocksize(blockSize);
        if (isNewVersionBehaviorEnabled()) {
            cfBuilder.setNewVersionBehavior(true);
        }
        builder.setColumnFamily(cfBuilder.build());
    }
    if (cpName != null) {
        builder.setCoprocessor(cpName);
    }
    getAdmin().createTable(builder.build());
    // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
    // assigned
    waitUntilAllRegionsAssigned(tableName);
    return getConnection().getTable(tableName);
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Example 15 with ColumnFamilyDescriptorBuilder

use of org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder in project hbase by apache.

the class HBaseTestingUtil method createTable.

/**
 * Create a table.
 * @return A Table instance for the created table.
 */
public Table createTable(TableName tableName, byte[][] families, int[] numVersions) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    int i = 0;
    for (byte[] family : families) {
        ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family).setMaxVersions(numVersions[i]);
        if (isNewVersionBehaviorEnabled()) {
            cfBuilder.setNewVersionBehavior(true);
        }
        builder.setColumnFamily(cfBuilder.build());
        i++;
    }
    getAdmin().createTable(builder.build());
    // HBaseAdmin only waits for regions to appear in hbase:meta we should wait until they are
    // assigned
    waitUntilAllRegionsAssigned(tableName);
    return getConnection().getTable(tableName);
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Aggregations

ColumnFamilyDescriptorBuilder (org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder)61 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)43 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)19 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)16 Test (org.junit.Test)9 Table (org.apache.hadoop.hbase.client.Table)7 Admin (org.apache.hadoop.hbase.client.Admin)6 Put (org.apache.hadoop.hbase.client.Put)6 IOException (java.io.IOException)5 Configuration (org.apache.hadoop.conf.Configuration)5 Path (org.apache.hadoop.fs.Path)5 TableName (org.apache.hadoop.hbase.TableName)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 QName (javax.xml.namespace.QName)3 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)3 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 FileStatus (org.apache.hadoop.fs.FileStatus)2 FileSystem (org.apache.hadoop.fs.FileSystem)2