Fix SQLite Engine Comparison Operators and ORDER BY Parsing #4126
+658
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes critical parsing issues in the SQLite engine where comparison operators were incorrectly defaulting to
=
and ORDER BY clauses were generating incorrect AST nodes. It also restores correct handling ofEXISTS
/NOT EXISTS
so SQLite queries emit the right boolean expressions and generated code.Issues Fixed
=
operator instead of extracting the actual operator (<
,>
,<=
,>=
,!=
,<>
,IS
,LIKE
,GLOB
,MATCH
,REGEXP
)NOT LIKE
,NOT GLOB
,NOT IN
,IS NOT NULL
, etc. were not handled properlyCaseExpr
nodes instead of properSortBy
nodesSortClause
fieldNOT EXISTS
flattened incorrectly - SQLite treatedNOT EXISTS
as a bare subquery, producingexists
variables instead of the expectednot_exists
boolean outputChanges Made
Core Fixes (
internal/engine/sqlite/convert.go
)convertComparison
: Now properly extracts actual comparison operators instead of defaulting to=
extractComparisonOperator
: Comprehensive function handling all SQLite comparison operators including NOT variantsconvertOrderby_stmtContext
: Now generates properSortBy
AST nodes with correct direction (ASC
/DESC
) and null handling (NULLS FIRST
/LAST
)convertMultiSelect_stmtContext
: Added ORDER BY integration to properly setSortClause
convertNullComparison
: HandleIS NULL
/IS NOT NULL
expressionsconvertUnaryExpr
: Detects unaryNOT
via the unary-operator node, including wrappingNOT EXISTS
as aBoolExpr
convertInSelectNode
: RecognisesNOT EXISTS
when the context begins with the NOT token so the AST preserves the negationNew Test Coverage (
internal/engine/sqlite/convert_test.go
)<
,>
,<=
,>=
,=
,!=
,<>
,<<
,>>
,&
,|
,IS
,LIKE
,GLOB
,MATCH
,REGEXP
)NOT LIKE
,NOT GLOB
,NOT IN
,IS NOT NULL
, etc.Operators Now Supported
<
,>
,<=
,>=
,=
,!=
,<>
<<
,>>
,&
,|
LIKE
,GLOB
,MATCH
,REGEXP
IS NULL
,IS NOT NULL
IN
,NOT IN
NOT LIKE
,NOT GLOB
,NOT MATCH
,NOT REGEXP
Testing
Example Impact
Before (incorrect):
After (correct):
Breaking Changes
EXISTS
/NOT EXISTS
return types: Generated Go methods now returnbool
(and emit variables namedexists
/not_exists
) instead of the previousint64
placeholder. Projects that already consume these helpers must update their call sites to expect a boolean result.NOT EXISTS
: Because the AST now retains the inner select, generated methods once again surface the query arguments. Call sites that relied on the buggy zero-argument signature will need to pass the correct inputs (for example,id
inBarNotExists
).Related Issues
Fixes parsing issues with SQLite comparison operators and ORDER BY clauses that could lead to incorrect SQL generation and runtime errors.