Search in sources :

Example 16 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema 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)

Example 17 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.

the class HandlerProxy method dropIndex.

/**
     * Drop the index specified by the index name from the table. The table must be open
     * before this operation can be performed.
     *
     * @param indexName The name of the index to add, not null or empty
     */
public void dropIndex(String indexName) {
    Verify.isNotNullOrEmpty(indexName, "The index name is invalid");
    checkTableOpen();
    TableSchema tableSchema = store.getSchema(tableName);
    IndexSchema indexSchema = tableSchema.getIndexSchema(indexName);
    table.deleteTableIndex(indexSchema);
    store.dropIndex(tableName, indexName);
}
Also used : AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 18 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.

the class HandlerProxy method indexContainsDuplicate.

/**
     * Check whether the index contains a row with the same field values and a
     * distinct UUID.
     *
     * @param indexName
     * @param serializedRow
     * @return True If a duplicate is found, False otherwise
     */
public boolean indexContainsDuplicate(String indexName, byte[] serializedRow) {
    // This method must get its own table because it may be called during
    // a full table scan.
    Verify.isNotNullOrEmpty(indexName);
    checkNotNull(serializedRow);
    Row row = Row.deserialize(serializedRow);
    Table t = store.openTable(tableName);
    TableSchema schema = store.getSchema(tableName);
    IndexSchema indexSchema = schema.getIndexSchema(indexName);
    QueryKey key = new QueryKey(indexName, QueryType.EXACT_KEY, row.getRecords());
    Scanner scanner = t.indexScanExact(key);
    try {
        while (scanner.hasNext()) {
            Row next = Row.deserialize(scanner.next());
            if (!next.getUUID().equals(row.getUUID())) {
                // Special case for inserting nulls
                for (String column : indexSchema.getColumns()) {
                    boolean isNullInRecord = !row.getRecords().containsKey(column);
                    if (isNullInRecord) {
                        return false;
                    }
                }
                return true;
            }
        }
        return false;
    } finally {
        Util.closeQuietly(scanner);
        Util.closeQuietly(t);
    }
}
Also used : Scanner(com.nearinfinity.honeycomb.Scanner) Table(com.nearinfinity.honeycomb.Table) AvroTableSchema(com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 19 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.

the class IndexOperationsIT method testAddIndex.

@Test
public void testAddIndex() {
    final IndexSchema indexSchema = new IndexSchema(NEW_INDEX_NAME, Lists.newArrayList(TestConstants.COLUMN1), false);
    // Add data rows to index
    ITUtils.insertData(proxy, ROW_COUNT, INDEX_COL_VALUE);
    // Add the new index to the table
    proxy.addIndex(NEW_INDEX_NAME, indexSchema.serialize());
    // Perform a scan with the new index
    final QueryKey key = new QueryKey(NEW_INDEX_NAME, QueryType.EXACT_KEY, ImmutableMap.<String, ByteBuffer>of(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE)));
    ITUtils.assertReceivingDifferentRows(proxy, key, ROW_COUNT);
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 20 with IndexSchema

use of com.nearinfinity.honeycomb.mysql.schema.IndexSchema in project honeycomb by altamiracorp.

the class IndexOperationsIT method testAddCompoundIndex.

@Test
public void testAddCompoundIndex() {
    // Create the compound index ordered as (col2, col1)
    final IndexSchema indexSchema = new IndexSchema(NEW_INDEX_NAME, Lists.newArrayList(TestConstants.COLUMN2, TestConstants.COLUMN1), false);
    final int column2Value = 0;
    // Add data rows to index
    ITUtils.insertData(proxy, ROW_COUNT, INDEX_COL_VALUE);
    // Add the new index to the table
    proxy.addIndex(NEW_INDEX_NAME, indexSchema.serialize());
    // Perform a scan with the new index
    final QueryKey key = new QueryKey(NEW_INDEX_NAME, QueryType.EXACT_KEY, ImmutableMap.<String, ByteBuffer>of(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE), TestConstants.COLUMN2, ITUtils.encodeValue(column2Value)));
    ITUtils.assertReceivingDifferentRows(proxy, key, ROW_COUNT);
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Aggregations

IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)22 TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)12 Test (org.junit.Test)10 ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)5 QueryKey (com.nearinfinity.honeycomb.mysql.QueryKey)3 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)3 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)3 Scanner (com.nearinfinity.honeycomb.Scanner)2 ByteBuffer (java.nio.ByteBuffer)2 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 Table (com.nearinfinity.honeycomb.Table)1 IndexRowKeyBuilder (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKeyBuilder)1 RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)1 HandlerProxy (com.nearinfinity.honeycomb.mysql.HandlerProxy)1 Row (com.nearinfinity.honeycomb.mysql.Row)1 ArrayList (java.util.ArrayList)1 Bytes (org.apache.hadoop.hbase.util.Bytes)1