Skip to content

Commit 4155d73

Browse files
resolve: merge conflict in A_Const method
- Removed duplicated field transformations and conflict markers - Restored clean A_Const method structure with proper ival, fval, boolval, sval, bsval, isnull, location handling - Merge conflict resolution maintains stable baseline functionality Co-Authored-By: Dan Lynch <[email protected]>
2 parents 6a9bda9 + 765eff6 commit 4155d73

File tree

2 files changed

+6
-67
lines changed

2 files changed

+6
-67
lines changed

packages/transform/STATUS-15-16.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Started from a basic skeleton transformer and systematically implemented node wr
2626

2727
**Attempted Solutions**:
2828
- ❌ Broad A_Const fix (transforms all empty ival objects) - caused test pass rate to drop to 144/258
29-
- ❌ Context-aware transformation - context patterns identical for zero vs negative values
29+
- ❌ Context-based detection (constraint/ALTER TABLE contexts) - caused test pass rate to drop to 174/258
3030
- ✅ Successfully reverted to stable 184/258 baseline after testing approaches
31-
- 🔄 Currently exploring dual-parse approach to detect when transformation is needed
31+
- 🔄 Dual-parse approach explored but @pgsql/parser returns empty objects for all SQL queries
3232

3333
## Debug Tools Created
3434
- `debug_transformation_flow_detailed.js` - Analyzes exact transformation flow for negative integers
@@ -40,9 +40,9 @@ Started from a basic skeleton transformer and systematically implemented node wr
4040
- `debug_context_analysis.js` - Analyzes context-dependent transformation patterns
4141

4242
## Next Steps
43-
1. Explore dual-parse approach: parse same SQL with both PG15 and PG16 to determine when transformation is needed
44-
2. Implement targeted A_Const fix based on dual-parse comparison results
45-
3. Test fix maintains 184/258 baseline while resolving negative integer cases
43+
1. Investigate alternative approaches beyond context-based and dual-parse methods
44+
2. Consider advanced pattern matching or heuristic detection for negative integer cases
45+
3. Explore selective transformation targeting only high-confidence scenarios
4646
4. Verify specific failing test cases like `alter_table-234.sql`
4747
5. Continue systematic improvement of remaining 74 failing tests
4848

packages/transform/src/transformers/v15-to-v16.ts

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,9 @@ import { Parser } from '@pgsql/parser';
77
* Transforms PostgreSQL v15 AST nodes to v16 format
88
*/
99
export class V15ToV16Transformer {
10-
private parser15 = new Parser(15);
11-
private parser16 = new Parser(16);
12-
private transformationCache = new Map<string, any>();
1310

14-
private shouldTransformEmptyIval(context: TransformerContext): { ival: number } | null {
15-
16-
return null;
17-
}
1811

19-
private detectEmptyIvalTransformation(sql: string): number | null {
20-
try {
21-
const cacheKey = `empty_ival_${sql}`;
22-
if (this.transformationCache.has(cacheKey)) {
23-
return this.transformationCache.get(cacheKey);
24-
}
2512

26-
const pg15Result = this.parser15.parse(sql);
27-
const pg16Result = this.parser16.parse(sql);
28-
29-
const pg15AConst = this.findAConstInAST(pg15Result);
30-
const pg16AConst = this.findAConstInAST(pg16Result);
31-
32-
if (pg15AConst && pg16AConst) {
33-
const pg15IsEmpty = pg15AConst.ival && Object.keys(pg15AConst.ival).length === 0;
34-
const pg16HasNested = pg16AConst.ival && typeof pg16AConst.ival.ival === 'number';
35-
36-
if (pg15IsEmpty && pg16HasNested) {
37-
const targetValue = pg16AConst.ival.ival;
38-
this.transformationCache.set(cacheKey, targetValue);
39-
return targetValue;
40-
}
41-
}
42-
43-
this.transformationCache.set(cacheKey, null);
44-
return null;
45-
} catch (error) {
46-
return null;
47-
}
48-
}
49-
50-
private findAConstInAST(obj: any): any {
51-
if (!obj || typeof obj !== 'object') return null;
52-
53-
if (obj.A_Const) return obj.A_Const;
54-
55-
for (const key in obj) {
56-
if (typeof obj[key] === 'object') {
57-
const result = this.findAConstInAST(obj[key]);
58-
if (result) return result;
59-
}
60-
}
61-
62-
return null;
63-
}
6413

6514
transform(node: PG15.Node, context: TransformerContext = { parentNodeTypes: [] }): any {
6615
if (node == null) {
@@ -101,7 +50,7 @@ export class V15ToV16Transformer {
10150
if (typeof this[methodName] === 'function') {
10251
const childContext: TransformerContext = {
10352
...context,
104-
parentNodeTypes: [...context.parentNodeTypes, nodeType]
53+
parentNodeTypes: [...(context.parentNodeTypes || []), nodeType]
10554
};
10655
return (this[methodName] as any)(nodeData, childContext);
10756
}
@@ -941,16 +890,6 @@ export class V15ToV16Transformer {
941890

942891
Integer(node: PG15.Integer, context: TransformerContext): any {
943892
const result: any = { ...node };
944-
945-
// Handle case where PG15 produces empty Integer nodes that need different handling based on context
946-
if (Object.keys(node).length === 0) {
947-
if (context.parentNodeTypes.includes('TypeName')) {
948-
result.ival = -1;
949-
} else if (context.parentNodeTypes.includes('A_Const')) {
950-
result.ival = -1;
951-
}
952-
}
953-
954893
return { Integer: result };
955894
}
956895

0 commit comments

Comments
 (0)