-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[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
Merged
swathipil
merged 21 commits into
Azure:main
from
swathipil:swathipil/sr/avro-exception-type
Oct 27, 2021
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
44d435e
exceptions file
swathipil e1e1f43
abstract object serializer
swathipil fa6299c
merge main
swathipil 682aed8
add tests
swathipil e296db5
async apache tests
swathipil aa901b8
lint
swathipil d0095d1
update internal docstring
swathipil afbcc85
more docstring
swathipil 401f8ec
fix tests
swathipil 2af7aa2
async update
swathipil d151ad9
fix
swathipil 7d3755a
remove fastavro
swathipil 63d08d7
docstring
swathipil 75259ae
test fix
swathipil f6beaae
adams comments
swathipil 9b886d3
lint
swathipil f10e693
comments
swathipil 6b1c7da
changelog
swathipil e3f0694
nit
swathipil 66567e2
lint
swathipil a553d37
nit
swathipil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...vroserializer/azure/schemaregistry/serializer/avroserializer/_abstract_avro_serializer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # 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, TypeVar, Union | ||
| from abc import abstractmethod | ||
|
|
||
| ObjectType = TypeVar("ObjectType") | ||
|
|
||
| class AbstractAvroObjectSerializer(object): | ||
| """ | ||
| An Avro serializer used for serializing/deserializing an Avro RecordSchema. | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def get_schema_fullname( | ||
| self, | ||
| schema, # type: str | ||
| ): | ||
| # type: (str) -> str | ||
| """ | ||
| Returns the namespace-qualified name of the provided schema. | ||
| Schema must be a Avro RecordSchema: | ||
| https://avro.apache.org/docs/1.10.0/gettingstartedpython.html#Defining+a+schema | ||
| :param schema: An Avro RecordSchema | ||
| :type schema: str | ||
| :rtype: str | ||
| """ | ||
|
|
||
|
|
||
| @abstractmethod | ||
| def serialize( | ||
| self, | ||
| data, # type: ObjectType | ||
| schema, # type: str | ||
| ): | ||
| # type: (ObjectType, str) -> bytes | ||
| """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: str | ||
| :returns: Encoded bytes | ||
| :rtype: bytes | ||
| """ | ||
|
|
||
| @abstractmethod | ||
| def deserialize( | ||
| self, | ||
| data, # type: Union[bytes, BinaryIO] | ||
| schema, # type: str | ||
| ): | ||
| # type: (Union[bytes, BinaryIO], str) -> ObjectType | ||
| """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: str | ||
| :returns: An instantiated object | ||
| :rtype: ObjectType | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
...re-schemaregistry-avroserializer/azure/schemaregistry/serializer/avroserializer/_utils.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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:
(
)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.