Search in sources :

Example 1 with RowKey

use of com.nearinfinity.honeycomb.hbase.rowkey.RowKey in project honeycomb by altamiracorp.

the class RowKeyTest method testRowKeyEncSort.

@Test
public void testRowKeyEncSort() {
    List<RowKey> rowKeys = new ArrayList<RowKey>();
    List<byte[]> encodedRowKeys = new ArrayList<byte[]>();
    for (RowKey rowKey : Iterables.toIterable(rowKeyGen)) {
        rowKeys.add(rowKey);
        encodedRowKeys.add(rowKey.encode());
    }
    Collections.sort(rowKeys);
    Collections.sort(encodedRowKeys, UnsignedBytes.lexicographicalComparator());
    for (int i = 0; i < rowKeys.size(); i++) {
        RowKey rowKey = rowKeys.get(i);
        byte[] encodedRowKey = encodedRowKeys.get(i);
        Assert.assertArrayEquals(encodedRowKey, rowKey.encode());
    }
}
Also used : RowKey(com.nearinfinity.honeycomb.hbase.rowkey.RowKey) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with RowKey

use of com.nearinfinity.honeycomb.hbase.rowkey.RowKey in project honeycomb by altamiracorp.

the class RowKeyTest method testIndexRowKeyStrings.

@Test
public void testIndexRowKeyStrings() {
    String columnName = "c1";
    String indexName = "i1";
    ColumnSchema columnSchema = ColumnSchema.builder("default", ColumnType.DATETIME).build();
    IndexSchema indexSchema = new IndexSchema(indexName, ImmutableList.of(columnName), false);
    TableSchema tableSchema = new TableSchema(ImmutableList.of(columnSchema), ImmutableList.of(indexSchema));
    Generator<RowKey> rowkeysGen = RowKeyGenerator.getAscIndexRowKeyGenerator(tableSchema);
    List<RowKey> rowkeys = Lists.newArrayList(Iterables.toIterable(rowkeysGen));
    Collections.sort(rowkeys);
    List<byte[]> encodedRowkeys = Lists.newArrayList();
    for (RowKey rowkey : rowkeys) {
        encodedRowkeys.add(rowkey.encode());
    }
    Collections.sort(encodedRowkeys, new Bytes.ByteArrayComparator());
    for (int i = 0; i < rowkeys.size(); i++) {
        RowKey rowKey = rowkeys.get(i);
        byte[] encodedRowKey = encodedRowkeys.get(i);
        Assert.assertArrayEquals(encodedRowKey, rowKey.encode());
    }
}
Also used : UnsignedBytes(com.google.common.primitives.UnsignedBytes) Bytes(org.apache.hadoop.hbase.util.Bytes) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) RowKey(com.nearinfinity.honeycomb.hbase.rowkey.RowKey) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Aggregations

RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)2 Test (org.junit.Test)2 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)1 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)1 TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)1 ArrayList (java.util.ArrayList)1 Bytes (org.apache.hadoop.hbase.util.Bytes)1