/** * Hashes an Avro schema. * * @param schema Avro schema to hash. * @return the schema hash. */ public BytesKey getHash(Schema schema) { final BytesKey hash = mCache.get(schema); if (null != hash) { return hash; } final BytesKey newHash = new BytesKey(hashSchema(schema)); mCache.put(schema, newHash); return newHash; } }
/** {@inheritDoc} */ @Override public Schema decode(ByteStreamArray bstream) throws IOException { final BytesKey schemaHash = new BytesKey(bstream.readBytes(Hasher.HASH_SIZE_BYTES)); final Schema schema = mSchemaTable.getSchema(schemaHash); if (null == schema) { throw new IOException( String.format("Schema with hash %s not found in schema table.", schemaHash)); } return schema; } }
/** * Converts an Avro SchemaTableEntry into a SchemaEntry. * * @param avroEntry Avro SchemaTableEntry * @return an equivalent SchemaEntry */ public static SchemaEntry fromAvroEntry(final SchemaTableEntry avroEntry) { final String schemaJson = avroEntry.getAvroSchema(); final Schema schema = new Schema.Parser().parse(schemaJson); return new SchemaEntry(avroEntry.getId(), new BytesKey(avroEntry.getHash().bytes()), schema); }
/** * Converts an Avro SchemaTableEntry into a SchemaEntry. * * @param avroEntry Avro SchemaTableEntry * @return an equivalent SchemaEntry */ public static SchemaEntry fromAvroEntry(final SchemaTableEntry avroEntry) { final String schemaJson = avroEntry.getAvroSchema(); final Schema schema = new Schema.Parser().parse(schemaJson); return new SchemaEntry(avroEntry.getId(), new BytesKey(avroEntry.getHash().bytes()), schema); }
LOG.error(String.format( "Invalid schema hash table row key size: %s, expecting %d bytes.", new BytesKey(result.getRow()), Hasher.HASH_SIZE_BYTES)); continue; final BytesKey rowKey = new BytesKey(result.getRow()); for (KeyValue keyValue : result.getColumn(SCHEMA_COLUMN_FAMILY_BYTES, SCHEMA_COLUMN_QUALIFIER_BYTES)) {
final BytesKey rowKey = new BytesKey(result.getRow());
final BytesKey bytesKey = new BytesKey(ByteArrayFormatter.parseHex(mGetByHashFlag, ':')); final SchemaEntry sEntry = table.getSchemaEntry(bytesKey); final Schema schema = sEntry.getSchema();
final BytesKey rowKey = new BytesKey( ByteUtils.toBytes(row.getBytesUnsafe(SCHEMA_COLUMN_ID_KEY)));
final BytesKey rowKey = new BytesKey(ByteUtils.toBytes(hashKey)); final long timestamp = row.getDate(SCHEMA_COLUMN_TIME).getTime(); final byte[] schemaAsBytes = ByteUtils.toBytes(row.getBytes(SCHEMA_COLUMN_VALUE));