public void deleteRow(byte[] rowBytes) { checkTableOpen(); Row row = Row.deserialize(rowBytes); table.deleteRow(row); }
public static byte[] updateSerializedSchema(byte[] row) { byte version = row[0]; if (isMostRecentVersion(version)) { return row; } // Bring the row up to most recent version return Row.deserialize(row).serialize(); }
@Override public Row getRow(UUID uuid) { DataRowKey dataRow = new DataRowKey(tableId, uuid); Get get = new Get(dataRow.encode()); Result result = HBaseOperations.performGet(hTable, get); if (result.isEmpty()) { throw new RowNotFoundException(uuid); } return Row.deserialize(result.getValue(columnFamily.getBytes(), new byte[0])); }
@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); }
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(); } }
/** * Insert row into table. * * @param rowBytes Serialized row to be written */ public void insertRow(byte[] rowBytes) { checkTableOpen(); checkNotNull(rowBytes); TableSchema schema = store.getSchema(tableName); Row row = Row.deserialize(rowBytes); row.setRandomUUID(); String auto_inc_col = schema.getAutoIncrementColumn(); if (auto_inc_col != null) { ByteBuffer bb = row.getRecords().get(auto_inc_col); if (bb != null) { long auto_inc = bb.getLong(); long next_auto_inc = auto_inc + 1; if (auto_inc > next_auto_inc) { // The autoincrement will wrap around. MySQL says don't wrap. next_auto_inc = auto_inc; } bb.rewind(); store.setAutoInc(tableName, next_auto_inc); } } table.insertRow(row); if (schema.hasUniqueIndices()) { table.flush(); } }
checkNotNull(serializedRow); Row row = Row.deserialize(serializedRow); Row next = Row.deserialize(scanner.next()); if (!next.getUUID().equals(row.getUUID())) {
/** * Test that row serialization and deserialization is isomorphic in the * serialization direction. * * @throws Exception */ @Test public void testSerDe() throws Exception { TableSchema schema = new TableSchemaGenerator().next(); for (Row row : Iterables.toIterable(new RowGenerator(schema))) { Assert.assertEquals(row, Row.deserialize(row.serialize())); } } }