@@ -259,15 +259,19 @@ class AvroDeserializer(Deserializer):
259
259
from_dict (callable, optional): Callable(dict, SerializationContext) -> object.
260
260
Converts dict to an instance of some object.
261
261
262
+ return_record_name (bool): If True, when reading a union of records, the result will
263
+ be a tuple where the first value is the name of the record and the second value is
264
+ the record itself. Defaults to False.
265
+
262
266
See Also:
263
267
`Apache Avro Schema Declaration <https://avro.apache.org/docs/current/spec.html#schemas>`_
264
268
265
269
`Apache Avro Schema Resolution <https://avro.apache.org/docs/1.8.2/spec.html#Schema+Resolution>`_
266
270
267
271
"""
268
- __slots__ = ['_reader_schema' , '_registry' , '_from_dict' , '_writer_schemas' ]
272
+ __slots__ = ['_reader_schema' , '_registry' , '_from_dict' , '_writer_schemas' , '_return_record_name' ]
269
273
270
- def __init__ (self , schema_registry_client , schema_str = None , from_dict = None ):
274
+ def __init__ (self , schema_registry_client , schema_str = None , from_dict = None , return_record_name = False ):
271
275
self ._registry = schema_registry_client
272
276
self ._writer_schemas = {}
273
277
@@ -278,6 +282,10 @@ def __init__(self, schema_registry_client, schema_str=None, from_dict=None):
278
282
" from_dict(SerializationContext, dict) -> object" )
279
283
self ._from_dict = from_dict
280
284
285
+ self ._return_record_name = return_record_name
286
+ if not isinstance (self ._return_record_name , bool ):
287
+ raise ValueError ("return_record_name must be a boolean value" )
288
+
281
289
def __call__ (self , value , ctx ):
282
290
"""
283
291
Decodes a Confluent Schema Registry formatted Avro bytes to an object.
@@ -321,7 +329,8 @@ def __call__(self, value, ctx):
321
329
322
330
obj_dict = schemaless_reader (payload ,
323
331
writer_schema ,
324
- self ._reader_schema )
332
+ self ._reader_schema ,
333
+ self ._return_record_name )
325
334
326
335
if self ._from_dict is not None :
327
336
return self ._from_dict (obj_dict , ctx )
0 commit comments