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

Add JSON support functions #841

Closed
beikov opened this issue Sep 14, 2019 · 3 comments · Fixed by #1135
Closed

Add JSON support functions #841

beikov opened this issue Sep 14, 2019 · 3 comments · Fixed by #1135

Comments

@beikov
Copy link
Member

beikov commented Sep 14, 2019

I'd like add cast functions for json and jsonb as well as add support for dereferencing a json attribute via normal path navigation I.e. jsonAttribute.person.age

In order to make this happen, we need a json metamodel in java that we can query to know what to cast a result to and to decide if a specific navigation operation is allowed. Maybe we could also support that without a model but then the user would have to do casts of the final values.

Using json access functions multiple times in a more complex expression could become inefficient, so we might want to consider wrapping jsonish expressions in a special function that takes care of optimizing this.

Selecting sub-objects of the JSON type should be possible by making use of a JSON binding provider in an internal ObjecBuilder.

In addition we can take a look at adding support for other json functions as well like e.g. functions for adding or removing objects from a JSON object.

This is blocked by #765 which will enable us to model foreign model structures and allow to easily de-reference it.

@jwgmeligmeyling
Copy link
Collaborator

jwgmeligmeyling commented Sep 15, 2019

How do you want to detect whether a field maps to a JSON column? Mapping a JSON or JSONB field requires a custom type. Personally I use JsonBinaryType from vladmihalcea/hibernate-types , which is Jackson based. I am also working on a PR that will provide an alternative that is JSON-P/JSON-B based: vladmihalcea/hypersistence-utils#112 . Perhaps though we can determine the columnDefinition from the metamodel (although DDL annotations are hidden away pretty well unfortunately...) or possibly we can even retrieve the actual type from the database schema.

FWIW Many of the JSON functions require the JSON type to be JSONB, I think this already addresses your performance concern for nested operations.

@beikov
Copy link
Member Author

beikov commented Sep 15, 2019

I'm not sure if the json type implementation vlad provides is sufficient, but we will see. I'd like to support it at least so that users don't have to switch types immediately.

I was thinking about using the colum definition or a custom annotation on the entity attribute to detect that.

The performance concern I have is about accessing a json field multiple times although it might be possible to use a function that operates on the whole json in a single context similar to what XQuery can do for XML. We'd have to test if using JSONB will help with that, but for text based columns it's definitely worth looking into optimizing this.

Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 20, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 20, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 20, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 20, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 20, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 20, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 20, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 20, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 21, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 21, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 21, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 21, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 22, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 22, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Jul 22, 2020
Mobe91 added a commit to Mobe91/blaze-persistence that referenced this issue Aug 19, 2020
beikov pushed a commit that referenced this issue Sep 2, 2020
@beikov beikov added this to the 1.5.0 milestone Sep 2, 2020
@beikov beikov changed the title Add JSON support functions and path navigation support Add JSON support functions Sep 2, 2020
@beikov
Copy link
Member Author

beikov commented Sep 2, 2020

I moved the navigation part into #1155

beikov pushed a commit to beikov/blaze-persistence that referenced this issue Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants