Skip to content

Commit

Permalink
Merge 'Support nested parenthesized conditional expressions in transl…
Browse files Browse the repository at this point in the history
…ator' from Preston Thorpe

This PR fixes queries like:
```sql
    SELECT count(*) FROM users WHERE ((age > 25 OR age < 18) AND (city = 'Boston' OR state = 'MA'));
```
Previously we would return `7516` rows instead of `146`, due to
disregarding the final `AND` from within the nested `OR` conditions,
unconditionally short circuiting when a TRUE is found in an OR
expression without any surrounding relevant context.
or:
```sql
    SELECT * FROM users WHERE (((age > 18 AND city = 'New Mario') OR age = 92) AND city = 'Lake Paul');
```
Previously we would incorrectly return the top row:
```
9984|Leah|Russell|..|..|6733 Weber Crossing|New Mario|SC|57707|78
9989|Timothy|Harrison|..|..|782 Wright Harbors|Lake Paul|ID|52330|92
```
Added localized jump targets for OR expressions within AND blocks to
prevent premature short-circuiting and `parent operator` to condition
metadata to trigger them.
If parent operator should instead be another function param on
`translate_conditional_expr`, instead of a field in condition_metadata,
let me know and I can change it.
EDIT: sorry I realize I should have included the other cleanup changes
in a different PR. I will fix this after work

Reviewed-by: Jussi Saurio <[email protected]>

Closes #633
  • Loading branch information
jussisaurio committed Jan 9, 2025
2 parents 0ef4def + 97d0fc6 commit 10fd8bb
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 234 deletions.
Loading

0 comments on commit 10fd8bb

Please sign in to comment.