/** * Add an index schema to the table schema * * @param indices New index schemas [Not null] */ public void addIndices(Collection<IndexSchema> indices) { checkNotNull(indices); for (IndexSchema entry : indices) { this.indices.add(entry); avroTableSchema.getIndices().put(entry.getIndexName(), entry.getAvroValue()); if (entry.getIsUnique()) { uniqueIndexCount++; } } }
private Put putIndices(long tableId, Collection<IndexSchema> indices) { checkState(!indices.isEmpty(), "putIndices requires 1 or more indices."); long indexId = getNextIndexId(tableId, indices.size()); Put put = new Put(new IndicesRowKey(tableId).encode()); for (IndexSchema columnEntry : indices) { put.add(columnFamily, serializeName(columnEntry.getIndexName()), serializeId(indexId--)); } return put; }
/** * Construct a table schema from a map of column schemas and index schemas. * * @param columns Column schemas map [Not null] * @param indices Index schema map [Not null] */ public TableSchema(Collection<ColumnSchema> columns, Collection<IndexSchema> indices) { checkArgument(columns.size() > 0, "Table must have at least one column."); checkNotNull(indices); Map<String, AvroColumnSchema> columnSchemaMap = Maps.newHashMap(); for (ColumnSchema columnSchema : columns) { columnSchemaMap.put(columnSchema.getColumnName(), columnSchema.getAvroValue()); } Map<String, AvroIndexSchema> indexSchemaMap = Maps.newHashMap(); for (IndexSchema indexSchema : indices) { indexSchemaMap.put(indexSchema.getIndexName(), indexSchema.getAvroValue()); if (indexSchema.getIsUnique()) { uniqueIndexCount++; } } avroTableSchema = AvroTableSchema.newBuilder() .setColumns(columnSchemaMap) .setIndices(indexSchemaMap) .build(); this.columns = new LinkedList<ColumnSchema>(columns); this.indices = new LinkedList<IndexSchema>(indices); }
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); } }
@Test public void testDeserializeValidSerializedSchemaAndIndexName() { final IndexSchema actualSchema = IndexSchema.deserialize(TEST_INDEX_SCHEMA.serialize(), TEST_INDEX_SCHEMA.getIndexName()); assertEquals(TEST_INDEX_SCHEMA.getIndexName(), actualSchema.getIndexName()); assertEquals(TEST_INDEX_SCHEMA, actualSchema); }
public QueryKeyGenerator(TableSchema schema) { super(); this.rows = new RowGenerator(schema); ImmutableList.Builder<String> indices = ImmutableList.builder(); for (IndexSchema indexSchema : schema.getIndices()) { indices.add(indexSchema.getIndexName()); } this.indices = PrimitiveGenerators.fixedValues(indices.build()); }
@Test public void testRemoveIndexValidIndexName() { final TableSchema schema = new TableSchema(COLUMNS, INDICES); assertEquals(INDICES.size(), schema.getIndices().size()); // Remove all of the indexes from the schema for(final IndexSchema indexSchema : INDICES ) { schema.removeIndex(indexSchema.getIndexName()); } assertEquals(0, schema.getIndices().size()); }
@Override public void deleteTableIndex(final IndexSchema indexSchema) { checkNotNull(indexSchema, "The index schema is invalid"); long indexId = store.getIndexId(tableId, indexSchema.getIndexName()); deleteRowsInRange( IndexRowKeyBuilder.newBuilder(tableId, indexId).withSortOrder(SortOrder.Ascending).build().encode(), IndexRowKeyBuilder.newBuilder(tableId, indexId + 1).withSortOrder(SortOrder.Ascending).build().encode()); deleteRowsInRange( IndexRowKeyBuilder.newBuilder(tableId, indexId).withSortOrder(SortOrder.Descending).build().encode(), IndexRowKeyBuilder.newBuilder(tableId, indexId + 1).withSortOrder(SortOrder.Descending).build().encode()); }