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

Feature/odata compact json #644

Closed

Conversation

gbryant-dev
Copy link
Contributor

@gbryant-dev gbryant-dev commented Nov 14, 2021

Introduces the option to use compact JSON format when querying cellsets. Beneficial when querying large amounts of data and / or remote environments where network latency is typically higher.

Implemented through a new odata_compact_json decorator which handles the header and maps the data back to the cellset properties based on the odata context. Whether the properties are returned is based on return_props_with_data is True. The odata context returned in the response is used to parse the response. Currently only supports requests that query only cell properties (see notes in decorator function).

Core low level extract functions have been decorated, namely extract_cellset_raw and extract_cellset_values. Some refactoring was required, particularly with the former to separate the metadata and cell calls.

A new parameter use_compact_json has been added to all of the relevant functions. Defaults to False.

A couple of reservations / thoughts I have on the approach:

  • Updating the Accept header - It's a little tricky because positioning matters and it needs to come after application/json. The default header defined in the RestService is application/json;odata.metadata=none,text/plain and in order to use the compact JSON format, it would be application/json;tm1.compact=v0;odata.metadata=none,text/plain. I've taken the approach of inserting the header in the right place as opposed to assuming what the default header contains and setting a new one directly.

  • Using compact JSON for metadata calls - It would be nice to be able to support this as well. However, the odata context only contains properties explicitly asked for on each Entity and doesn't include properties that are returned by default e.g a request to Cellsets('...')?$expand=Axes would lead to an odata context of $metadata#Cellsets(Axes)/$entity but Ordinal and Cardinality properties would be included in the response by default. In order to parse the response correctly, the odata context would need to be $metadata#Cellsets(Axes(Ordinal,Cardinality)/$entity. In order to implement fully, based on what I know so far, besides the parser being very robust to handle all the variations and navigation options, possible workarounds could be to:

    • Ensure all requests specify properties for each Entity, expand options included.
    • Hold a lookup to the default properties for each Entity

I'm not a fan of either approach really but the 1st option would appear to be more in our control. That being said, I think this PR is a good start so maybe something we come back to.

Thanks,
George

@rclapp
Copy link
Collaborator

rclapp commented Nov 14, 2021 via email

@MariusWirtz
Copy link
Collaborator

Thank you @gbryant-dev. This looks like more than a good start!

I kinda think we should have been explicit about the expands from the beginning, anyways. I wouldn't mind doing a quick refactoring exercise to tidy this up.

I will provide more feedback and help with the code this week after the other open MR is merged.

@gbryant-dev
Copy link
Contributor Author

gbryant-dev commented Nov 24, 2021

Thanks @MariusWirtz and apologies for the late follow up.

Agree with being explicit when requesting properties for each entity. I think we would need to go down this road in order to utilise compact JSON fully. My initial reservation was around the governance to ensure it's enforced across all the current and new functions in the CellService that use the decorator. That said, using the decorator is an opt-in approach so as long as it's clear that the decorated function is required to specify properties in the request, I think that covers it.

I've pushed a couple of more commits to tidy up a bit and do some renaming so hopefully the utility functions make more sense but I welcome your feedback on this.

I would like to take the opportunity to write some tests but I likely won't get round to that for a couple of weeks yet so don't wait for me on that. What I have done on testing so far is run the unit tests for the CellService using pytest and done some manual testing on running functions with compact_json=True. All tests passed which is good news.

@MariusWirtz
Copy link
Collaborator

Very nice work. I like the approach to using a decorator to manage the header. The Utils functions look very tidy too.

I have started to go through the code and to solve the conflicts between this and #612.
I will provide feedback in this thread and open a Pull Request into this branch to solve the conflicts over the next few days.

Agree. It would be nice to have some tests for it. Also for the Utils functions.

@MariusWirtz
Copy link
Collaborator

I am currently working to resolve the conflicts, and I think maybe we should harmonize the naming of the two new features.
Currently the two new arguments are called: iterative_json_parsing and use_compact_json.

I think it would be nice if we called them either:

  • use_iterative_json_parsing and use_compact_json
  • or iterative_json_parsing and compact_json

Does anyone have preferences? Or other suggestions?

@gbryant-dev
Copy link
Contributor Author

I think the use_ convention makes more sense in this case. There are also two other arguments used in the CellService that align with this - use_ti and use_changeset.

@rclapp
Copy link
Collaborator

rclapp commented Dec 2, 2021 via email

@MariusWirtz
Copy link
Collaborator

Substituted by #650

@MariusWirtz MariusWirtz closed this Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants