Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devmanuelli
Copy link

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
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