Search in sources :

Example 21 with BufferedMutator

use of org.apache.hadoop.hbase.client.BufferedMutator in project drill by apache.

the class TestTableGenerator method generateHBaseDatasetCompositeKeyDate.

public static void generateHBaseDatasetCompositeKeyDate(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
    if (admin.tableExists(tableName)) {
        admin.disableTable(tableName);
        admin.deleteTable(tableName);
    }
    HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILY_F));
    if (numberRegions > 1) {
        admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions - 1));
    } else {
        admin.createTable(desc);
    }
    BufferedMutator table = conn.getBufferedMutator(tableName);
    Date startDate = new Date(1408924800000L);
    long startTime = startDate.getTime();
    long MILLISECONDS_IN_A_DAY = (long) 1000 * 60 * 60 * 24;
    long MILLISECONDS_IN_A_YEAR = MILLISECONDS_IN_A_DAY * 365;
    long endTime = startTime + MILLISECONDS_IN_A_YEAR;
    long interval = MILLISECONDS_IN_A_DAY / 3;
    for (long ts = startTime, counter = 0; ts < endTime; ts += interval, counter++) {
        byte[] rowKey = ByteBuffer.allocate(16).putLong(ts).array();
        for (int i = 0; i < 8; ++i) {
            rowKey[8 + i] = (byte) (counter >> (56 - (i * 8)));
        }
        Put p = new Put(rowKey);
        p.addColumn(FAMILY_F, COLUMN_C, "dummy".getBytes());
        table.mutate(p);
    }
    table.close();
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) Date(java.util.Date) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 22 with BufferedMutator

use of org.apache.hadoop.hbase.client.BufferedMutator in project drill by apache.

the class TestTableGenerator method generateHBaseDatasetIntOB.

public static void generateHBaseDatasetIntOB(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
    if (admin.tableExists(tableName)) {
        admin.disableTable(tableName);
        admin.deleteTable(tableName);
    }
    HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILY_F));
    if (numberRegions > 1) {
        admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions - 1));
    } else {
        admin.createTable(desc);
    }
    BufferedMutator table = conn.getBufferedMutator(tableName);
    for (int i = -49; i <= 100; i++) {
        byte[] bytes = new byte[5];
        PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 5);
        OrderedBytes.encodeInt32(br, i, Order.ASCENDING);
        Put p = new Put(bytes);
        p.addColumn(FAMILY_F, COLUMN_C, String.format("value %d", i).getBytes());
        table.mutate(p);
    }
    table.close();
    admin.flush(tableName);
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 23 with BufferedMutator

use of org.apache.hadoop.hbase.client.BufferedMutator in project drill by apache.

the class TestTableGenerator method generateHBaseDatasetDoubleOBDesc.

public static void generateHBaseDatasetDoubleOBDesc(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
    if (admin.tableExists(tableName)) {
        admin.disableTable(tableName);
        admin.deleteTable(tableName);
    }
    HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILY_F));
    if (numberRegions > 1) {
        admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions - 1));
    } else {
        admin.createTable(desc);
    }
    BufferedMutator table = conn.getBufferedMutator(tableName);
    for (double i = 0.5; i <= 100.00; i += 0.75) {
        byte[] bytes = new byte[9];
        PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 9);
        OrderedBytes.encodeFloat64(br, i, Order.DESCENDING);
        Put p = new Put(bytes);
        p.addColumn(FAMILY_F, COLUMN_C, String.format("value %03f", i).getBytes());
        table.mutate(p);
    }
    table.close();
    admin.flush(tableName);
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 24 with BufferedMutator

use of org.apache.hadoop.hbase.client.BufferedMutator in project drill by apache.

the class TestTableGenerator method generateHBaseDatasetCompositeKeyTime.

public static void generateHBaseDatasetCompositeKeyTime(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
    if (admin.tableExists(tableName)) {
        admin.disableTable(tableName);
        admin.deleteTable(tableName);
    }
    HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILY_F));
    if (numberRegions > 1) {
        admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions - 1));
    } else {
        admin.createTable(desc);
    }
    BufferedMutator table = conn.getBufferedMutator(tableName);
    long startTime = 0;
    long MILLISECONDS_IN_A_SEC = (long) 1000;
    long MILLISECONDS_IN_A_DAY = MILLISECONDS_IN_A_SEC * 60 * 60 * 24;
    long endTime = startTime + MILLISECONDS_IN_A_DAY;
    long smallInterval = 25;
    long largeInterval = MILLISECONDS_IN_A_SEC * 42;
    long interval = smallInterval;
    for (long ts = startTime, counter = 0; ts < endTime; ts += interval, counter++) {
        byte[] rowKey = ByteBuffer.allocate(16).putLong(ts).array();
        for (int i = 0; i < 8; ++i) {
            rowKey[8 + i] = (byte) (counter >> (56 - (i * 8)));
        }
        Put p = new Put(rowKey);
        p.addColumn(FAMILY_F, COLUMN_C, "dummy".getBytes());
        table.mutate(p);
        if (interval == smallInterval) {
            interval = largeInterval;
        } else {
            interval = smallInterval;
        }
    }
    table.close();
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 25 with BufferedMutator

use of org.apache.hadoop.hbase.client.BufferedMutator in project drill by apache.

the class TestTableGenerator method generateHBaseDatasetFloatOB.

public static void generateHBaseDatasetFloatOB(Connection conn, Admin admin, TableName tableName, int numberRegions) throws Exception {
    if (admin.tableExists(tableName)) {
        admin.disableTable(tableName);
        admin.deleteTable(tableName);
    }
    HTableDescriptor desc = new HTableDescriptor(tableName);
    desc.addFamily(new HColumnDescriptor(FAMILY_F));
    if (numberRegions > 1) {
        admin.createTable(desc, Arrays.copyOfRange(SPLIT_KEYS, 0, numberRegions - 1));
    } else {
        admin.createTable(desc);
    }
    BufferedMutator table = conn.getBufferedMutator(tableName);
    for (float i = (float) 0.5; i <= 100.00; i += 0.75) {
        byte[] bytes = new byte[5];
        PositionedByteRange br = new SimplePositionedMutableByteRange(bytes, 0, 5);
        OrderedBytes.encodeFloat32(br, i, Order.ASCENDING);
        Put p = new Put(bytes);
        p.addColumn(FAMILY_F, COLUMN_C, String.format("value %03f", i).getBytes());
        table.mutate(p);
    }
    table.close();
    admin.flush(tableName);
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) SimplePositionedMutableByteRange(org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange) PositionedByteRange(org.apache.hadoop.hbase.util.PositionedByteRange) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Aggregations

BufferedMutator (org.apache.hadoop.hbase.client.BufferedMutator)25 Put (org.apache.hadoop.hbase.client.Put)19 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)16 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)16 PositionedByteRange (org.apache.hadoop.hbase.util.PositionedByteRange)8 SimplePositionedMutableByteRange (org.apache.hadoop.hbase.util.SimplePositionedMutableByteRange)8 TableName (org.apache.hadoop.hbase.TableName)3 Connection (org.apache.hadoop.hbase.client.Connection)3 Table (org.apache.hadoop.hbase.client.Table)3 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 Mutation (org.apache.hadoop.hbase.client.Mutation)2 IOException (java.io.IOException)1 Key (java.security.Key)1 SecureRandom (java.security.SecureRandom)1 Date (java.util.Date)1 Iterator (java.util.Iterator)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1