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

JSON: function "query" #157

Merged
merged 55 commits into from
May 8, 2024
Merged

Conversation

ralfhandl
Copy link
Contributor

@ralfhandl ralfhandl commented Sep 27, 2021

Resolves https://issues.oasis-open.org/browse/ODATA-1336

Check which syntax elements are supported by which implementation

@ralfhandl ralfhandl marked this pull request as draft September 27, 2021 15:46
@ralfhandl ralfhandl self-assigned this Sep 29, 2021
@ralfhandl ralfhandl marked this pull request as ready for review October 1, 2021 12:45
vocabularies/Org.OData.JSON.V1.xml Outdated Show resolved Hide resolved
HeikoTheissen
HeikoTheissen previously approved these changes Mar 14, 2024
@HeikoTheissen
Copy link
Contributor

HeikoTheissen commented Mar 15, 2024

The proposed OData function JSON.value can instead be implemented with the SQL function JSON_QUERY, which returns a stringified JSON

But if JSON.value occurs in a common expression, SQL cannot parse the stringified JSON for each row. Therefore

$filter=resume/JSON.value('$.birthYear') gt ReceivedYear sub 18

(to find applications by under-age candidates) would be converted into

where JSON_VALUE(Stream, '$.birthYear') >= "ReceivedYear" - 18

which makes sense if the implicit casting rules for OData common expressions are the same as for SQL.

But

$compute=resume/JSON.value('$.birthYear') as BirthYear

could then not be converted into SQL without parsing JSON, since BirthYear must be numeric.

Perhaps it is better to have three functions:

  • JSON.value returns the string computed by JSON_VALUE
  • JSON.query returns a JSON.JSON as computed by JSON_QUERY
  • JSON.parsedquery returns a JSON.JSON for JSON objects but a primitive value like Edm.String or Edm.Boolean otherwise. It does so by parsing the stringified JSON returned by JSON_QUERY. This could be used in the $compute example above, but probably not be part of a bigger common expression.

@HeikoTheissen HeikoTheissen dismissed their stale review March 15, 2024 07:14

Doubts about $compute

@HeikoTheissen HeikoTheissen linked an issue Apr 3, 2024 that may be closed by this pull request
Copy link
Contributor

@HeikoTheissen HeikoTheissen left a comment

Choose a reason for hiding this comment

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

TC 2024-04-03 agrees to have return-type-specific functions JSON.stringValue, JSON.intValue etc.

@mikepizzo
Copy link
Contributor

mikepizzo commented Apr 3, 2024

Alternative: single JSON_QUERY function with optional 3rd parameter that specified return type. The type of this function would have to be Edm.Untyped; may still have to cast to compose in expression.

Other alternative: have different functions for each type to be returned, thus avoiding the cast.

It would be more extensible to pass a type name to return as, but then the return type of the function would not be strongly typed (it would have to be Edm.Untyped) so it would have to be cast in an expression/annotated in a response.

If there are only a handful of types that may be returned, we can define separate functions for each return type which would improve usability.

vocabularies/Org.OData.JSON.V1.xml Outdated Show resolved Hide resolved
vocabularies/Org.OData.JSON.V1.xml Outdated Show resolved Hide resolved
Copy link
Contributor

@sthagen sthagen left a comment

Choose a reason for hiding this comment

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

LGTM.

@ralfhandl ralfhandl changed the base branch from main to v4.02-release-candidate April 17, 2024 16:28
@ralfhandl ralfhandl merged commit 4b3d0bd into v4.02-release-candidate May 8, 2024
1 check passed
@ralfhandl ralfhandl deleted the ODATA-1336/json-query branch May 8, 2024 16:47
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.

Querying "JSON properties"
5 participants