Skip to content

Commit fa067ad

Browse files
revert: remove overly broad A_Const ival transformation
- Reverted simplified fix that transformed all empty ival objects to {ival: -1} - Test pass rate dropped from 184/258 to 144/258 with this approach - Need more targeted solution to distinguish zero values from negative integers - Maintaining stable 184/258 test baseline Co-Authored-By: Dan Lynch <[email protected]>
1 parent 602b5b8 commit fa067ad

File tree

1 file changed

+2
-61
lines changed

1 file changed

+2
-61
lines changed

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

Lines changed: 2 additions & 61 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-
}
18-
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-
}
2511

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-
}
4912

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
}
@@ -585,15 +534,7 @@ export class V15ToV16Transformer {
585534
}
586535

587536
if (result.ival !== undefined) {
588-
// Handle case where PG15 produces empty ival objects for negative integers
589-
if (typeof result.ival === 'object' && Object.keys(result.ival).length === 0) {
590-
const transformedIval = this.shouldTransformEmptyIval(context);
591-
if (transformedIval) {
592-
result.ival = transformedIval;
593-
}
594-
} else {
595-
result.ival = this.transform(result.ival as any, context);
596-
}
537+
result.ival = this.transform(result.ival as any, context);
597538
}
598539

599540
if (result.fval !== undefined) {

0 commit comments

Comments
 (0)