Skip to content

feat: add support for NOT EXISTS / NOT EXIST comparator - #9

Merged
pinzon merged 1 commit into
localstack:mainfrom
azhar22k:feat/not-exists-comparator
Sep 29, 2026
Merged

pinzon merged 1 commit into
localstack:mainfrom
azhar22k:feat/not-exists-comparator

Conversation

@azhar22k

Copy link
Copy Markdown
Contributor

Closes #8

Description

CloudWatch filter expressions support checking whether a JSON attribute does not exist using the NOT EXISTS syntax (e.g. { $.SomeOtherObject NOT EXISTS }). This PR extends the Lark grammar and matcher parser to support this comparator.

Key Changes

  • Grammar (grammar.lark):
    • Added comparison: ... | entity NOT_EXISTS -> not_exists
    • Added NOT_EXISTS: /(?i:NOT\s+EXISTS?)/ terminal matching both NOT EXISTS and NOT EXIST case-insensitively with flexible whitespace.
  • Matcher (matcher.py):
    • Introduced MISSING sentinel object to distinguish between absent attributes and attributes explicitly set to null (None).
    • Added not_exists handler in FilterEvaluator to return True when the resolved entity is MISSING.
    • Refactored resolve_entity to safely traverse nested objects, dictionaries, and list indices without raising AttributeError or KeyError on missing intermediate paths.
    • Ensured comparisons on missing attributes safely return False.
    • Updated extract_boolean to support raw booleans as well as AST nodes.
  • Tests:
    • Added parser test cases in tests/test_parser.py (including invalid syntax error cases).
    • Added matcher test cases in tests/test_matcher.py (missing fields, present fields, nested paths, list indices, null values, and combined logical expressions).

@pinzon
pinzon self-requested a review September 28, 2026 19:25

@pinzon pinzon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for contributing to this project

@pinzon
pinzon merged commit 789d67b into localstack:main Sep 29, 2026
@azhar22k
azhar22k deleted the feat/not-exists-comparator branch September 29, 2026 15:41
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.

feature request: NOT EXIST comparator

2 participants