Skip to content

As a user, I want the exists operator to be prepended to the queryΒ #727

@tloubrieu-jpl

Description

@tloubrieu-jpl

Checked for duplicates

No - I haven't checked

πŸ§‘β€πŸ”¬ User Persona(s)

User

πŸ’ͺ Motivation

...so that I can more intuitively use the exists operator with a syntax that reads naturally in English (prefix notation) and combine it cleanly with the not operator.

πŸ“– Additional Details

Feedback from the API Working Group meeting on 01-28-2026.

The current postfix syntax (implemented in #406) requires awkward constructions for negation:

  • Current (postfix): pds:Target/pds:name exists
  • Current negation: not (pds:Investigation/pds:stop_date_time exists)

The new prefix syntax is more intuitive and reads naturally:

  • New (prefix): (exists pds:Target/pds:name)
  • New negation: (not exists pds:Citation_Information/pds:author_list)

Examples of new syntax:

Use Case New Syntax
Check field exists (exists pds:Target/pds:name)
Check field does NOT exist (not exists pds:Investigation/pds:stop_date_time)
Regex pattern matching (exists "pds:Target.*")
Combined with other conditions (exists pds:Target/pds:name) and pds:Target/pds:type eq "Planet"
Complex query (exists pds:Target/pds:name) and (not exists pds:Citation_Information/pds:author_list)

Acceptance Criteria

Given I am querying the registry API
When I use (exists field_name) with the prefix syntax
Then the API returns only documents where the specified field exists and has a non-null/non-empty value

Given I am querying the registry API
When I use (not exists field_name) in my query
Then the API returns only documents where the specified field does not exist or is null/empty

Given I want to check for fields matching a regex pattern
When I use (exists "regex_pattern") with a quoted string
Then the API matches the regex against known field names and returns documents where any matched field exists

Given I combine exists with other query operators
When I use queries like (exists pds:Target/pds:name) and pds:Target/pds:type eq "Planet"
Then the API correctly applies both conditions and returns matching documents

βš™οΈ Engineering Details

This change requires updates to the ANTLR4 lexer grammar (Search.g4) in the lexer module:

  1. Grammar Changes: Modify the EXISTS rule from postfix to prefix notation:

    • Current grammar: comparison : FIELD EXISTS | STRINGVAL EXISTS | ...
    • New grammar: comparison : EXISTS FIELD | EXISTS STRINGVAL | ...
  2. Listener Updates: Update Antlr4SearchListener.java in the service module to handle the new parse tree structure where EXISTS precedes the field/pattern.

  3. NOT handling: Ensure NOT EXISTS works as a combined prefix operator (not just NOT wrapping the entire expression).

  4. Backward Compatibility: Determine whether to support both syntaxes during a transition period or deprecate the postfix syntax immediately.

  5. Integration Tests: Update Postman collection in the registry repository with tests for the new syntax.

Files likely to be modified:

  • lexer/src/main/antlr4/gov/nasa/pds/api/registry/lexer/Search.g4
  • service/src/main/java/gov/nasa/pds/api/registry/search/Antlr4SearchListener.java

πŸŽ‰ I&T

Update integration tests in the registry repository Postman collection to use the new prefix syntax for exists queries.

Metadata

Metadata

Assignees

Labels

Projects

Status

ToDo

Status

Todo

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions