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