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

[Python Client] Fix handle complex schema #11400

Merged

Conversation

gaoran10
Copy link
Contributor

@gaoran10 gaoran10 commented Jul 20, 2021

Fixes #7785, #11221

Motivation

Currently, the Pulsar python client couldn't handle complex schema, users using complex schema will encounter errors.

Modifications

Fix AvroSchema encodes and decodes complex schema.
Fix JsonSchema decodes complex schema.

Verifying this change

This change added tests and can be verified as follows:

  • Encode and decode complex schema data
  • Produce and consume complex schema data

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (yes)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

@gaoran10 gaoran10 added the doc-not-needed Your PR changes do not impact docs label Jul 20, 2021
@gaoran10 gaoran10 self-assigned this Jul 20, 2021
@Anonymitaet
Copy link
Member

Thanks for your contribution. For this PR, do we need to update docs?

(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

obj = {}
for k, v in d.items():
if isinstance(v, Record):
obj[k] = self.encode_dict(v.__dict__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check could also be don in the _get_serialized_value() method:

def _get_serialized_value(self, x):
            if isinstance(x, enum.Enum):
                return x.name
            elif isinstance(x, Record):
                self.encode_dict(x.__dict__)
            else:
                return x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this. PTAL

@@ -56,15 +57,20 @@ def _get_fields(cls, dct):

class Record(with_metaclass(RecordMeta, object)):

def __init__(self, default=None, required_default=False, required=False, *args, **kwargs):
def __init__(self, default=None, required_default=False, required=False, decode=False, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not easy to understand what is the meaning of decode=False|True here. Also these arguments are exposed to the users (eg: marking a field as "required"), do we need to expose this decode too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not necessary, I remove the param decode.

@sijie sijie added this to the 2.9.0 milestone Jul 22, 2021
@codelipenghui
Copy link
Contributor

@gaoran10 Please rebase to the master branch to make the CI gets passed.

@gaoran10 gaoran10 force-pushed the fix-python-client-complex-schema branch from 377a12a to 64a56c0 Compare July 22, 2021 03:32
@codelipenghui codelipenghui merged commit 2370643 into apache:master Jul 22, 2021
@gaoran10 gaoran10 deleted the fix-python-client-complex-schema branch July 22, 2021 14:11
Technoboy- pushed a commit to Technoboy-/pulsar that referenced this pull request Jul 22, 2021
Fixes apache#7785, apache#11221

### Motivation

Currently, the Pulsar python client couldn't handle complex schema, users using complex schema will encounter errors.

### Modifications

Fix AvroSchema encodes and decodes complex schema.
Fix JsonSchema decodes complex schema.

### Verifying this change

This change added tests and can be verified as follows:

  - *Encode and decode complex schema data*
  - *Produce and consume complex schema data*
codelipenghui pushed a commit that referenced this pull request Jul 23, 2021
Fixes #7785, #11221

### Motivation

Currently, the Pulsar python client couldn't handle complex schema, users using complex schema will encounter errors.

### Modifications

Fix AvroSchema encodes and decodes complex schema.
Fix JsonSchema decodes complex schema.

### Verifying this change

This change added tests and can be verified as follows:

  - *Encode and decode complex schema data*
  - *Produce and consume complex schema data*

(cherry picked from commit 2370643)
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Jul 23, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Fixes apache#7785, apache#11221

### Motivation

Currently, the Pulsar python client couldn't handle complex schema, users using complex schema will encounter errors.

### Modifications

Fix AvroSchema encodes and decodes complex schema.
Fix JsonSchema decodes complex schema.

### Verifying this change

This change added tests and can be verified as follows:

  - *Encode and decode complex schema data*
  - *Produce and consume complex schema data*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure of the Avro Serialization for Complex Types in the Python Client
5 participants