Skip to content

Commit 21a4270

Browse files
committed
fix cut unsupported constructions
1 parent bbe44e5 commit 21a4270

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func checkQuery(stat *QueryStats, rules Rules, db *ydb.Driver, queryText string)
409409
queryText = strings.TrimSpace(queryText)
410410
queryText = fixSchemaNames(queryText)
411411
queryText = fixCreateTable(queryText)
412-
queryText = cutGreenplumSpecific(queryText)
412+
queryText = cutUnsupportedConstructions(queryText)
413413

414414
ctx := context.Background()
415415
res, err := db.Query().Execute(
@@ -468,17 +468,19 @@ func fixCreateTable(queryText string) string {
468468
return queryText
469469
}
470470

471-
func cutGreenplumSpecific(q string) string {
472-
q = createAndDistributedByWithBrackets.ReplaceAllString(q, "$1")
473-
q = createTableAsSelect.ReplaceAllLiteralString(q, "")
471+
func cutUnsupportedConstructions(q string) string {
472+
q = createAS.ReplaceAllString(q, "$1")
473+
q = createTableAsSelect.ReplaceAllLiteralString(q, "SELECT")
474474
q = distributedBy.ReplaceAllLiteralString(q, "")
475+
q = distributedWord.ReplaceAllLiteralString(q, "")
475476
return q
476477
}
477478

478479
var (
479-
createAndDistributedByWithBrackets = regexp.MustCompile(`(?is)CREATE\s+.*\sTABLE\s+.*\s+AS\s+\(\s*(.*)\s*\)\s+DISTRIBUTED\s+BY\s\(.*\)`)
480-
createTableAsSelect = regexp.MustCompile(`(?is)create\s+(temporary\s+)?table .* as`)
481-
distributedBy = regexp.MustCompile(`(?i)DISTRIBUTED BY \(.*\)`)
480+
createAS = regexp.MustCompile(`(?is)CREATE\s+.*\sTABLE\s+.*\s+AS\s+\(\s*(.*)\s*\)\s`)
481+
createTableAsSelect = regexp.MustCompile(`(?is)CREATE\s+(TEMPORARY\s+)?TABLE .* AS\s+SELECT`)
482+
distributedBy = regexp.MustCompile(`(?is)DISTRIBUTED BY \(.*\)`)
483+
distributedWord = regexp.MustCompile(`(?is)DISTRIBUTED \w+`)
482484
)
483485

484486
type QueryStats struct {

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ func TestCutGreenplumSpecific(t *testing.T) {
4444
select *
4545
from bbb;
4646
`,
47-
to: `
48-
select *
47+
to: `SELECT *
4948
from bbb;
5049
`,
5150
},
@@ -56,19 +55,35 @@ func TestCutGreenplumSpecific(t *testing.T) {
5655
SELECT DISTINCT b AS ticket_id
5756
FROM t2 --comment
5857
WHERE mytime BETWEEN ''2024-04-10 00:00:00''::timestamp AND ''2024-04-30 23:59:59''::timestamp
59-
)
60-
DISTRIBUTED BY (ticket_id);
58+
) DISTRIBUTED BY (ticket_id);
6159
`,
6260
to: ` SELECT DISTINCT b AS ticket_id
6361
FROM t2 --comment
6462
WHERE mytime BETWEEN ''2024-04-10 00:00:00''::timestamp AND ''2024-04-30 23:59:59''::timestamp
6563
;
64+
`,
65+
},
66+
{
67+
name: "CreateAndDistributedSomething",
68+
from: ` CREATE TEMPORARY TABLE result_table
69+
ON COMMIT DROP AS
70+
SELECT dt AS utc_dt
71+
, diff_a
72+
, diff_b
73+
FROM t
74+
DISTRIBUTED REPLICATED;
75+
`,
76+
to: ` SELECT dt AS utc_dt
77+
, diff_a
78+
, diff_b
79+
FROM t
80+
;
6681
`,
6782
},
6883
}
6984
for _, test := range table {
7085
t.Run(test.name, func(t *testing.T) {
71-
res := cutGreenplumSpecific(test.from)
86+
res := cutUnsupportedConstructions(test.from)
7287
require.Equal(t, test.to, res)
7388
})
7489
}

tools/greenplum-to-pg-tests/issues.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ issues:
1515
query_regexp:
1616
- "(?i)^\\s*COMMIT\\s*;?\\s*$"
1717
- "(?i)^\\s*ROLLBACK\\s*;?\\s*$"
18-
- name: Set variables
19-
issue_regexp: "VariableSetStmt, not supported name"
2018
- name: drop external table
2119
count: 2
2220
tag:

0 commit comments

Comments
 (0)