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