Top Description Fields Constructors Methods
org.apache.avro

public Class LogicalType

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.avro.LogicalTypes.Decimal, org.apache.avro.LogicalTypes.Date, org.apache.avro.LogicalTypes.TimeMillis, org.apache.avro.LogicalTypes.TimeMicros, org.apache.avro.LogicalTypes.TimestampMillis, org.apache.avro.LogicalTypes.TimestampMicros, org.apache.avro.LogicalTypes.LocalTimestampMillis, org.apache.avro.LogicalTypes.LocalTimestampMicros
Imports
org.apache.avro.generic.GenericData, org.apache.avro.specific.SpecificData

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

Modifier and TypeField and Description
private static final String[]
public static final String
private final String

Constructor Summary

AccessConstructor and Description
public
LogicalType(String logicalTypeName)

Method Summary

Modifier and TypeMethod and Description
public Schema

Returns:

the modified Schema
addToSchema
(Schema
a Schema
schema
)

Add this logical type to the given Schema.

public String

Returns:

the String name of the logical type
getName
()

Get the name of this logical type.

public void
validate(Schema
a Schema
schema
)

Validate this logical type for the given Schema.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INCOMPATIBLE_PROPSback to summary
private static final String[] INCOMPATIBLE_PROPS
LOGICAL_TYPE_PROPback to summary
public static final String LOGICAL_TYPE_PROP
nameback to summary
private final String name

Constructor Detail

LogicalTypeback to summary
public LogicalType(String logicalTypeName)

Method Detail

addToSchemaback to summary
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:Schema

a Schema

Returns:Schema

the modified Schema

Exceptions
IllegalArgumentException:
if the type and schema are incompatible
getNameback to summary
public String getName()

Get the name of this logical type.

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

Returns:String

the String name of the logical type

validateback to summary
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:Schema

a Schema

Exceptions
IllegalArgumentException:
if the type and schema are incompatible