Skip to content

Add flatten method and extend filterAnd for nested expressions#97

Merged
vogievetsky merged 4 commits intomasterfrom
fix_filter_and
May 20, 2025
Merged

Add flatten method and extend filterAnd for nested expressions#97
vogievetsky merged 4 commits intomasterfrom
fix_filter_and

Conversation

@vogievetsky
Copy link
Member

This PR adds a new flatten method to SQL expressions and improves the filterAnd method to handle nested AND expressions correctly.

Changes:

  1. Added flatten method to SqlExpression:
    - Base implementation in SqlExpression class returns the expression as-is
    - SqlMulti class implementation recursively flattens nested multi expressions with the same operator
    - Allows flattening expressions like a AND (b AND c) to a AND b AND c
  2. Enhanced filterAnd method in SqlMulti:
    - Fixed to correctly handle nested AND expressions
    - Now recursively filters through nested expressions instead of just top-level ones
    - Example: a AND (x AND y AND b) with filter removing 'b' now correctly produces a AND (x AND y)
  3. Comprehensive test coverage:
    - Added tests for the new flatten method covering various scenarios including deeply nested expressions
    - Added test for nested AND expressions in filterAnd
    - Moved removeColumnFromAnd tests from sql-multi.spec.ts to sql-expression.spec.ts and added invariant tests to ensure correctness

@changeset-bot
Copy link

changeset-bot bot commented May 19, 2025

🦋 Changeset detected

Latest commit: ac190a7

The changes in this PR will be included in the next version bump.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vogievetsky vogievetsky merged commit a7e1b22 into master May 20, 2025
1 check passed
@vogievetsky vogievetsky deleted the fix_filter_and branch May 20, 2025 16:40
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