Search in sources :

Example 56 with ColumnFamilyDescriptorBuilder

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

the class HBaseTestingUtility method createTable.

/**
 * Create a table.
 * @param htd table descriptor
 * @param families array of column families
 * @param splitKeys array of split keys
 * @param type Bloom type
 * @param blockSize block size
 * @param c Configuration to use
 * @return A Table instance for the created table.
 * @throws IOException if getAdmin or createTable fails
 */
public Table createTable(TableDescriptor htd, byte[][] families, byte[][] splitKeys, BloomType type, int blockSize, Configuration c) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(htd);
    for (byte[] family : families) {
        ColumnFamilyDescriptorBuilder cfdb = ColumnFamilyDescriptorBuilder.newBuilder(family).setBloomFilterType(type).setBlocksize(blockSize);
        if (isNewVersionBehaviorEnabled()) {
            cfdb.setNewVersionBehavior(true);
        }
        builder.setColumnFamily(cfdb.build());
    }
    TableDescriptor td = builder.build();
    if (splitKeys != null) {
        getAdmin().createTable(td, splitKeys);
    } else {
        getAdmin().createTable(td);
    }
    // HBaseAdmin only waits for regions to appear in hbase:meta
    // we should wait until they are assigned
    waitUntilAllRegionsAssigned(td.getTableName());
    return getConnection().getTable(td.getTableName());
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Example 57 with ColumnFamilyDescriptorBuilder

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

the class HBaseTestingUtility method createPreSplitLoadTestTable.

/**
 * Creates a pre-split table for load testing. If the table already exists,
 * logs a warning and continues.
 * @return the number of regions the table was split into
 */
public static int createPreSplitLoadTestTable(Configuration conf, TableName tableName, byte[][] columnFamilies, Algorithm compression, DataBlockEncoding dataBlockEncoding, int numRegionsPerServer, int regionReplication, Durability durability) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    builder.setDurability(durability);
    builder.setRegionReplication(regionReplication);
    ColumnFamilyDescriptor[] hcds = new ColumnFamilyDescriptor[columnFamilies.length];
    for (int i = 0; i < columnFamilies.length; i++) {
        ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(columnFamilies[i]);
        cfBuilder.setDataBlockEncoding(dataBlockEncoding);
        cfBuilder.setCompressionType(compression);
        hcds[i] = cfBuilder.build();
    }
    return createPreSplitLoadTestTable(conf, builder.build(), hcds, numRegionsPerServer);
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)

Example 58 with ColumnFamilyDescriptorBuilder

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

the class HBaseTestingUtility method createTable.

/**
 * Create a table.
 * @return A Table instance for the created table.
 */
public Table createTable(TableName tableName, byte[][] families, int numVersions, byte[][] splitKeys) throws IOException {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    for (byte[] family : families) {
        ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(family).setMaxVersions(numVersions);
        if (isNewVersionBehaviorEnabled()) {
            cfBuilder.setNewVersionBehavior(true);
        }
        builder.setColumnFamily(cfBuilder.build());
    }
    if (splitKeys != null) {
        getAdmin().createTable(builder.build(), splitKeys);
    } else {
        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 59 with ColumnFamilyDescriptorBuilder

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

the class HBaseTestingUtility method createTableDescriptor.

public TableDescriptor createTableDescriptor(final TableName name, final int minVersions, final int versions, final int ttl, KeepDeletedCells keepDeleted) {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(name);
    for (byte[] cfName : new byte[][] { fam1, fam2, fam3 }) {
        ColumnFamilyDescriptorBuilder cfBuilder = ColumnFamilyDescriptorBuilder.newBuilder(cfName).setMinVersions(minVersions).setMaxVersions(versions).setKeepDeletedCells(keepDeleted).setBlockCacheEnabled(false).setTimeToLive(ttl);
        if (isNewVersionBehaviorEnabled()) {
            cfBuilder.setNewVersionBehavior(true);
        }
        builder.setColumnFamily(cfBuilder.build());
    }
    return builder.build();
}
Also used : ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder)

Example 60 with ColumnFamilyDescriptorBuilder

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

the class TestMaxResultsPerColumnFamily method testSetMaxResultsPerColumnFamilySimple.

@Test
public void testSetMaxResultsPerColumnFamilySimple() throws Exception {
    TableName tableName = TableName.valueOf(name.getMethodName());
    Admin admin = UTIL.getAdmin();
    ColumnFamilyDescriptorBuilder cfBuilder0 = ColumnFamilyDescriptorBuilder.newBuilder(FAMILIES[0]);
    TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(cfBuilder0.build()).build();
    admin.createTable(tableDescriptor);
    try (Table table = UTIL.getConnection().getTable(tableName)) {
        for (int i = 0; i < 30000; i++) {
            byte[] ROW = Bytes.toBytes("" + i);
            Put p = new Put(ROW);
            p.addColumn(FAMILIES[0], Bytes.toBytes("" + 1), VALUES[1]);
            p.addColumn(FAMILIES[0], Bytes.toBytes("" + 2), VALUES[0]);
            table.put(p);
        }
    }
    try (Table t = UTIL.getConnection().getTable(tableName)) {
        int expected = 30000;
        Scan limits = new Scan().setReadType(Scan.ReadType.PREAD);
        limits.setMaxResultsPerColumnFamily(1);
        int count1 = countScanRows(t, limits);
        assertEquals(expected, count1);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) ColumnFamilyDescriptorBuilder(org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder) Scan(org.apache.hadoop.hbase.client.Scan) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

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