Schema#
- class lsst.alert.packet.Schema(schema_definition)#
Bases:
objectAn Avro schema.
Parameters#
- schema_definition
dict An Avro schema definition as returned by e.g.
fastavro.schema.load_schema.
Notes#
The interaction with
fastavrohere needs some explanation.When
fastavroloads 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,fastavrowill 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.diaSourcetype 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
fastavrocache after loading.Methods Summary
deserialize(record)Deserialize an Avro packet folowing this schema.
from_file([filename])Instantiate a
Schemaby reading its definition from the filesystem.from_uri([base_uri])Instantiate a
Schemaby 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.
Parameters#
- record
bytes The data to be deserialized.
Returns#
- alert_data
dict Deserialized packet contents.
- record
- classmethod from_file(filename=None)#
Instantiate a
Schemaby reading its definition from the filesystem.Parameters#
- filename
str, optional Path to the schema root (/path/to/lsst.vM_m.alert.avsc). Will recursively load referenced schemas, assuming they can be found; otherwise, will raise. If
None(the default), will load the latest schema defined in this package.
- filename
- classmethod from_uri(base_uri: None | str | ResourcePath = None) Schema#
Instantiate a
Schemaby reading its definition from a URI.Parameters#
- base_uri
strorlsst.resources.ResourcePathorNone URI to the base schema as either a
ResourcePathor a string that can be converted to one. IfNonethe 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.
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.
- fpderivative of
- serialize(record)#
Create an Avro representation of data following this schema.
Parameters#
- record
dict The data to be serialized to Avro.
Returns#
- avro_data
bytes An Avro serialization of the input data.
- record
- schema_definition