Fix JSON path operators: Use schema-based detection and correct table.column handling #60
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
Fixes two critical issues with JSON path operator generation:
Issue #59: Incorrect operator usage - was applying
->>to table namesIssue #20: Hardcoded JSON field names causing maintainability and security issues
Problem
Issue #59: Wrong SQL Generated
The code was treating
obj(the table name) as something that needs JSON operators, when it should recognizeobj.metadataas a regular table.column reference.Issue #20: Hardcoded Field Names
JSON field detection relied on hardcoded lists in 7+ locations:
Solution
1. Schema-Based Type Detection
IsJSON boolfield topg.FieldSchemaConvertWithSchemas(ast, schemas)function2. Fixed table.column Handling
getTableAndFieldFromSelectChain()to identify direct table.column accessbuildJSONPathInternal()to rendertable.columncorrectly before applying JSON operatorsChanges
Core Changes
ConvertWithSchemas(), schema lookup methods, andschemasfield to convertershouldUseJSONPath()andbuildJSONPathInternal()to use schema informationIsJSONfield toFieldSchema,GetSchemas()method to interfaceTesting
ConvertWithSchemas()and setIsJSON: truePostgreSQL Validation
Created integration tests using testcontainers with PostgreSQL 17:
✅ Correct SQL that works:
❌ Wrong SQL that fails:
Backward Compatibility
Convert(ast)still works without schema informationTest Results
All tests pass:
Closes
Closes #59
Addresses #20
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com