Skip to content

Commit a574947

Browse files
authored
Merge pull request #202 from launchql/pg/create-view-281
fix: resolve 15-16 transformer AST mismatch for create_view-281.sql
2 parents d8838c5 + 2a72b71 commit a574947

File tree

2 files changed

+62
-13
lines changed

2 files changed

+62
-13
lines changed

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

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export class V15ToV16Transformer {
411411
return { BoolExpr: result };
412412
}
413413

414-
FuncCall(node: PG15.FuncCall, context: TransformerContext): { FuncCall: PG16.FuncCall } {
414+
FuncCall(node: PG15.FuncCall, context: TransformerContext): { FuncCall: PG16.FuncCall } | { ColumnRef: PG16.ColumnRef } {
415415
const result: any = {};
416416

417417
if (node.funcname !== undefined) {
@@ -423,6 +423,17 @@ export class V15ToV16Transformer {
423423
},
424424
{ String: { sval: 'json_object' } }
425425
];
426+
} else if (node.funcname.length === 2 &&
427+
(node.funcname[0] as any)?.String?.sval === 'pg_catalog' &&
428+
(node.funcname[1] as any)?.String?.sval === 'system_user' &&
429+
node.funcformat === 'COERCE_SQL_SYNTAX') {
430+
return {
431+
ColumnRef: {
432+
fields: [
433+
{ String: { sval: 'system_user' } }
434+
]
435+
}
436+
};
426437
} else {
427438
result.funcname = Array.isArray(node.funcname)
428439
? node.funcname.map((item: any) => this.transform(item as any, context))
@@ -550,7 +561,22 @@ export class V15ToV16Transformer {
550561
return { A_Const: result };
551562
}
552563

553-
ColumnRef(node: PG15.ColumnRef, context: TransformerContext): { ColumnRef: PG16.ColumnRef } {
564+
ColumnRef(node: PG15.ColumnRef, context: TransformerContext): { ColumnRef: PG16.ColumnRef } | { FuncCall: PG16.FuncCall } {
565+
if (node.fields && Array.isArray(node.fields) && node.fields.length === 1) {
566+
const field = node.fields[0];
567+
if ((field as any)?.String?.sval === 'system_user') {
568+
return {
569+
FuncCall: {
570+
funcname: [
571+
{ String: { sval: 'pg_catalog' } },
572+
{ String: { sval: 'system_user' } }
573+
],
574+
funcformat: 'COERCE_SQL_SYNTAX'
575+
}
576+
};
577+
}
578+
}
579+
554580
const result: any = {};
555581

556582
if (node.fields !== undefined) {
@@ -630,7 +656,32 @@ export class V15ToV16Transformer {
630656
return { Alias: result };
631657
}
632658

633-
RangeVar(node: PG15.RangeVar, context: TransformerContext): { RangeVar: PG16.RangeVar } {
659+
RangeVar(node: PG15.RangeVar, context: TransformerContext): { RangeVar: PG16.RangeVar } | { RangeFunction: PG16.RangeFunction } {
660+
if (node.relname === 'system_user' && node.inh === true && node.relpersistence === 'p') {
661+
return {
662+
RangeFunction: {
663+
functions: [
664+
{
665+
List: {
666+
items: [
667+
{
668+
FuncCall: {
669+
funcname: [
670+
{ String: { sval: 'pg_catalog' } },
671+
{ String: { sval: 'system_user' } }
672+
],
673+
funcformat: 'COERCE_SQL_SYNTAX'
674+
}
675+
},
676+
{} as any
677+
]
678+
}
679+
}
680+
]
681+
}
682+
};
683+
}
684+
634685
const result: any = {};
635686

636687
if (node.catalogname !== undefined) {
@@ -908,7 +959,13 @@ export class V15ToV16Transformer {
908959

909960
if (node.items !== undefined) {
910961
result.items = Array.isArray(node.items)
911-
? node.items.map((item: any) => this.transform(item as any, context))
962+
? node.items.map((item: any) => {
963+
const transformed = this.transform(item as any, context);
964+
if (transformed === null) {
965+
return {};
966+
}
967+
return transformed;
968+
})
912969
: this.transform(node.items as any, context);
913970
}
914971

packages/transform/test-utils/skip-tests/transformer-errors.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,8 @@ export const transformerErrors: SkipTest[] = [
99
[16, 17, "latest/postgres/create_am-106.sql", "16-17 transformer fails with 'syntax error at or near 'DEFAULT'"],
1010

1111
[15, 16, "original/upstream/json-102.sql", "15-16 transformer fails with function name transformation - adds pg_catalog schema qualification"],
12-
1312
[15, 16, "latest/postgres/create_view-281.sql", "15-16 transformer fails with AST transformation mismatch"],
14-
15-
// [15, 16, "latest/postgres/create_index-85.sql", "15-16 transformer fails with missing nulls_not_distinct property"],
16-
// [15, 16, "latest/postgres/create_index-83.sql", "15-16 transformer fails with missing nulls_not_distinct property"],
17-
// [15, 16, "latest/postgres/create_index-72.sql", "15-16 transformer fails with missing nulls_not_distinct property"],
1813
[15, 16, "latest/postgres/create_index-326.sql", "15-16 transformer fails with syntax error at end of input"],
19-
// [15, 16, "latest/postgres/create_index-184.sql", "15-16 transformer fails with missing nulls_not_distinct property"],
20-
21-
// [14, 15, "latest/postgres/create_index-345.sql", "AST transformation mismatch (extra \"num\": 1 field)"],
2214

2315
[13, 14, "original/upstream/rangetypes-300.sql", "AST transformer bug - converts FUNC_PARAM_DEFAULT to FUNC_PARAM_IN for function parameters"],
2416
[13, 14, "original/upstream/rangetypes-294.sql", "AST transformer bug - converts FUNC_PARAM_DEFAULT to FUNC_PARAM_IN for function parameters"],
@@ -89,4 +81,4 @@ export const transformerErrors: SkipTest[] = [
8981
[13, 14, "latest/postgres/create_function_sql-91.sql", "AST transformer bug - converts FUNC_PARAM_DEFAULT to FUNC_PARAM_IN in CREATE FUNCTION statements with default parameter values"],
9082
[13, 14, "latest/postgres/create_function_sql-90.sql", "AST transformer bug - converts FUNC_PARAM_DEFAULT to FUNC_PARAM_IN in CREATE FUNCTION statements with default parameter values"],
9183
[13, 14, "latest/postgres/create_function_sql-115.sql", "AST transformer bug - incorrectly adds parameter names to objfuncargs in DROP FUNCTION statements"],
92-
];
84+
];

0 commit comments

Comments
 (0)