org.apache.avro

## Class LogicalType

- java.lang.Object
- - org.apache.avro.LogicalType

Direct Known Subclasses:
  LogicalTypes.BigDecimal, LogicalTypes.Date, LogicalTypes.Decimal, LogicalTypes.LocalTimestampMicros, LogicalTypes.LocalTimestampMillis, LogicalTypes.TimeMicros, LogicalTypes.TimeMillis, LogicalTypes.TimestampMicros, LogicalTypes.TimestampMillis

    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 Summary

Fields
`static String` `LOGICAL_TYPE_PROP`

### Constructor Summary

Constructors
Constructor and Description
`LogicalType(String logicalTypeName)`

### Method Summary

All Methods Instance Methods Concrete Methods
`Schema` `addToSchema(Schema schema)` Add this logical type to the given Schema.
`String` `getName()` Get the name of this logical type.
`void` `validate(Schema schema)` Validate this logical type for the given Schema.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### LOGICAL_TYPE_PROP

    public static final String LOGICAL_TYPE_PROP

See Also:
  Constant Field Values

### Constructor Detail

#### LogicalType

    public LogicalType(String logicalTypeName)

### Method Detail

#### 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