Java Code Examples for org.apache.avro.SchemaNormalization#parsingFingerprint()

The following examples show how to use org.apache.avro.SchemaNormalization#parsingFingerprint() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AvroEventDeserializer.java    From mt-flume with Apache License 2.0 6 votes vote down vote up
private void initialize() throws IOException, NoSuchAlgorithmException {
  SeekableResettableInputBridge in = new SeekableResettableInputBridge(ris);
  long pos = in.tell();
  in.seek(0L);
  fileReader = new DataFileReader<GenericRecord>(in,
      new GenericDatumReader<GenericRecord>());
  fileReader.sync(pos);

  schema = fileReader.getSchema();
  datumWriter = new GenericDatumWriter(schema);
  out = new ByteArrayOutputStream();
  encoder = EncoderFactory.get().binaryEncoder(out, encoder);

  schemaHash = SchemaNormalization.parsingFingerprint("CRC-64-AVRO", schema);
  schemaHashString = Hex.encodeHexString(schemaHash);
}
 
Example 2
Source File: IcebergEncoder.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static byte[] getWriteHeader(org.apache.avro.Schema schema) {
  try {
    byte[] fp = SchemaNormalization.parsingFingerprint("CRC-64-AVRO", schema);
    return Bytes.concat(V1_HEADER, fp);
  } catch (NoSuchAlgorithmException e) {
    throw new AvroRuntimeException(e);
  }
}
 
Example 3
Source File: IcebergEncoder.java    From iceberg with Apache License 2.0 5 votes vote down vote up
private static byte[] getWriteHeader(org.apache.avro.Schema schema) {
  try {
    byte[] fp = SchemaNormalization.parsingFingerprint("CRC-64-AVRO", schema);
    return Bytes.concat(V1_HEADER, fp);
  } catch (NoSuchAlgorithmException e) {
    throw new AvroRuntimeException(e);
  }
}
 
Example 4
Source File: GoogleCloudPubSubFlusher.java    From divolte-collector with Apache License 2.0 5 votes vote down vote up
private static String schemaFingerprint(final DivolteSchema schema) {
    final Schema avroSchema = schema.avroSchema;
    final byte[] fingerprint;
    // SHA-256 is on the list of mandatory JCE algorithms, so this shouldn't be an issue.
    try {
        fingerprint = SchemaNormalization.parsingFingerprint("SHA-256", avroSchema);
    } catch (final NoSuchAlgorithmException e) {
        throw new RuntimeException("Cannot calculate schema fingerprint; missing SHA-256 digest algorithm", e);
    }
    return FINGERPRINT_ENCODER.encodeToString(fingerprint);
}
 
Example 5
Source File: FixedAvroSerializer.java    From jstorm with Apache License 2.0 5 votes vote down vote up
public FixedAvroSerializer() throws IOException, NoSuchAlgorithmException {
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("FixedAvroSerializer.config");
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));

    String line;
    while((line = reader.readLine()) != null) {
        Schema schema = new Schema.Parser().parse(line);
        byte [] fp = SchemaNormalization.parsingFingerprint(FP_ALGO, schema);
        String fingerPrint = new String(Base64.decodeBase64(fp));

        fingerprint2schemaMap.put(fingerPrint, schema);
        schema2fingerprintMap.put(schema, fingerPrint);
    }
}