Schema¶
- class lsst.alert.packet.Schema(schema_definition)¶
Bases:
object
An Avro schema.
- Parameters:
- schema_definition
dict
An Avro schema definition as returned by e.g.
fastavro.schema.load_schema
.
- schema_definition
Notes
The interaction with
fastavro
here needs some explanation.When
fastavro
loads a schema, it parses each of the types contained within that schema and remembers them for future use. So that if, for example, your schema defines a typelsst.alert.diaSource
,fastavro
will remember that type and use it when referring to your schema.However, it uses a single lookup table by type for these. Thus, if you load another schema which defines an
lsst.alert.diaSource
type which is not the same as the first, then it will clobber the earlier definition, and confusion will reign.We avoid this here by fully resolving everything (ie, all schemas are defined in terms of primitive types) and then clearing the
fastavro
cache after loading.Methods Summary
deserialize
(record)Deserialize an Avro packet folowing this schema.
from_file
([filename])Instantiate a
Schema
by reading its definition from the filesystem.from_uri
([base_uri])Instantiate a
Schema
by reading its definition from a URI.Retrieve the schema id used in the schema registry.
retrieve_alerts
(fp)Read alert packets from the given I/O stream.
serialize
(record)Create an Avro representation of data following this schema.
store_alerts
(fp, records)Store alert packets to the given I/O stream.
validate
(record)Validate packet contents against this schema.
Methods Documentation
- deserialize(record)¶
Deserialize an Avro packet folowing this schema.
- classmethod from_file(filename=None)¶
Instantiate a
Schema
by reading its definition from the filesystem.
- classmethod from_uri(base_uri: None | str | ResourcePath = None) Schema ¶
Instantiate a
Schema
by reading its definition from a URI.- Parameters:
- base_uri
str
orlsst.resources.ResourcePath
orNone
URI to the base schema as either a
ResourcePath
or a string that can be converted to one. IfNone
the most recent default schema will be used.
- base_uri
- get_schema_id()¶
Retrieve the schema id used in the schema registry.
- retrieve_alerts(fp)¶
Read alert packets from the given I/O stream.
- Parameters:
- fpderivative of
IOBase
I/O stream from which data will be read.
- schema
list
, optional A schema describing the contents of the Avro packets. If not provided, the schema used when writing the alert stream will be used.
- fpderivative of
- Returns:
- schema
lsst.alert.Schema
The schema with which alerts were written (which may be different from this schema being used for deserialization).
- recordsiterable of
dict
Alert records.
- schema
- serialize(record)¶
Create an Avro representation of data following this schema.