Skip to content

Commit 8043947

Browse files
committed
fix regexps
1 parent 860ecad commit 8043947

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tools/greenplum-to-pg-tests/cmd/check_pg_queries.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,14 @@ type ReplacePair struct {
474474
To string
475475
}
476476

477-
var schemaTableRegexp = regexp.MustCompile(`(?i)(CREATE TABLE|FROM|INSERT INTO|JOIN|UPDATE)\s+"?([^\s."]+)"?\."?([^\s."]+)"?`)
477+
var (
478+
schemaTableRegexp = regexp.MustCompile(`(?is)(EXISTS|FROM|INSERT INTO|JOIN|\s+ON|ROOTPARTITION|TABLE|UPDATE)\s+"?([^\s."]+)"?\."?([^\s."]+)"?`)
479+
schemaTableField = regexp.MustCompile(`"?([^\s."]+)"?\."?([^\s."]+)"?\."?([^\s."]+)"?`)
480+
)
478481

479482
func fixSchemaNames(queryText string) string {
480483
queryText = schemaTableRegexp.ReplaceAllString(queryText, "${1} ${2}___${3}")
484+
queryText = schemaTableField.ReplaceAllString(queryText, "${1}___${2}.${3}")
481485
return queryText
482486
}
483487

tools/greenplum-to-pg-tests/cmd/check_pg_queries_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ FROM asd___sss t
2222
USING "kkk" AS base
2323
WHERE`,
2424
},
25+
{
26+
from: `LOCK TABLE "asd"."ffa" IN EXCLUSIVE MODE`,
27+
result: `LOCK TABLE asd___ffa IN EXCLUSIVE MODE`,
28+
},
29+
{
30+
from: `DROP TABLE IF EXISTS "aaa"."bbb"`,
31+
result: `DROP TABLE IF EXISTS aaa___bbb`,
32+
},
33+
{
34+
from: `GRANT SELECT ON sss.tt to public`,
35+
result: `GRANT SELECT ON sss___tt to public`,
36+
},
37+
{
38+
from: `SELECT s.t.f FROM s.t`,
39+
result: `SELECT s___t.f FROM s___t`,
40+
},
2541
}
2642

2743
for i, test := range table {

0 commit comments

Comments
 (0)