8000 PATHS/VALUES w/ WHERE & $ + has operator by devmanuelli · Pull Request #644 · jolie/jolie · GitHub
[go: up one dir, main page]

Skip to content

PATHS/VALUES w/ WHERE & $ + has operator - #644

Draft
devmanuelli wants to merge 11 commits into
jolie:masterfrom
devmanuelli:feature/paths
Draft

devmanuelli wants to merge 11 commits into
jolie:masterfrom
devmanuelli:feature/paths

Conversation

@devmanuelli
Copy link
Copy Markdown

Implements PATHS and VALUES expressions for querying data structures:

  • paths data[*] where $ > 5 → returns matching paths
  • values data[*] where $ > 5 → returns matching values
  • $ with composable path navigation: $.[], $..field, $[n], $[*]
  • HAS operator: where $ has "field" checks field existence
  • Existential semantics: ANY value matches (∃), not all

Example: paths tree..field[].[4] where $.field2[].[*] has "field3"

Key components:

  • PathsExpression/ValuesExpression (runtime evaluation)
  • CurrentValueExpression ($ with path operations)
  • WhereEvaluator (existential WHERE clause evaluation)
  • ValueNavigator (tree traversal with path operations)
  • PathOperation sealed interface (6 composable operation types)
  • Candidate record (vector + index + path for navigation)

Implements PATHS and VALUES expressions for querying data structures:
- paths data[*] where $ > 5 → returns matching paths
- values data[*] where $ > 5 → returns matching values
- $ with composable path navigation: $.*[*], $..field, $[n], $[*]
- HAS operator: where $ has "field" checks field existence
- Existential semantics: ANY value matches (∃), not all

Example: paths tree..field[*].*[4] where $.field2[*].*[*] has "field3"

Key components:
- PathsExpression/ValuesExpression (runtime evaluation)
- CurrentValueExpression ($ with path operations)
- WhereEvaluator (existential WHERE clause evaluation)
- ValueNavigator (tree traversal with path operations)
- PathOperation sealed interface (6 composable operation types)
- Candidate record (vector + index + path for navigation)
Added WHERE token and inWhereClause flag to prevent $ usage outside
WHERE clauses in PATHS/VALUES expressions.

Changes:
- Scanner: Added WHERE token type and unreserved keyword
- OLParser: Added inWhereClause flag with try-finally for safety
- Parser validates $ can only appear in WHERE clauses
- Error: "$ can only be used in WHERE clauses"
- primitives/paths_values.ol: basic array and nested field tests
- library/paths_values.ol: comprehensive tests with JSON data
  - founded year filters, city filters, recursive descent
  - existential checks ($..technologies[*]), has operator
  - complex AND/OR conditions
- ValuePath: new runtime class representing paths in data structures
- NativeType: add PATH("path") enum value
- Value: add isPath(), pathValue(), setValue(ValuePath), create(ValuePath)
- BasicType: add PATH_PREDICATE for type checking
- PathsExpression: return ValuePath values instead of strings
- Test: verify instanceof path and PathResult type checking
Implements pval(pathExpr) that dereferences a path value to get a
reference to the actual value. Supports path navigation suffix:
- pval(res.results[0]) → returns link to the value at the path
- pval(res.results[0]).child → navigates to child field
- pval(res.results[0]).children[n] → supports array indexing
- pval(res.results[0]).a.b[n].c → composite paths

Returns reference semantics (ValueLink), not deep copy like values.
Runtime type check throws TypeMismatch fault if input is not path type.

Reuses parsePathOperationsSuffix from PATHS/VALUES for path navigation.
Adds VariablePathBuilder.add(String) overload for fields without index.
- Add PvalAssignStatement AST node for pval(path).field = value
- Add PvalAssignmentProcess runtime for executing pval assignments
- Add PvalHelper utility class to share code between rvalue/lvalue
- Refactor PvalExpression to use PvalHelper
- Add visitor implementations across all OLVisitor implementers
- Add tryConvertValue helper in Type.check() for fast path optimization
- Fix reserved keyword conflict in assertions.ol (values -> valuesService)
This commit combines two related improvements to WHERE clause expressions:

1. Extend # operator to accept general expressions:
   - Allow #($.field) syntax in WHERE clauses for path-based size checks
   - Restrict # operator to VariablePath and CurrentValueExpression only
   - Add binding support for arithmetic expressions (SumExpression, ProductExpression)
   - Make ProductExpression/SumExpression children package-private for WhereEvaluator access

2. Fix NOT operator precedence bug:
   - Add parseNotExpression() method at correct precedence level
   - Update parseAndCondition() to call parseNotExpression()
   - Fix parser so !$ has "field" correctly parses as !($ has "field")
   - NOT now binds less tightly than HAS and comparison operators per formal grammar

Files modified:
- OOITBuilder.java: Restrict # to VariablePath and CurrentValueExpression
- ValueVectorSizeExpression.java: Update to use CurrentValueExpression exclusively
- WhereEvaluator.java: Add binding for arithmetic expressions
- ProductExpression.java, SumExpression.java: Make children package-private
- OLParser.java: Add parseNotExpression() and update # parsing
} catch( TypeCheckingException ex ) {
// ANY is not handled, because checkNativeType returns true for it anyway
switch( basicType.nativeType() ) {
switch( targetType ) {

Check warning

Code scanning / CodeQL

Missing enum case in switch Warning

Switch statement does not have a case for
ANY
.
if( i < 0 )
b.add( s );
else
b.add( s.substring( 0, i ), Integer.parseInt( s.substring( i + 1, s.length() - 1 ) ) );

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.
*/
public void bind( Candidate candidate ) {
switch( target ) {
case VariablePathTarget(var path) -> {

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'VariablePath path' is never read.
nextToken();
break;
case INT:
long idx = Long.parseLong( token.content() );

Check notice

Code scanning / CodeQL

Missing catch of NumberFormatException Note

Potential uncaught 'java.lang.NumberFormatException'.

R visit( ConstantStringExpression n, C ctx );

R visit( CurrentValueNode n, C ctx );

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'ctx' is never used.

R visit( CurrentValueNode n, C ctx );

R visit( PathsExpressionNode n, C ctx );

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'ctx' is never used.

R visit( PathsExpressionNode n, C ctx );

R visit( ValuesExpressionNode n, C ctx );

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'ctx' is never used.

R visit( ValuesExpressionNode n, C ctx );

R visit( PvalExpressionNode n, C ctx );

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'ctx' is never used.

R visit( PvalExpressionNode n, C ctx );

R visit( PvalAssignStatement n, C ctx );

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'ctx' is never used.

R visit( PvalAssignStatement n, C ctx );

R visit( PvalDeepCopyStatement n, C ctx );

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'ctx' is never used.
@fmontesi
fmontesi requested review from kicito and klag February 28, 2026 11:05
@mwallnoefer
mwallnoefer marked this pull request as draft May 8, 2026 17:04
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.

2 participants < 37AF /h3>

0