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.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:
-
retrieve_alerts(fp)¶ Read alert packets from the given I/O stream.
Parameters: - fp : derivative 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).
- records : iterable of
dict Alert records.
- fp : derivative 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 :