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 EF.Functions.JsonExists(expression, path) DbFunction #35389

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

Conversation

mseada94
Copy link
Contributor

@mseada94 mseada94 commented Dec 27, 2024

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

TODO

  • Define relational level EF.Functions.JsonExists DbFunction
  • Define SqlServer translation
  • Define Sqllite translation
  • Add test for constant json expression translation success
  • Add test for column (string) json expression translation success
  • Add test for column (owned) json expression translation success
  • Add test for column (string value converter) json expression translation success
  • Add test for column (not of the previous types) json expression translation failure
  • Add function test for 3 cases of the result (true, false, null)

Design notes:

  • The json expression is being tested before translation to allows only
    • String expressions (column, constant, complex)
    • Owned JSON column expression
    • Column with string value converter expression
  • In SQL Server, EF.Functions.JsonExists translate to JSON_PATH_EXISTS function which require SQL Server 2022.
  • In SQLite, EF.Functions.JsonExists translate to the following expression using JSON_TYPE function, as the best available equivalent for JsonExists at the moment.
    IIF(arguments_0 IS NULL, NULL, JSON_TYPE(arguments_0, arguments_1) IS NOT NULL)
CASE 
    WHEN arguments_0 IS NOT NULL THEN JSONT_YPE(arguments_0, arguments_1) IS NOT NULL
    ELSE NULL
END
  • The nullability of the second argument is not considered, generally user should not use null json path when calling this function
    • In SQL Server there will be an error
    • In SQLite JSON_TYPE will return NULL which will result in FALSE to be returned from this expression

@mseada94 mseada94 changed the title Add EF.JsonExists(expression, path) DbFunction Add EF.Functions.JsonExists(expression, path) DbFunction Dec 27, 2024
- Define SqlServer translation
- Define Sqllite translation

Fixes dotnet#31136
@mseada94 mseada94 force-pushed the feature/json-exists branch from 8689dd9 to 48692ba Compare December 27, 2024 19:05
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.

Relational method for checking whether a path in a JSON exists
2 participants