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);
}
}
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);
}
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);
}
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));
}
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));
}
Aggregations