pub enum Schema {
Show 28 variants
Null,
Boolean,
Int,
Long,
Float,
Double,
Bytes,
String,
Array(ArraySchema),
Map(MapSchema),
Union(UnionSchema),
Record(RecordSchema),
Enum(EnumSchema),
Fixed(FixedSchema),
Decimal(DecimalSchema),
BigDecimal,
Uuid(UuidSchema),
Date,
TimeMillis,
TimeMicros,
TimestampMillis,
TimestampMicros,
TimestampNanos,
LocalTimestampMillis,
LocalTimestampMicros,
LocalTimestampNanos,
Duration(FixedSchema),
Ref {
name: Name,
},
}Expand description
Represents any valid Avro schema More information about Avro schemas can be found in the Avro Specification
Variants§
Null
A null Avro schema.
Boolean
A boolean Avro schema.
Int
An int Avro schema.
Long
A long Avro schema.
Float
A float Avro schema.
Double
A double Avro schema.
Bytes
A bytes Avro schema.
Bytes represents a sequence of 8-bit unsigned bytes.
String
A string Avro schema.
String represents a unicode character sequence.
Array(ArraySchema)
An array Avro schema.
All items will have the same schema.
Map(MapSchema)
A map Avro schema.
Keys are always a Schema::String and all values will have the same schema.
Union(UnionSchema)
A union Avro schema.
Record(RecordSchema)
A record Avro schema.
Enum(EnumSchema)
An enum Avro schema.
Fixed(FixedSchema)
A fixed Avro schema.
Decimal(DecimalSchema)
Logical type which represents Decimal values.
The underlying type is serialized and deserialized as Schema::Bytes or Schema::Fixed.
BigDecimal
Logical type which represents Decimal values without predefined scale.
The underlying type is serialized and deserialized as Schema::Bytes
Uuid(UuidSchema)
A universally unique identifier, annotating a string, bytes or fixed.
Date
Logical type which represents the number of days since the unix epoch.
Serialization format is Schema::Int.
TimeMillis
The time of day in number of milliseconds after midnight.
This type has no reference to any calendar, time zone or date in particular.
TimeMicros
The time of day in number of microseconds after midnight.
This type has no reference to any calendar, time zone or date in particular.
TimestampMillis
An instant in time represented as the number of milliseconds after the UNIX epoch.
TimestampMicros
An instant in time represented as the number of microseconds after the UNIX epoch.
TimestampNanos
An instant in time represented as the number of nanoseconds after the UNIX epoch.
LocalTimestampMillis
An instant in localtime represented as the number of milliseconds after the UNIX epoch.
LocalTimestampMicros
An instant in local time represented as the number of microseconds after the UNIX epoch.
LocalTimestampNanos
An instant in local time represented as the number of nanoseconds after the UNIX epoch.
Duration(FixedSchema)
An amount of time defined by a number of months, days and milliseconds.
Ref
A reference to another schema.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn union(schemas: Vec<Schema>) -> AvroResult<Schema>
pub fn union(schemas: Vec<Schema>) -> AvroResult<Schema>
Returns a Schema::Union with the given variants.
§Errors
Will return an error if schemas has duplicate unnamed schemas or if schemas
contains a union.
Sourcepub fn map(types: Schema) -> SchemaMapBuilder
pub fn map(types: Schema) -> SchemaMapBuilder
Returns a Schema::Map with the given types and optional default
and custom attributes.
Sourcepub fn array(items: Schema) -> SchemaArrayBuilder
pub fn array(items: Schema) -> SchemaArrayBuilder
Returns a Schema::Array with the given items and optional default
and custom attributes.
Sourcepub fn enum<I1>(name: Name, symbols: Vec<I1>) -> SchemaEnumBuilder<I1>
pub fn enum<I1>(name: Name, symbols: Vec<I1>) -> SchemaEnumBuilder<I1>
Returns a Schema::Enum with the given name, symbols and optional
aliases, doc, default and custom attributes.
Source§impl Schema
impl Schema
Sourcepub fn canonical_form(&self) -> String
pub fn canonical_form(&self) -> String
Converts self into its Parsing Canonical Form.
Sourcepub fn independent_canonical_form(
&self,
schemata: &[Schema],
) -> Result<String, Error>
pub fn independent_canonical_form( &self, schemata: &[Schema], ) -> Result<String, Error>
Returns the Parsing Canonical Form of self that is self contained (not dependent on
any definitions in schemata)
If you require a self contained schema including default and doc attributes, see denormalize.
Sourcepub fn fingerprint<D: Digest>(&self) -> SchemaFingerprint
pub fn fingerprint<D: Digest>(&self) -> SchemaFingerprint
Generate the fingerprint of the schema’s Parsing Canonical Form.
§Example
use apache_avro::rabin::Rabin;
use apache_avro::{Schema, Error};
use md5::Md5;
use sha2::Sha256;
fn main() -> Result<(), Error> {
let raw_schema = r#"
{
"type": "record",
"name": "test",
"fields": [
{"name": "a", "type": "long", "default": 42},
{"name": "b", "type": "string"}
]
}
"#;
let schema = Schema::parse_str(raw_schema)?;
println!("{}", schema.fingerprint::<Sha256>());
println!("{}", schema.fingerprint::<Md5>());
println!("{}", schema.fingerprint::<Rabin>());
Ok(())
}Sourcepub fn parse_str(input: &str) -> Result<Schema, Error>
pub fn parse_str(input: &str) -> Result<Schema, Error>
Create a Schema from a string representing a JSON Avro schema.
Sourcepub fn parse_list(
input: impl IntoIterator<Item = impl AsRef<str>>,
) -> AvroResult<Vec<Schema>>
pub fn parse_list( input: impl IntoIterator<Item = impl AsRef<str>>, ) -> AvroResult<Vec<Schema>>
Create an array of Schema’s from a list of named JSON Avro schemas (Record, Enum, and
Fixed).
It is allowed that the schemas have cross-dependencies; these will be resolved during parsing.
If two of the input schemas have the same fullname, an Error will be returned.
Sourcepub fn parse_str_with_list(
schema: &str,
schemata: impl IntoIterator<Item = impl AsRef<str>>,
) -> AvroResult<(Schema, Vec<Schema>)>
pub fn parse_str_with_list( schema: &str, schemata: impl IntoIterator<Item = impl AsRef<str>>, ) -> AvroResult<(Schema, Vec<Schema>)>
Create a Schema from a string representing a JSON Avro schema,
along with an array of Schema’s from a list of named JSON Avro schemas (Record, Enum, and
Fixed).
It is allowed that the schemas have cross-dependencies; these will be resolved during parsing.
If two of the named input schemas have the same fullname, an Error will be returned.
§Arguments
schema- the JSON string of the schema to parseschemata- a slice of additional schemas that is used to resolve cross-references
Sourcepub fn parse_reader(reader: &mut (impl Read + ?Sized)) -> AvroResult<Schema>
pub fn parse_reader(reader: &mut (impl Read + ?Sized)) -> AvroResult<Schema>
Create a Schema from a reader which implements Read.
Sourcepub fn parse(value: &JsonValue) -> AvroResult<Schema>
pub fn parse(value: &JsonValue) -> AvroResult<Schema>
Parses an Avro schema from JSON.
Sourcepub fn custom_attributes(&self) -> Option<&BTreeMap<String, JsonValue>>
pub fn custom_attributes(&self) -> Option<&BTreeMap<String, JsonValue>>
Returns the custom attributes (metadata) if the schema supports them.
Sourcepub fn is_named(&self) -> bool
pub fn is_named(&self) -> bool
Returns whether the schema represents a named type according to the avro specification
Sourcepub fn denormalize(&mut self, schemata: &[Schema]) -> AvroResult<()>
pub fn denormalize(&mut self, schemata: &[Schema]) -> AvroResult<()>
Remove all external references from the schema.
schemata must contain all externally referenced schemas.
§Errors
Will return a Details::SchemaResolutionError if it fails to find
a referenced schema. This will put the schema in a partly denormalized state.