-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[SchemaRegistry] avro serializer add exceptions #21381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
44d435e
e1e1f43
fa6299c
682aed8
e296db5
aa901b8
d0095d1
afbcc85
401f8ec
2af7aa2
d151ad9
7d3755a
63d08d7
75259ae
f6beaae
9b886d3
f10e693
6b1c7da
e3f0694
66567e2
a553d37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from typing import BinaryIO, Dict, Mapping, Any, TypeVar, Union | ||
| from abc import abstractmethod | ||
| import avro | ||
|
|
||
| ObjectType = TypeVar("ObjectType") | ||
|
|
||
| class AbstractAvroObjectSerializer(object): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if this comment will matter much, since we're changing the design anyway. But, just an option:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as OOB discussion: I think this is a great idea being able to let users opt in their own avro implementation. I personally prefer keeping try/except wrapping in the schema registry avro serializer. My 2 cents are exception experience will be strongly consistent among different avro implementation if done in the schema registry avro serializer. If we want to define error raising as part of the protocol (abstraction), then users need to try/except wrap by themselves in which case tend to make mistake, e.g. forget to handle error I don't think this would impact our current design, we could revisit it if users request for this in the future. |
||
| """ | ||
| An Avro serializer used for serializing/deserializing an Avro RecordSchema. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def serialize( | ||
| self, | ||
| data, # type: ObjectType | ||
| schema, # type: Union[str, bytes, avro.schema.Schema] | ||
| ): | ||
| # type: (ObjectType, Union[str, bytes, avro.schema.Schema]) -> bytes | ||
|
yunhaoling marked this conversation as resolved.
Outdated
|
||
| """Convert the provided value to it's binary representation and write it to the stream. | ||
| Schema must be a Avro RecordSchema: | ||
| https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema | ||
| :param data: An object to serialize | ||
| :type data: ObjectType | ||
| :param schema: An Avro RecordSchema | ||
| :type schema: Union[str, bytes, avro.schema.Schema] | ||
| :returns: Encoded bytes | ||
| :rtype: bytes | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def deserialize( | ||
| self, | ||
| data, # type: Union[bytes, BinaryIO] | ||
| schema, # type: Union[str, bytes, avro.schema.Schema] | ||
| ): | ||
| # type: (Union[bytes, BinaryIO], Union[str, bytes, avro.schema.Schema]) -> ObjectType | ||
|
swathipil marked this conversation as resolved.
Outdated
|
||
| """Read the binary representation into a specific type. | ||
| Return type will be ignored, since the schema is deduced from the provided bytes. | ||
| :param data: A stream of bytes or bytes directly | ||
| :type data: BinaryIO or bytes | ||
| :param schema: An Avro RecordSchema | ||
| :type schema: Union[str, bytes, avro.schema.Schema] | ||
| :returns: An instantiated object | ||
| :rtype: ObjectType | ||
| """ | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from azure.core.exceptions import AzureError | ||
|
|
||
| class SchemaParseError(AzureError): | ||
| def __init__(self, message, *args, **kwargs): | ||
| super(SchemaParseError, self).__init__(message, *args, **kwargs) | ||
|
|
||
| class SchemaSerializationError(AzureError): | ||
| def __init__(self, message, *args, **kwargs): | ||
| super(SchemaSerializationError, self).__init__(message, *args, **kwargs) | ||
|
|
||
| class SchemaDeserializationError(AzureError): | ||
| def __init__(self, message, *args, **kwargs): | ||
| super(SchemaDeserializationError, self).__init__(message, *args, **kwargs) |
Uh oh!
There was an error while loading. Please reload this page.