Module avro_schema_store

Stores all types in the schema.

Authors: Ilya Staheev (ilya.staheev@klarna.com).

Description

Stores all types in the schema.

The module allows to access all types in uniform way by using their full names. After a type was successfully placed into the store all its name parts are resolved so that no further actions to work with names are needed.

When type is added to the store all its children named types are extracted and stored as separate types as well. Their placeholders in the original type are replaced by their full names. The types itself keep their full names in 'name' field and empty strings in 'namespace'.

Error will be thrown when name conflict is detected during type addition.

Data Types

array_type()

array_type() = #avro_array_type{type = avro:type_or_name(), custom = [avro:custom_prop()]}

avro_type()

avro_type() = primitive_type() | array_type() | enum_type() | fixed_type() | map_type() | record_type() | union_type()

enum_type()

enum_type() = #avro_enum_type{name = avro:name(), namespace = avro:namespace(), aliases = [avro:name()], doc = avro:typedoc(), symbols = [avro:enum_symbol()], fullname = avro:fullname(), custom = [avro:custom_prop()]}

filename()

filename() = file:filename_all()

fixed_type()

fixed_type() = #avro_fixed_type{name = avro:name(), namespace = avro:namespace(), aliases = [avro:name()], size = pos_integer(), fullname = avro:fullname(), custom = [avro:custom_prop()]}

map_type()

map_type() = #avro_map_type{type = avro:type_or_name(), custom = [avro:custom_prop()]}

name_raw()

name_raw() = atom() | string() | binary()

option_key()

option_key() = access | name | dict

options()

options() = [option_key() | {option_key(), term()}]

primitive_type()

primitive_type() = #avro_primitive_type{name = avro:name(), custom = [avro:custom_prop()]}

record_type()

record_type() = #avro_record_type{name = avro:name(), namespace = avro:namespace(), doc = avro:typedoc(), aliases = [avro:name()], fields = [avro:record_field()], fullname = avro:fullname(), custom = [avro:custom_prop()]}

store()

abstract datatype: store()

union_type()

union_type() = #avro_union_type{id2type = avro_union:id2type(), name2id = avro_union:name2id()}

Function Index

add_type/2Add named type into the schema store.
add_type/3Add (maybe unnamed) type to schema store.
close/1Delete the ets table.
ensure_store/1To make dialyzer happy.
get_all_types/1Get all schema types.
import_file/2Import avro JSON file into schema store.
import_files/2Import avro JSON files into schema store.
import_schema_json/2Decode avro schema JSON into erlavro records.
is_store/1Return true if the given arg is a schema store.
lookup_type/2Lookup a type using its full name.
new/0Equivalent to new([]).
new/1Create a new ets table to store avro types.
new/2Create a new schema store and improt the given schema JSON files.
to_lookup_fun/1Make a schema lookup function from store.

Function Details

add_type/2

add_type(Type::avro_type(), Store::store()) -> store()

Add named type into the schema store. NOTE: the type is flattened before inserting into the schema store. i.e. named types nested in the given type are lifted up to root level.

add_type/3

add_type(AssignedName::undefined | name_raw(), Type0::avro_type(), Store::store()) -> store()

Add (maybe unnamed) type to schema store. If the type is unnamed, the assigned name is used. For named types, the assigned name works like an alias.

close/1

close(Store::store()) -> ok

Delete the ets table.

ensure_store/1

ensure_store(Store::atom() | integer() | reference() | {dict, dict:dict()}) -> store()

To make dialyzer happy.

get_all_types/1

get_all_types(Store::store()) -> [avro_type()]

Get all schema types

import_file/2

import_file(File::filename(), Store::store()) -> store()

Import avro JSON file into schema store. In case the schema is unnamed, the file basename is used as its lookup name. Extention ".avsc" or ".json" will be stripped, Otherwise the full file basename is used. e.g. "/path/to/com.klarna.test.x.avsc" to 'com.klarna.etst.x" "/path/to/com.klarna.test.x.json" to 'com.klarna.etst.x" "/path/to/com.klarna.test.x" to 'com.klarna.etst.x"

import_files/2

import_files(Files::[filename()], Store::store()) -> store()

Import avro JSON files into schema store.

import_schema_json/2

import_schema_json(Json::binary(), Store::store()) -> store()

Decode avro schema JSON into erlavro records. NOTE: Exception if the type is unnamed.

is_store/1

is_store(T::term()) -> boolean()

Return true if the given arg is a schema store.

lookup_type/2

lookup_type(FullName::name_raw(), Store::store()) -> {ok, avro_type()} | false

Lookup a type using its full name.

new/0

new() -> store()

Equivalent to new([]).

new/1

new(Options::options()) -> store()

Create a new ets table to store avro types. Options: * {access, public|protected|private} - has same meaning as access mode in ets:new and defines what processes can have access to * {name, atom()} - used to create a named ets table. * dict - use dict as store backend, ignore access and name options

new/2

new(Options::[proplists:property()], Files::[filename()]) -> store()

Create a new schema store and improt the given schema JSON files.

to_lookup_fun/1

to_lookup_fun(Store::store()) -> fun((name_raw()) -> avro_type())

Make a schema lookup function from store.


Generated by EDoc