@Test(expected = IllegalArgumentException.class) public void testDeserializeEmptySerializedSchema() { TableSchema.deserialize(new byte[0]); }
@Test(expected = NullPointerException.class) public void testDeserializeNullSerializedSchema() { TableSchema.deserialize(null); }
/** * Create a table with the given specifications. The table is not open when * this is called. * * @param tableName Name of the table * @param serializedTableSchema Serialized {@link AvroTableSchema} avro object * @param autoInc Initial auto increment value */ public void createTable(String tableName, byte[] serializedTableSchema, long autoInc) { Verify.isNotNullOrEmpty(tableName); checkNotNull(serializedTableSchema, "Schema cannot be null"); store = storeFactory.createStore(tableName); TableSchema tableSchema = TableSchema.deserialize(serializedTableSchema); Verify.isValidTableSchema(tableSchema); store.createTable(tableName, tableSchema); store.incrementAutoInc(tableName, autoInc); }
/** * Fetches the {@link TableSchema} for the table corresponding to the specified table identifier * * @param tableId The valid table identifier of the table this lookup is for * @return The table schema details for the table */ public TableSchema getSchema(final long tableId) { Verify.isValidId(tableId); final byte[] serializedTableId = serializeId(tableId); final Get get = new Get(new SchemaRowKey().encode()); get.addColumn(columnFamily, serializedTableId); final HTableInterface hTable = getHTable(); try { final Result result = HBaseOperations.performGet(hTable, get); final byte[] serializedSchema = result.getValue(columnFamily, serializedTableId); if (serializedSchema == null) { throw new TableNotFoundException(tableId); } checkNotNull(serializedSchema, "Schema cannot be null"); return TableSchema.deserialize(serializedSchema); } finally { HBaseOperations.closeTable(hTable); } }
@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); }