Class SchemaNormalization

java.lang.Object
org.apache.avro.SchemaNormalization

public class SchemaNormalization extends Object
Collection of static methods for generating the canonical form of schemas (see toParsingForm(org.apache.avro.Schema)) -- and fingerprints of canonical forms (fingerprint(java.lang.String, byte[])).
  • Method Details

    • toParsingForm

      public static String toParsingForm(Schema s)
      Returns "Parsing Canonical Form" of a schema as defined by Avro spec.
    • fingerprint

      public static byte[] fingerprint(String fpName, byte[] data) throws NoSuchAlgorithmException
      Returns a fingerprint of a string of bytes. This string is presumed to contain a canonical form of a schema. The algorithm used to compute the fingerprint is selected by the argument fpName. If fpName equals the string "CRC-64-AVRO", then the result of fingerprint64(byte[]) is returned in little-endian format. Otherwise, fpName is used as an algorithm name for MessageDigest.getInstance(String), which will throw NoSuchAlgorithmException if it doesn't recognize the name.

      Recommended Avro practice dictates that "CRC-64-AVRO" is used for 64-bit fingerprints, "MD5" is used for 128-bit fingerprints, and "SHA-256" is used for 256-bit fingerprints.

      Throws:
      NoSuchAlgorithmException
    • fingerprint64

      public static long fingerprint64(byte[] data)
      Returns the 64-bit Rabin Fingerprint (as recommended in the Avro spec) of a byte string.
    • parsingFingerprint

      public static byte[] parsingFingerprint(String fpName, Schema s) throws NoSuchAlgorithmException
      Returns fingerprint(java.lang.String, byte[]) applied to the parsing canonical form of the supplied schema.
      Throws:
      NoSuchAlgorithmException
    • parsingFingerprint64

      public static long parsingFingerprint64(Schema s)
      Returns fingerprint64(byte[]) applied to the parsing canonical form of the supplied schema.