Search in sources :

Example 1 with TableSchema

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

the class MutationFactory method doToIndices.

private void doToIndices(long tableId, final Row row, final Collection<IndexSchema> indices, final IndexAction action) {
    for (IndexSchema index : indices) {
        long indexId = store.getIndexId(tableId, index.getIndexName());
        TableSchema schema = store.getSchema(tableId);
        IndexRowKeyBuilder builder = IndexRowKeyBuilder.newBuilder(tableId, indexId).withUUID(row.getUUID()).withRow(row, index.getIndexName(), schema);
        action.execute(builder);
    }
}
Also used : IndexRowKeyBuilder(com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKeyBuilder) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 2 with TableSchema

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

the class HBaseMetadata method createTableIndex.

/**
     * Performs all metadata operations necessary to create a table index
     *
     * @param tableId     The id of the table to create the index
     * @param indexSchema The {@link com.nearinfinity.honeycomb.mysql.schema.IndexSchema} representing the index details, not null
     */
public void createTableIndex(final long tableId, final IndexSchema indexSchema) {
    Verify.isValidId(tableId);
    checkNotNull(indexSchema, "The index schema is invalid");
    final List<Put> puts = Lists.newArrayList();
    final List<IndexSchema> indexDetailMap = ImmutableList.of(indexSchema);
    // Update the table schema to store the new index schema details
    final TableSchema existingSchema = getSchema(tableId);
    final TableSchema updatedSchema = existingSchema.schemaCopy();
    updatedSchema.addIndices(indexDetailMap);
    // Write the updated table schema and created index
    puts.add(putTableSchema(tableId, updatedSchema));
    puts.add(putIndices(tableId, indexDetailMap));
    performMutations(ImmutableList.<Delete>of(), puts);
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 3 with TableSchema

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

the class HBaseTable method ascendingIndexScanAfter.

@Override
public Scanner ascendingIndexScanAfter(QueryKey key) {
    final TableSchema schema = store.getSchema(tableId);
    long indexId = store.getIndexId(tableId, key.getIndexName());
    IndexRowKey startRow = IndexRowKeyBuilder.newBuilder(tableId, indexId).withQueryKey(key, schema).withSortOrder(SortOrder.Ascending).build();
    IndexRowKey endRow = IndexRowKeyBuilder.newBuilder(tableId, indexId + 1).withSortOrder(SortOrder.Ascending).build();
    return createScannerForRange(incrementRowKey(startRow.encode()), endRow.encode());
}
Also used : IndexRowKey(com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKey) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema)

Example 4 with TableSchema

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

the class HBaseTable method descendingIndexScanBefore.

@Override
public Scanner descendingIndexScanBefore(QueryKey key) {
    final TableSchema schema = store.getSchema(tableId);
    long indexId = store.getIndexId(tableId, key.getIndexName());
    IndexRowKey startRow = IndexRowKeyBuilder.newBuilder(tableId, indexId).withQueryKey(key, schema).withSortOrder(SortOrder.Descending).build();
    IndexRowKey endRow = IndexRowKeyBuilder.newBuilder(tableId, indexId + 1).withSortOrder(SortOrder.Descending).build();
    return createScannerForRange(incrementRowKey(startRow.encode()), endRow.encode());
}
Also used : IndexRowKey(com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKey) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema)

Example 5 with TableSchema

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

the class HBaseMetadataPropertyTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    provider = mock(HTableProvider.class);
    when(provider.get()).thenReturn(table);
    hbaseMetadata = new HBaseMetadata(provider);
    hbaseMetadata.setColumnFamily("nic");
    for (int i = 0; i < 20; i++) {
        TableSchema schema = tableSchemaGen.next();
        final String tableName = TableSchemaGenerator.MYSQL_NAME_GEN.next();
        tableSchemas.put(tableName, schema);
        hbaseMetadata.createTable(tableName, schema);
    }
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) BeforeClass(org.junit.BeforeClass)

Aggregations

TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)34 Test (org.junit.Test)17 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)12 ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)9 IndexRowKey (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKey)5 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)5 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 MockHTable (com.nearinfinity.honeycomb.MockHTable)1 Scanner (com.nearinfinity.honeycomb.Scanner)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 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1