Search in sources :

Example 1 with IndexSchema

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

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

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

the class HBaseTable method insertTableIndex.

@Override
public void insertTableIndex(final IndexSchema indexSchema) {
    checkNotNull(indexSchema, "The index schema is invalid");
    final Collection<IndexSchema> indices = ImmutableList.of(indexSchema);
    final Scanner scanner = tableScan();
    while (scanner.hasNext()) {
        HBaseOperations.performPut(hTable, mutationFactory.insertIndices(tableId, Row.deserialize(scanner.next()), indices));
    }
    Util.closeQuietly(scanner);
}
Also used : Scanner(com.nearinfinity.honeycomb.Scanner) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema)

Example 4 with IndexSchema

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

the class HBaseMetadataTest method testCreateIndex.

@Test
public void testCreateIndex() {
    final TableSchema tableSchema = new TableSchema(COLUMN_SCHEMAS, ImmutableList.<IndexSchema>of());
    // Create a new table with the configured details
    hbaseMetadata.createTable(TABLE_NAME, tableSchema);
    final long tableId = hbaseMetadata.getTableId(TABLE_NAME);
    // Verify that the table schema has no indices after creation
    final TableSchema schemaBefore = hbaseMetadata.getSchema(tableId);
    assertNotNull(schemaBefore);
    assertTrue(schemaBefore.getIndices().isEmpty());
    // Add a new index to the table
    hbaseMetadata.createTableIndex(tableId, new IndexSchema(INDEX_NAME, ImmutableList.<String>of(COLUMN_NAME), false));
    // Verify that the table schema has been correctly updated
    final TableSchema schemaAfter = hbaseMetadata.getSchema(tableId);
    assertNotNull(schemaAfter);
    final Collection<IndexSchema> schemaIndices = schemaAfter.getIndices();
    assertEquals(1, schemaIndices.size());
    final IndexSchema newIndexDetails = Iterables.find(schemaIndices, indexPredicate);
    assertNotNull(newIndexDetails);
    final List<String> indexColumns = newIndexDetails.getColumns();
    assertEquals(1, indexColumns.size());
    assertEquals(COLUMN_NAME, indexColumns.get(0));
    assertEquals(false, newIndexDetails.getIsUnique());
    // Verify that the new index has been stored correctly
    final Map<String, Long> tableIndexInfo = hbaseMetadata.getIndexIds(tableId);
    assertEquals(1, tableIndexInfo.size());
    assertTrue(tableIndexInfo.containsKey(INDEX_NAME));
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Example 5 with IndexSchema

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

the class HBaseMetadataTest method testLookupIndexIdsValidTableId.

@Test
public void testLookupIndexIdsValidTableId() {
    final TableSchema tableSchema = new TableSchema(COLUMN_SCHEMAS, ImmutableList.of(new IndexSchema(INDEX_NAME, Lists.newArrayList(COLUMN_NAME), false)));
    hbaseMetadata.createTable(TABLE_NAME, tableSchema);
    final long tableId = hbaseMetadata.getTableId(TABLE_NAME);
    final Map<String, Long> tableIndices = hbaseMetadata.getIndexIds(tableId);
    assertEquals(1, tableIndices.size());
    assertTrue(tableIndices.containsKey(INDEX_NAME));
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) 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