Repository navigation
PATHS/VALUES w/ WHERE & $ + has operator - #644
devmanuelli wants to merge 11 commits into
Conversation
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
1d9f69c to
8c65b90
Compare
- 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
| 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
| */ | ||
| public void bind( Candidate candidate ) { | ||
| switch( target ) { | ||
| case VariablePathTarget(var path) -> { |
Check notice
Code scanning / CodeQL
Unread local variable Note
| nextToken(); | ||
| break; | ||
| case INT: | ||
| long idx = Long.parseLong( token.content() ); |
Check notice
Code scanning / CodeQL
Missing catch of NumberFormatException Note
|
|
||
| R visit( ConstantStringExpression n, C ctx ); | ||
|
|
||
| R visit( CurrentValueNode n, C ctx ); |
Check notice
Code scanning / CodeQL
Useless parameter Note
|
|
||
| R visit( CurrentValueNode n, C ctx ); | ||
|
|
||
| R visit( PathsExpressionNode n, C ctx ); |
Check notice
Code scanning / CodeQL
Useless parameter Note
|
|
||
| R visit( PathsExpressionNode n, C ctx ); | ||
|
|
||
| R visit( ValuesExpressionNode n, C ctx ); |
Check notice
Code scanning / CodeQL
Useless parameter Note
|
|
||
| R visit( ValuesExpressionNode n, C ctx ); | ||
|
|
||
| R visit( PvalExpressionNode n, C ctx ); |
Check notice
Code scanning / CodeQL
Useless parameter Note
|
|
||
| R visit( PvalExpressionNode n, C ctx ); | ||
|
|
||
| R visit( PvalAssignStatement n, C ctx ); |
Check notice
Code scanning / CodeQL
Useless parameter Note
|
|
||
| R visit( PvalAssignStatement n, C ctx ); | ||
|
|
||
| R visit( PvalDeepCopyStatement n, C ctx ); |
Check notice
Code scanning / CodeQL
Useless parameter Note
Implements PATHS and VALUES expressions for querying data structures:
Example: paths tree..field[].[4] where $.field2[].[*] has "field3"
Key components: