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

Relational method for checking whether a path in a JSON exists #31136

Open
roji opened this issue Jun 26, 2023 · 13 comments · May be fixed by #35389
Open

Relational method for checking whether a path in a JSON exists #31136

roji opened this issue Jun 26, 2023 · 13 comments · May be fixed by #35389
Labels
area-json area-query customer-reported good first issue This issue should be relatively straightforward to fix. type-enhancement
Milestone

Comments

@roji
Copy link
Member

roji commented Jun 26, 2023

All relational databases support some way of checking whether a given JSON PATH exists in a JSON document. We should add a relational-level EF.Functions.JsonExists (or similar) which the different providers can translate to this.

Database Function
PG jsonb_path_exists
SQL Server JSON_PATH_EXISTS (since SQL Server 2022)
SQLite json_type (returns NULL for non-existing path, as opposed to 'null' for JSON null values)
MariaDB JSON_EXISTS
MySQL JSON_CONTAINS_PATH
Oracle JSON_EXISTS
@joelmandell
Copy link

Depending on what happens with this PR #30010. I might continue with adding those as well...

@abcdefgabcefg
Copy link

Hi @roji as I see @joelmandell PR is stuck. I'd like to try to implement this by:

  1. Create JsonExists in RelationalDbFunctionsExtensions that throws an exception
  2. Create SqlServerJsonExistTranslator
  3. Create SqliteJsonExistTranslator
  4. Register translators at SqlServerMethodCallTranslatorProvider and SqlliteMethodCallTranslatorProvider accordingly
    I believe that will support JSON PATH for SQL Server and SQLite providers, but will throw an exception for any other relational provider unless their developers implement support for one.
    Can I do it?

@joelmandell
Copy link

@abcdefgabcefg I am just waiting for feedback on that PR before I started on the other things. That's why I am lagging behind

@roji
Copy link
Member Author

roji commented Sep 17, 2023

@joelmandell oh sorry, I don't I was aware you were waiting for feedback there... we've unfortunately gone into feature freeze for 8.0 so we won't be able to merge it for that...

@abcdefgabcefg
Copy link

@roji please tell, this issue is also frozen till EF 8?

@roji
Copy link
Member Author

roji commented Sep 20, 2023

EF 8 will be out in November, and feature work on it has stopped; we're now stabilizing/fixing bugs only. Any feature PR will generally be merged for EF 9 at this point, which will come out in November 2024.

@imangd
Copy link
Contributor

imangd commented Jun 4, 2024

Hi @roji , is this issue still open for contribution?

@roji
Copy link
Member Author

roji commented Jun 5, 2024

@Ricketiman and others, @joelmandell made good progress on this in #30010 - it's my fault it hasn't progressed. I'm generally trying to make progress on dormant PRs, I'll try to pick up this work again - I don't think it makes sense to start a new PR.

@sheikharfaz
Copy link

Hi @roji , Is this Issue still open for contribution?

@roji
Copy link
Member Author

roji commented Oct 1, 2024

Yes.

@mseada94
Copy link
Contributor

mseada94 commented Dec 18, 2024

Hi @roji , I would like to try working on this issue if it's open for contribution
what is the status of this PR #30010? I think it would be better if the common json functions added on the relational level as well not just JsonExists

@roji
Copy link
Member Author

roji commented Dec 19, 2024

what is the status of this PR #30010?

We're unfortunately backed up on processing community PRs; #30010 looks like it's in the right direction but we need to find some time to get it to mergeable state.

I think it would be better if the common json functions added on the relational level as well not just JsonExists

It's a good idea to do this method by method, since support across databases varies in this area. Definitely feel free to open more issues like this one, detailing the proposed translations across databases (see the origina post above).

@mseada94
Copy link
Contributor

@roji I will start working on JsonExists for now and after that creating issue with other function proposals and work on them one by one.

I will use case expression or iif for sqlite to maintain the same behavior as follow

CASE 
    WHEN [json_value] IS NULL THEN NULL
    ELSE json_type([json_value], [json_path]) IS NOT NULL
END
iif([json_value] IS NULL, NULL, json_type([json_value], [json_path]) IS NOT NULL)

mseada94 added a commit to mseada94/efcore that referenced this issue Dec 27, 2024
- Fixes dotnet#31136
- Define SqlServer translation
- Define Sqllite translation
@mseada94 mseada94 linked a pull request Dec 27, 2024 that will close this issue
15 tasks
mseada94 added a commit to mseada94/efcore that referenced this issue Dec 27, 2024
- Define SqlServer translation
- Define Sqllite translation

Fixes dotnet#31136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-json area-query customer-reported good first issue This issue should be relatively straightforward to fix. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants