You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2019/04/30 19:41:42 UTC

[pulsar] branch master updated: Handle subrecords in complex types (#4050)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 4b3fb0c  Handle subrecords in complex types (#4050)
4b3fb0c is described below

commit 4b3fb0c1cd4c2c66f078e2f1274300ce3341f67b
Author: Yoann Ciabaud <yc...@users.noreply.github.com>
AuthorDate: Tue Apr 30 21:41:38 2019 +0200

    Handle subrecords in complex types (#4050)
---
 pulsar-client-cpp/python/pulsar/schema/definition.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pulsar-client-cpp/python/pulsar/schema/definition.py b/pulsar-client-cpp/python/pulsar/schema/definition.py
index 7610e7f..6491be3 100644
--- a/pulsar-client-cpp/python/pulsar/schema/definition.py
+++ b/pulsar-client-cpp/python/pulsar/schema/definition.py
@@ -65,6 +65,9 @@ class Record(with_metaclass(RecordMeta, object)):
             if k in kwargs:
                 # Value was overridden at constructor
                 self.__setattr__(k, kwargs[k])
+            elif isinstance(value, Record):
+                # Value is a subrecord
+                self.__setattr__(k, value)
             else:
                 # Set field to default value
                 self.__setattr__(k, value.default())
@@ -195,7 +198,8 @@ class Array(Field):
     def schema(self):
         return {
             'type': self.type(),
-            'items': self.array_type.type()
+            'items': self.array_type.schema() if isinstance(self.array_type, Record) 
+                else self.array_type.type()
         }
 
 
@@ -211,5 +215,6 @@ class Map(Field):
     def schema(self):
         return {
             'type': self.type(),
-            'values': self.value_type.type()
+            'values': self.value_type.schema() if isinstance(self.value_type, Record)
+                else self.value_type.type()
         }