/** * Build put list for a row insert with indices * * @param tableId * @param row * @return The list of put mutations */ public List<Put> insert(long tableId, final Row row) { return insert(tableId, row, store.getSchema(tableId).getIndices()); }
/** * Build delete list for the indices belonging to the row * * @param tableId * @param row * @return The list of delete mutations */ public List<Delete> deleteIndices(long tableId, final Row row) { Verify.isValidId(tableId); final Collection<IndexSchema> indices = store.getSchema(tableId).getIndices(); return deleteIndices(tableId, row, indices); }
/** * Performs all metadata operations necessary to create a table * * @param tableName The name of the table to create, not null or empty * @param schema The schema details of the table to create, not null */ public void createTable(final String tableName, final TableSchema schema) { Verify.isNotNullOrEmpty(tableName); checkNotNull(schema); final List<Put> puts = Lists.newArrayList(); // Fetch the next table id to use for this table final long tableId = getNextTableId(); puts.add(putTableId(tableName, tableId)); puts.add(putColumnIds(tableId, schema.getColumns())); puts.add(putTableSchema(tableId, schema)); if (schema.hasIndices()) { puts.add(putIndices(tableId, schema.getIndices())); } performMutations(ImmutableList.<Delete>of(), puts); }
@Test public void testAddIndicesValidIndex() { final List<IndexSchema> indices = Lists.newArrayList(); final TableSchema schema = new TableSchema(COLUMNS, indices); assertEquals(0, schema.getIndices().size()); schema.addIndices(INDICES); assertEquals(INDICES.size(), schema.getIndices().size()); }
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()); }
@Test public void testDeserializeValidSerializedSchema() { final TableSchema actualSchema = TableSchema.deserialize(tableSchema.serialize()); assertEquals(COLUMNS.size(), tableSchema.getColumns().size()); assertEquals(INDICES.size(), tableSchema.getIndices().size()); assertEquals(tableSchema, actualSchema); }
public void updateRow(byte[] oldRowBytes, byte[] rowBytes) { checkTableOpen(); checkNotNull(rowBytes); Row updatedRow = Row.deserialize(rowBytes); TableSchema schema = store.getSchema(tableName); Row oldRow = Row.deserialize(oldRowBytes); oldRow.setUUID(updatedRow.getUUID()); ImmutableList<IndexSchema> changedIndices = Util.getChangedIndices(schema.getIndices(), oldRow.getRecords(), updatedRow.getRecords()); table.updateRow(oldRow, updatedRow, changedIndices); if (schema.hasUniqueIndices()) { table.flush(); } }