Skip to content
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

[SchemaRegistry] update positional args to req kwargs #20763

Merged
merged 8 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
- `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.
- The following positional arguments are now required keyword arguments:
- `client` and `group_name` in `SchemaRegistryAvroSerializer` constructor
- `schema` in `serialize` on `SchemaRegistryAvroSerializer`

### Bugs Fixed

- `value` parameter in `serialize` on `SchemaRegistryAvroSerializer` takes type `Mapping` rather than `Dict`.
swathipil marked this conversation as resolved.
Show resolved Hide resolved

### Other Changes

## 1.0.0b2 (2021-08-18)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#
# --------------------------------------------------------------------------
from io import BytesIO
from typing import Any, Dict, Union
from typing import Any, Dict, Union, Mapping
import avro

from ._constants import SCHEMA_ID_START_INDEX, SCHEMA_ID_LENGTH, DATA_START_INDEX
Expand All @@ -36,20 +36,23 @@ class SchemaRegistryAvroSerializer(object):
SchemaRegistryAvroSerializer provides the ability to serialize and deserialize data according
to the given avro schema. It would automatically register, get and cache the schema.

:param client: The schema registry client
:keyword client: Required. The schema registry client
which is used to register schema and retrieve schema from the service.
:type client: ~azure.schemaregistry.SchemaRegistryClient
:param str group_name: Schema group under which schema should be registered.
:paramtype client: ~azure.schemaregistry.SchemaRegistryClient
:keyword str group_name: Required. Schema group under which schema should be registered.
:keyword bool auto_register_schemas: When true, register new schemas passed to serialize.
Otherwise, and by default, fail if it has not been pre-registered in the registry.

"""

def __init__(self, client, group_name, **kwargs):
# type: ("SchemaRegistryClient", str, Any) -> None
self._schema_group = group_name
def __init__(self, **kwargs):
# type: (Any) -> None
try:
self._schema_group = kwargs.pop("group_name")
self._schema_registry_client = kwargs.pop("client") # type: "SchemaRegistryClient"
except KeyError as e:
raise ValueError("'{}' is a required keyword.".format(e.args[0]))
swathipil marked this conversation as resolved.
Show resolved Hide resolved
self._avro_serializer = AvroObjectSerializer(codec=kwargs.get("codec"))
self._schema_registry_client = client # type: "SchemaRegistryClient"
self._auto_register_schemas = kwargs.get("auto_register_schemas", False)
self._auto_register_schema_func = (
self._schema_registry_client.register_schema
Expand Down Expand Up @@ -119,20 +122,23 @@ def _get_schema(self, schema_id, **kwargs):
self._schema_to_id[schema_str] = schema_id
return schema_str

def serialize(self, value, schema, **kwargs):
# type: (Dict[str, Any], Union[str, bytes], Any) -> bytes
def serialize(self, value, **kwargs):
# type: (Mapping[str, Any], Any) -> bytes
"""
Encode data with the given schema. The returns bytes are consisted of: The first 4 bytes
denoting record format identifier. The following 32 bytes denoting schema id returned by schema registry
service. The remaining bytes are the real data payload.

:param value: The data to be encoded.
:type value: Dict[str, Any]
:param schema: The schema used to encode the data.
:type schema: str
:type value: Mapping[str, Any]
:keyword schema: Required. The schema used to encode the data.
:paramtype schema: str
:rtype: bytes
"""
raw_input_schema = schema
try:
raw_input_schema = kwargs.get("schema")
except KeyError as e:
raise ValueError("'{}' is a required keyword.".format(e.args[0]))
swathipil marked this conversation as resolved.
Show resolved Hide resolved
try:
cached_schema = self._user_input_schema_cache[raw_input_schema]
except KeyError:
Expand Down
6 changes: 5 additions & 1 deletion sdk/schemaregistry/azure-schemaregistry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
- `group_name`, which has been renamed from `schema_group`
- `name`, which has been renamed from `schema_name`
- `content`, which has been renamed from `schema_content`
- `serialization_type`
- `format`, which has been renamed from `serialization_type`
- `location` instance variable in `SchemaProperties` has been removed.
- The following positional arguments are now required keyword arguments:
- `id`, `serialization_type`, and `version` on `SchemaProperties`
- `content` and `properties` on `Schema`
swathipil marked this conversation as resolved.
Show resolved Hide resolved

### Bugs Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
from typing import Any, Optional
from typing import Any


class SchemaProperties(object):
"""
Meta properties of a schema.

:ivar id: References specific schema in registry namespace.
:type id: str
:ivar location: URL location of schema, identified by schema group, schema name, and version.
:type location: str
:ivar serialization_type: Serialization type for the schema being stored.
:type serialization_type: str
:ivar version: Version of the returned schema.
:type version: int
:keyword id: Required. References specific schema in registry namespace.
:paramtype id: str
:keyword serialization_type: Required. Serialization type for the schema being stored.
:paramtype serialization_type: str
:keyword version: Required. Version of the returned schema.
:paramtype version: int

.. admonition:: Example:

Expand All @@ -52,24 +50,26 @@ class SchemaProperties(object):

def __init__(
self,
id=None, # pylint:disable=redefined-builtin
**kwargs
):
# type: (Optional[str], Any) -> None
self.id = id
self.location = kwargs.get('location')
self.serialization_type = kwargs.get('serialization_type')
self.version = kwargs.get('version')
# type: (Any) -> None
try:
self.id = kwargs.pop('id')
self.location = kwargs.pop('location')
self.serialization_type = kwargs.pop('serialization_type')
self.version = kwargs.pop('version')
except KeyError as e:
raise ValueError("'{}' is a required keyword.".format(e.args[0]))


class Schema(object):
"""
The schema content of a schema, along with id and meta properties.

:ivar content: The content of the schema.
:type content: str
:ivar properties: The properties of the schema.
:type properties: SchemaProperties
:keyword content: Required. The content of the schema.
:paramtype content: str
:keyword properties: Required. The properties of the schema.
:paramtype properties: SchemaProperties

.. admonition:: Example:

Expand All @@ -84,9 +84,11 @@ class Schema(object):

def __init__(
self,
content,
properties,
**kwargs
):
# type: (str, SchemaProperties) -> None
self.content = content
self.properties = properties
# type: (Any) -> None
try:
self.content = kwargs.pop("content")
self.properties = kwargs.pop("properties")
except KeyError as e:
raise ValueError("'{}' is a required keyword.".format(e.args[0]))