Skip to content

Commit

Permalink
[SchemaRegistry] rename namespace (#20965)
Browse files Browse the repository at this point in the history
fixes: #20711
  • Loading branch information
swathipil authored Oct 1, 2021
1 parent cfb945d commit 6b33654
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@

### Features Added

- `auto_register_schemas` keyword argument has been added to `SchemaRegistryAvroSerializer`, which will allow for automatically registering schemas passed in to the `serialize`.
- `value` parameter in `serialize` on `SchemaRegistryAvroSerializer` takes type `Mapping` rather than `Dict`.
- `auto_register_schemas` keyword argument has been added to `AvroSerializer`, which will allow for automatically registering schemas passed in to the `serialize`.
- `value` parameter in `serialize` on `AvroSerializer` takes type `Mapping` rather than `Dict`.

### Breaking Changes

- `schema_registry` parameter in the `SchemaRegistryAvroSerializer` constructor has been renamed `client`.
- `schema_group` parameter in the `SchemaRegistryAvroSerializer` constructor has been renamed `group_name`.
- `data` parameter in the `serialize` and `deserialize` methods on `SchemaRegistryAvroSerializer` has been renamed `value`.
- `schema` parameter in the `serialize` method on `SchemaRegistryAvroSerializer` no longer accepts argument of type `bytes`.
- `SchemaRegistryAvroSerializer` constructor no longer takes in the `codec` keyword argument.
- `SchemaRegistryAvroSerializer` has been renamed `AvroSerializer`.
- `schema_registry` parameter in the `AvroSerializer` constructor has been renamed `client`.
- `schema_group` parameter in the `AvroSerializer` constructor has been renamed `group_name`.
- `data` parameter in the `serialize` and `deserialize` methods on `AvroSerializer` has been renamed `value`.
- `schema` parameter in the `serialize` method on `AvroSerializer` no longer accepts argument of type `bytes`.
- `AvroSerializer` constructor no longer takes in the `codec` keyword argument.
- The following positional arguments are now required keyword arguments:
- `client` and `group_name` in `SchemaRegistryAvroSerializer` constructor
- `schema` in `serialize` on `SchemaRegistryAvroSerializer`
- `client` and `group_name` in `AvroSerializer` constructor
- `schema` in `serialize` on `AvroSerializer`

### Bugs Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

__version__ = VERSION

from ._schema_registry_avro_serializer import SchemaRegistryAvroSerializer
from ._schema_registry_avro_serializer import AvroSerializer

__all__ = [
"SchemaRegistryAvroSerializer"
"AvroSerializer"
]
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
from ._avro_serializer import AvroObjectSerializer


class SchemaRegistryAvroSerializer(object):
class AvroSerializer(object):
"""
SchemaRegistryAvroSerializer provides the ability to serialize and deserialize data according
AvroSerializer provides the ability to serialize and deserialize data according
to the given avro schema. It would automatically register, get and cache the schema.
:keyword client: Required. The schema registry client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

from azure.identity import ClientSecretCredential
from azure.schemaregistry import SchemaRegistryClient
from azure.schemaregistry.serializer.avroserializer import SchemaRegistryAvroSerializer
from azure.schemaregistry.serializer.avroserializer import AvroSerializer

TENANT_ID=os.environ['AZURE_TENANT_ID']
CLIENT_ID=os.environ['AZURE_CLIENT_ID']
Expand Down Expand Up @@ -80,7 +80,7 @@ def deserialize(serializer, bytes_payload):

if __name__ == '__main__':
schema_registry = SchemaRegistryClient(endpoint=SCHEMAREGISTRY_FULLY_QUALIFIED_NAMESPACE, credential=token_credential)
serializer = SchemaRegistryAvroSerializer(client=schema_registry, group_name=GROUP_NAME, auto_register_schemas=True)
serializer = AvroSerializer(client=schema_registry, group_name=GROUP_NAME, auto_register_schemas=True)
bytes_data_ben, bytes_data_alice = serialize(serializer)
dict_data_ben = deserialize(serializer, bytes_data_ben)
dict_data_alice = deserialize(serializer, bytes_data_alice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
# --------------------------------------------------------------------------------------------

"""
Examples to show receiving events from EventHub with SchemaRegistryAvroSerializer integrated for data deserialization.
Examples to show receiving events from EventHub with AvroSerializer integrated for data deserialization.
"""

# pylint: disable=C0111
import os
from azure.eventhub import EventHubConsumerClient
from azure.identity import DefaultAzureCredential
from azure.schemaregistry import SchemaRegistryClient
from azure.schemaregistry.serializer.avroserializer import SchemaRegistryAvroSerializer
from azure.schemaregistry.serializer.avroserializer import AvroSerializer

EVENTHUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR']
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME']
Expand Down Expand Up @@ -44,9 +44,9 @@ def on_event(partition_context, event):
)


# create a SchemaRegistryAvroSerializer instance
# create a AvroSerializer instance
# TODO: after 'azure-schemaregistry==1.0.0b3' is released, update 'endpoint' to 'fully_qualified_namespace'
avro_serializer = SchemaRegistryAvroSerializer(
avro_serializer = AvroSerializer(
client=SchemaRegistryClient(
endpoint=SCHEMAREGISTRY_FULLY_QUALIFIED_NAMESPACE,
credential=DefaultAzureCredential()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# --------------------------------------------------------------------------------------------

"""
Examples to show sending event to EventHub with SchemaRegistryAvroSerializer integrated for data serialization.
Examples to show sending event to EventHub with AvroSerializer integrated for data serialization.
"""

# pylint: disable=C0111
Expand All @@ -15,7 +15,7 @@
from azure.eventhub import EventHubProducerClient, EventData
from azure.identity import DefaultAzureCredential
from azure.schemaregistry import SchemaRegistryClient
from azure.schemaregistry.serializer.avroserializer import SchemaRegistryAvroSerializer
from azure.schemaregistry.serializer.avroserializer import AvroSerializer

EVENTHUB_CONNECTION_STR = os.environ['EVENT_HUB_CONN_STR']
EVENTHUB_NAME = os.environ['EVENT_HUB_NAME']
Expand Down Expand Up @@ -58,9 +58,9 @@ def send_event_data_batch(producer, serializer):
)


# create a SchemaRegistryAvroSerializer instance
# create a AvroSerializer instance
# TODO: after 'azure-schemaregistry==1.0.0b3' is released, update 'endpoint' to 'fully_qualified_namespace'
avro_serializer = SchemaRegistryAvroSerializer(
avro_serializer = AvroSerializer(
client=SchemaRegistryClient(
endpoint=SCHEMAREGISTRY_FULLY_QUALIFIED_NAMESPACE,
credential=DefaultAzureCredential()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interactions:
content-type:
- application/json
date:
- Tue, 28 Sep 2021 22:27:25 GMT
- Thu, 30 Sep 2021 02:05:53 GMT
location:
- https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2017-04
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interactions:
content-type:
- application/json
date:
- Tue, 28 Sep 2021 22:27:26 GMT
- Thu, 30 Sep 2021 02:05:54 GMT
location:
- https://swathip-test-eventhubs.servicebus.windows.net:443/$schemagroups/fakegroup/schemas/example.avro.User/versions/1?api-version=2017-04
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from io import BytesIO

from azure.schemaregistry import SchemaRegistryClient
from azure.schemaregistry.serializer.avroserializer import SchemaRegistryAvroSerializer
from azure.schemaregistry.serializer.avroserializer import AvroSerializer
from azure.schemaregistry.serializer.avroserializer._avro_serializer import AvroObjectSerializer
from azure.identity import ClientSecretCredential
from azure.core.exceptions import ClientAuthenticationError, ServiceRequestError, HttpResponseError
Expand All @@ -34,7 +34,7 @@

SchemaRegistryPowerShellPreparer = functools.partial(PowerShellPreparer, "schemaregistry", schemaregistry_fully_qualified_namespace="fake_resource.servicebus.windows.net/", schemaregistry_group="fakegroup")

class SchemaRegistryAvroSerializerTests(AzureTestCase):
class AvroSerializerTests(AzureTestCase):

def test_raw_avro_serializer(self):
schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
Expand Down Expand Up @@ -78,7 +78,7 @@ def test_raw_avro_serializer_negative(self):
def test_basic_sr_avro_serializer_with_auto_register_schemas(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs):
# TODO: AFTER RELEASING azure-schemaregistry=1.0.0b3, UPDATE 'endpoint' to 'fully_qualified_namespace'
sr_client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_fully_qualified_namespace)
sr_avro_serializer = SchemaRegistryAvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True)
sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group, auto_register_schemas=True)

schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
schema = avro.schema.parse(schema_str)
Expand All @@ -103,7 +103,7 @@ def test_basic_sr_avro_serializer_with_auto_register_schemas(self, schemaregistr
def test_basic_sr_avro_serializer_without_auto_register_schemas(self, schemaregistry_fully_qualified_namespace, schemaregistry_group, **kwargs):
# TODO: AFTER RELEASING azure-schemaregistry=1.0.0b3, UPDATE 'endpoint' to 'fully_qualified_namespace'
sr_client = self.create_basic_client(SchemaRegistryClient, endpoint=schemaregistry_fully_qualified_namespace)
sr_avro_serializer = SchemaRegistryAvroSerializer(client=sr_client, group_name=schemaregistry_group)
sr_avro_serializer = AvroSerializer(client=sr_client, group_name=schemaregistry_group)

schema_str = """{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""
schema = avro.schema.parse(schema_str)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore

0 comments on commit 6b33654

Please sign in to comment.