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

JEP-19 Evaluation of Pipe Expressions #5

Merged
merged 1 commit into from
Dec 8, 2022

Conversation

springcomp
Copy link
Contributor

Evaluation of Pipe Expressions

JEP 19
Author Maxime Labelle
Created 29-October-2022
SemVer MINOR
Status Draft
[Discussion] #113

Abstract

This JEP introduces changes that outline the exact intended behaviour of evaluating a pipe-expression. It also clarifies an ambiguity when evaluating a sub-expression where the left-hand-side evaluates to null.

Motivation

Sub Expression Evaluation

The specification for sub-expression outlines how it should be evaluated using pseudocode:

left-evaluation = search(left-expression, original-json-document)
result = search(right-expression, left-evaluation)

This is slightly ambiguous, as many compliance tests expect the result to be null when the left-hand-side evaluates to  null. So, the real pseudocode shoud in fact be:

left-evaluation = search(left-expression, original-json-document)
if left-evaluation is `null` then result = `null`
else result = search(right-expression, left-evaluation)

Pipe Expression Evaluation

In contrast, however, it seems intuitive for pipe-expression to evaluate as was originally outlined by the first pseudocode fragment referred to a above.

left-evaluation = search(left-expression, original-json-document)
result = search(right-expression, left-evaluation)

Which means that the evaluation should still happens if the left-hand-side is null.

Specification

Sub Expressions

The paragraph on sub expressions in the specification will be updated as follows, with changes outlined in bold:

A subexpression is evaluted as follows:

  • Evaluate the expression on the left with the original JSON document.
  • If the result of the left expression evaluation is null, return null.
  • Otherwise, eEvaluate the expression on the right with the result of the left expression evaluation.

In pseudocode:

left-evaluation = search(left-expression, original-json-document)
If result is `null` the result = `null`
else result = search(right-expression, left-evaluation)

Pipe Expressions

Likewise the paragraph on pipe expressions in the specification will be updated as follows:

A pipe expression combines two expressions, separated by the | character. It is similar to a sub-expression with twothe following important distinctions:

  1. Any expression can be used on the right hand side. A sub-expression restricts the type of expression that can be used on the right hand side.
  2. A pipe-expression stops projections on the left hand side for from propagating to the right hand side. If the left expression creates a projection, it does not apply to the right hand side.
  3. A pipe-expression evaluates the right expression unconditionally. A sub-expression shortcuts evaluation if the result of the left expression evaluation is null

In pseudocode:

left-evaluation = search(left-expression, original-json-document)
result = search(right-expression, left-evaluation)

Example

Expression Result
`null` . [@] null
`` null ` [@] ``

Compliance

The pipe.json compliance test file will be updated with the example from this JEP.

@springcomp springcomp merged commit eca3c16 into develop Dec 8, 2022
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.

1 participant