/** * Fetches a schema entry from the tables given a schema hash. * * @param schemaHash schema hash * @return Avro schema entry, or null if the schema hash does not exist in the table * @throws IOException on I/O error. */ private SchemaTableEntry loadFromHashTable(BytesKey schemaHash) throws IOException { final Get get = new Get(schemaHash.getBytes()); final Result result = mSchemaHashTable.get(get); return result.isEmpty() ? null : decodeSchemaEntry(result.value()); }
/** {@inheritDoc} */ @Override public void encode(final Schema writerSchema) throws IOException { final BytesKey schemaHash = mCellSpec.getSchemaTable().getOrCreateSchemaHash(writerSchema); mByteArrayEncoder.writeFixed(schemaHash.getBytes()); } }
/** * Fetches a schema entry from the tables given a schema hash. * * @param schemaHash schema hash * @return Avro schema entry, or null if the schema hash does not exist in the table * @throws IOException on I/O error. */ private SchemaTableEntry loadFromHashTable(BytesKey schemaHash) throws IOException { final ByteBuffer tableKey = ByteBuffer.wrap(schemaHash.getBytes()); final ResultSet resultSet = mAdmin.execute(mPreparedStatementReadHashTable.bind(tableKey)); final List<Row> rows = resultSet.all(); if (0 == rows.size()) { return null; } assert(rows.size() == 1); final byte[] schemaAsBytes = ByteUtils.toBytes(rows.get(0).getBytes(SCHEMA_COLUMN_VALUE)); return decodeSchemaEntry(schemaAsBytes); }
/** * Converts a SchemaEntry into an Avro SchemaTableEntry. * * @param entry a SchemaEntry. * @return an equivalent Avro SchemaTableEntry. */ public static SchemaTableEntry toAvroEntry(final SchemaEntry entry) { return SchemaTableEntry.newBuilder().setId(entry.getId()) .setHash(new MD5Hash(entry.getHash().getBytes())) .setAvroSchema(entry.getSchema().toString()).build(); }
/** * Converts a SchemaEntry into an Avro SchemaTableEntry. * * @param entry a SchemaEntry. * @return an equivalent Avro SchemaTableEntry. */ public static SchemaTableEntry toAvroEntry(final SchemaEntry entry) { return SchemaTableEntry .newBuilder() .setId(entry.getId()) .setHash(new MD5Hash(entry.getHash().getBytes())) .setAvroSchema(entry.getSchema().toString()) .build(); }