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

AVRO-4026: [c++] Allow non-string custom attributes in schemas #3069

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jmd-z
Copy link

@jmd-z jmd-z commented Aug 6, 2024

Custom attributes are encoded as JSON to avoid ambiguity with simple string values.

What is the purpose of the change

Fixes exception from C++ library when compiling schemas with non-string custom attributes.

Verifying this change

This change added tests and can be verified as follows:

  • Added test that compiles a schema with a non-string custom attribute

Documentation

  • Does this pull request introduce a new feature? yes
  • If yes, how is the feature documented? not documented

…m attributes are JSON string to avoid ambiguity
@github-actions github-actions bot added the C++ Pull Requests for C++ binding label Aug 6, 2024
Copy link
Contributor

@pascalginter pascalginter left a comment

Choose a reason for hiding this comment

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

LGTM
I would be happy to see this PR revived and eventually merged

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: format the json over more lines for better readability

@martin-g
Copy link
Member

@Gerrit0 @mkmkme Do you want to review too ?

Copy link
Contributor

@mkmkme mkmkme left a comment

Choose a reason for hiding this comment

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

LGTM!

"\"mapField\": \"{\\\"key1\\\":\\\"value1\\\", \\\"key2\\\":\\\"value2\\\"}\", "
"\"nullField\": \"null\", "
"\"numberField\": \"1.23\", "
"\"arrayField\": [1], "
Copy link
Member

Choose a reason for hiding this comment

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

Looking at these changes I think this change may break someone's application.
Do we want to support a backward compatible encoding via some property/setting/... ?

@jmd-z
Copy link
Author

jmd-z commented Sep 26, 2024 via email

@martin-g
Copy link
Member

Perhaps renaming the function CustomAttributes::getAttributes to CustomAttributes::getAttributesJSON would do the same here.

Perhaps this would be the best!
In my experience (Java and Rust) the best is to keep the old behavior as deprecated and introduce a new one as the recommended. In a later version, e.g. 1.13.0, the deprecated method could be removed.

@pascalginter
Copy link
Contributor

It seems that everyone involved in this discussion agrees with @jmd-z's proposal, and the PR could be merged once the change is implemented. @jmd--z, do you have time to make the small adjustment?

@johd01
Copy link

johd01 commented Nov 19, 2024

looking forward for this fix to be merged!

@erikgustavalm
Copy link

looking forward for this fix to be merged!

second this.
Would make my ugly hack obsolete and not a day too soon.

@martin-g
Copy link
Member

Do we wait for an improvement here (deprecate the old methods and introduce new ones) ?
Or the community is happy with the current solution ?

@mkmkme
Copy link
Contributor

mkmkme commented Nov 25, 2024

@martin-g IIUC others were waiting for the improvement.
If @jmd-z doesn't have time to do this, I can do this

@martin-g
Copy link
Member

Help is always welcome!

@jhump
Copy link

jhump commented Dec 16, 2024

Before I stumbled upon this issue (and the associated JIRA issue), I had made a patch similar to what's proposed -- but instead of just renaming methods to make it more clear that they are JSON-encoded, I had actually added new methods. I just opened a PR with that change (#3266), however I'm more than happy to close that PR if the change in this one is preferred.

Is this PR's merge being held up only for renaming the methods to have a "JSON" suffix? If we wanted to keep the old ones and just add new ones, that ends up looking a lot like the PR I just opened. I'd just need to mark the old methods deprecated in my branch.

@martin-g
Copy link
Member

Is this PR's merge being held up only for renaming the methods to have a "JSON" suffix? If we wanted to keep the old ones and just add new ones, that ends up looking a lot like the PR I just opened. I'd just need to mark the old methods deprecated in my branch.

I didn't compare this PR against #3266 but yes, the requested change here is to keep the old API as deprecated and introduce new methods which behave better.

@jhump
Copy link

jhump commented Dec 17, 2024

@martin-g, I would happily see @jmd-z's change (this PR) merge, since he put the effort into it first. @jmd-z, do you plan to make these changes? It's been a few months since your last comment.

In the meantime, since we cannot push a commit to their branch to help push this forward, I have made changes in my own branch. Perhaps my PR (#3266) could be considered as an alternative if we don't hear back from @jmd-z? It deprecates all of the old string-only methods (addAttribute, getAttribute, and attributes) and introduces alternatives where the value is JSON-encoded and string values must be quoted and escaped (addAttributeJson, getAttributeJson, and jsonAttributes). It is, obviously, very similar to the change here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ Pull Requests for C++ binding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants