Class LogicalType

java.lang.Object
org.apache.avro.LogicalType
Direct Known Subclasses:
LogicalTypes.BigDecimal, LogicalTypes.Date, LogicalTypes.Decimal, LogicalTypes.Duration, LogicalTypes.LocalTimestampMicros, LogicalTypes.LocalTimestampMillis, LogicalTypes.LocalTimestampNanos, LogicalTypes.TimeMicros, LogicalTypes.TimeMillis, LogicalTypes.TimestampMicros, LogicalTypes.TimestampMillis, LogicalTypes.TimestampNanos, LogicalTypes.Uuid

public class LogicalType extends Object
Logical types provides an opt-in way to extend Avro's types. Logical types specify a way of representing a high-level type as a base Avro type. For example, a date is specified as the number of days after the unix epoch (or before using a negative value). This enables extensions to Avro's type system without breaking binary compatibility. Older versions see the base type and ignore the logical type.
  • Field Details

  • Constructor Details

    • LogicalType

      public LogicalType(String logicalTypeName)
  • Method Details

    • getName

      public String getName()
      Get the name of this logical type.

      This name is set as the Schema property "logicalType".

      Returns:
      the String name of the logical type
    • addToSchema

      public Schema addToSchema(Schema schema)
      Add this logical type to the given Schema.

      The "logicalType" property will be set to this type's name, and other type-specific properties may be added. The Schema is first validated to ensure it is compatible.

      Parameters:
      schema - a Schema
      Returns:
      the modified Schema
      Throws:
      IllegalArgumentException - if the type and schema are incompatible
    • validate

      public void validate(Schema schema)
      Validate this logical type for the given Schema.

      This will throw an exception if the Schema is incompatible with this type. For example, a date is stored as an int and is incompatible with a fixed Schema.

      Parameters:
      schema - a Schema
      Throws:
      IllegalArgumentException - if the type and schema are incompatible