Skip to content

Commit 5b322fe

Browse files
swathipilscbedd
andauthored
[SchemaRegistry] AvroEncoder (Azure#22816)
* remove serializer folder * update EventData * eventdata update * make ED data bytearray * initial commit * tests/changelog/docstring * add encoder to ci * fix ED body as str * shared reqs * cspell/lint * spell check/lint/tests/docs * links + mypy * docstring * fix EH azure-core min dependency conflict * adams comments * pylint * more comments * lint * correct how the value of SetDevVersion environment variable is compared * allow reader's schema in decode * adams comments * update to callable + add classmethod to EventData * combine data/content_type in messagetype protocol * docs * pylint Co-authored-by: scbedd <45376673+scbedd@users.noreply.github.com>
1 parent 27313b3 commit 5b322fe

File tree

75 files changed

+3023
-953
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3023
-953
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@
8686
"sdk/metricsadvisor/azure-ai-metricsadvisor/**",
8787
"sdk/purview/azure-purview-catalog/**",
8888
"sdk/remoterendering/azure-mixedreality-remoterendering/**",
89+
"sdk/schemaregistry/ci.yml",
8990
"sdk/schemaregistry/azure-schemaregistry/**",
90-
"sdk/schemaregistry/azure-schemaregistry-avroserializer/**",
91+
"sdk/schemaregistry/azure-schemaregistry-avroencoder/**",
9192
"sdk/servicefabric/azure-servicefabric/**",
9293
"sdk/search/azure-search-documents/**",
9394
"sdk/storage/azure-storage-blob-changefeed/**",

eng/tox/create_package_and_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def build_and_discover_package(setuppy_path, dist_dir, target_setup, package_typ
183183
os.mkdir(tmp_dl_folder)
184184

185185
# preview version is enabled when installing dev build so pip will install dev build version from devpos feed
186-
if os.getenv("SetDevVersion"):
186+
if os.getenv("SetDevVersion", 'false') == 'true':
187187
commands_options.append("--pre")
188188

189189
if args.cache_dir:

sdk/eventhub/azure-eventhub/CHANGELOG.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
# Release History
22

3-
## 5.7.1 (Unreleased)
3+
## 5.9.0b1 (Unreleased)
44

55
### Features Added
66

7-
### Breaking Changes
8-
9-
### Bugs Fixed
10-
11-
### Other Changes
7+
- The classmethod `from_message_data` has been added to `EventData` for interoperability with the Schema Registry Avro Encoder library, and takes `data` and `content_type` as positional parameters.
128

139
## 5.7.0 (2022-01-12)
1410

sdk/eventhub/azure-eventhub/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,10 @@ Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-pytho
435435

436436
Reference documentation is available [here](https://azuresdkdocs.blob.core.windows.net/$web/python/azure-eventhub/latest/azure.eventhub.html).
437437

438-
### Schema Registry and Avro Serializer
438+
### Schema Registry and Avro Encoder
439439

440440
The EventHubs SDK integrates nicely with the [Schema Registry][schemaregistry_service] service and [Avro][avro].
441-
For more information, please refer to [Schema Registry SDK][schemaregistry_repo] and [Schema Registry Avro Serializer SDK][schemaregistry_avroserializer_repo].
441+
For more information, please refer to [Schema Registry SDK][schemaregistry_repo] and [Schema Registry Avro Encoder SDK][schemaregistry_avroencoder_repo].
442442

443443
### Building uAMQP wheel from source
444444

@@ -467,6 +467,6 @@ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.
467467
[api_reference]: https://docs.microsoft.com/python/api/overview/azure/eventhub-readme
468468
[schemaregistry_service]: https://aka.ms/schemaregistry
469469
[schemaregistry_repo]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry
470-
[schemaregistry_avroserializer_repo]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry-avroserializer
470+
[schemaregistry_avroencoder_repo]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/schemaregistry/azure-schemaregistry-avroencoder
471471

472472
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-python/sdk/eventhub/azure-eventhub/README.png)

sdk/eventhub/azure-eventhub/azure/eventhub/_common.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ class EventData(object):
110110
111111
"""
112112

113-
def __init__(self, body=None):
114-
# type: (Union[str, bytes, List[AnyStr]]) -> None
113+
def __init__(
114+
self,
115+
body: Optional[Union[str, bytes, List[AnyStr]]] = None,
116+
) -> None:
115117
self._last_enqueued_event_properties = {} # type: Dict[str, Any]
116118
self._sys_properties = None # type: Optional[Dict[bytes, Any]]
117119
if body is None:
@@ -180,6 +182,20 @@ def __str__(self):
180182
event_str += " }"
181183
return event_str
182184

185+
def __message_data__(self) -> Dict:
186+
if self.body_type != AmqpMessageBodyType.DATA:
187+
raise TypeError('`body_type` must be `AmqpMessageBodyType.DATA`.')
188+
data = bytearray()
189+
for d in self.body: # type: ignore
190+
data += d # type: ignore
191+
return {"data": bytes(data), "content_type": self.content_type}
192+
193+
@classmethod
194+
def from_message_data(cls, data: bytes, content_type: str) -> "EventData":
195+
event_data = cls(data)
196+
event_data.content_type = content_type
197+
return event_data
198+
183199
@classmethod
184200
def _from_message(cls, message, raw_amqp_message=None):
185201
# type: (Message, Optional[AmqpAnnotatedMessage]) -> EventData

sdk/eventhub/azure-eventhub/azure/eventhub/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
# Licensed under the MIT License.
44
# ------------------------------------
55

6-
VERSION = "5.7.1"
6+
VERSION = "5.9.0b1"

sdk/eventhub/azure-eventhub/dev_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
../../core/azure-core
33
-e ../../identity/azure-identity
44
-e ../azure-mgmt-eventhub
5-
-e ../../resources/azure-mgmt-resource
5+
azure-mgmt-resource==20.0.0
66
aiohttp>=3.0
77
-e ../../../tools/azure-devtools
88
-e ../../servicebus/azure-servicebus
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Release History
2+
3+
## 1.0.0b1 (Unreleased)
4+
5+
This version and all future versions will require Python 3.6+. Python 2.7 is no longer supported.
6+
7+
### Features Added
8+
9+
- This package is meant to replace the azure-schemaregistry-avroserializer.
10+
- APIs have been updated to allow for encoding directly to and decoding from message type objects, where the data value is the Avro encoded payload.
11+
- The content type of the message will hold the schema ID and record format indicator.
12+
13+
### Other Changes
14+
15+
- This beta release will be backward compatible for decoding data that was encoded with the AvroSerializer.
16+
- The `encode` and `decode` methods on `AvroEncoder` support the following message models:
17+
- `azure.eventhub.EventData` in `azure-eventhub==5.9.0b1`

sdk/schemaregistry/azure-schemaregistry-avroserializer/LICENSE renamed to sdk/schemaregistry/azure-schemaregistry-avroencoder/LICENSE

File renamed without changes.

sdk/schemaregistry/azure-schemaregistry-avroserializer/MANIFEST.in renamed to sdk/schemaregistry/azure-schemaregistry-avroencoder/MANIFEST.in

File renamed without changes.

0 commit comments

Comments
 (0)