Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: fix bugs and add more tests for plsql completion (#12878)
rebelice593911d7ab55
diff --git a/backend/plugin/parser/plsql/completion.go b/backend/plugin/parser/plsql/completion.goindex 7208b33997..ebfcfaed53 100644--- a/backend/plugin/parser/plsql/completion.go+++ b/backend/plugin/parser/plsql/completion.go@@ -727,13 +727,13 @@ func (c *Completer) determineGeneralElementPartCandidates() (schema, table strinfunc unquote(s string) string {if len(s) < 2 {- return s+ return strings.ToUpper(s)}if (s[0] == '`' || s[0] == '\'' || s[0] == '"') && s[0] == s[len(s)-1] {return s[1 : len(s)-1]}- return s+ return strings.ToUpper(s)}func (c *Completer) collectRemainingTableReferences() {diff --git a/backend/plugin/parser/plsql/completion_test.go b/backend/plugin/parser/plsql/completion_test.goindex e2c0e32fad..ceb5086536 100644--- a/backend/plugin/parser/plsql/completion_test.go+++ b/backend/plugin/parser/plsql/completion_test.go@@ -39,13 +39,13 @@ func TestCompletion(t *testing.T) {a.NoError(yaml.Unmarshal(byteValue, &tests))for i, t := range tests {- text, caretOffset := catchCaret(t.Input)+ text, caretLine, caretOffset := catchCaret(t.Input)result, err := base.Completion(context.Background(), storepb.Engine_ORACLE, base.CompletionContext{Scene: base.SceneTypeAll,DefaultDatabase: "SCHEMA1",Metadata: getMetadataForTest,ListDatabaseNames: listDatabaseNamesForTest,- }, text, 1, caretOffset)+ }, text, caretLine, caretOffset)a.NoError(err)var filteredResult []base.Candidatefor _, r := range result {@@ -208,11 +208,19 @@ func getMetadataForTest(_ context.Context, _, databaseName string) (string, *mod}}-func catchCaret(s string) (string, int) {+func catchCaret(s string) (string, int, int) {+ line := 1+ column := 0for i, c := range s {- if c == '|' {- return s[:i] + s[i+1:], i+ switch c {+ case '|':+ return s[:i] + s[i+1:], line, column+ case '\n':+ line+++ column = 0+ default:+ column++}}- return s, -1+ return s, -1, -1}diff --git a/backend/plugin/parser/plsql/test-data/test_completion.yaml b/backend/plugin/parser/plsql/test-data/test_completion.yamlindex d8664c3cdc..428625a8a9 100644--- a/backend/plugin/parser/plsql/test-data/test_completion.yaml+++ b/backend/plugin/parser/plsql/test-data/test_completion.yaml@@ -1,3 +1,149 @@+- input: SELECT c1 as eid, c2 as xid FROM t2 ORDER BY |+ want:+ - text: SCHEMA1+ type: SCHEMA+ definition: ""+ comment: ""+ - text: SCHEMA2+ type: SCHEMA+ definition: ""+ comment: ""+ - text: SCHEMA3+ type: SCHEMA+ definition: ""+ comment: ""+ - text: T1+ type: TABLE+ definition: ""+ comment: ""+ - text: T2+ type: TABLE+ definition: ""+ comment: ""+ - text: C1+ type: COLUMN+ definition: T2 | int, NOT NULL+ comment: ""+ - text: C2+ type: COLUMN+ definition: T2 | int, NOT NULL+ comment: ""+ - text: V1+ type: VIEW+ definition: ""+ comment: ""+- input: SELECT c1 as eid FROM t1 ORDER BY |+ want:+ - text: SCHEMA1+ type: SCHEMA+ definition: ""+ comment: ""+ - text: SCHEMA2+ type: SCHEMA+ definition: ""+ comment: ""+ - text: SCHEMA3+ type: SCHEMA+ definition: ""+ comment: ""+ - text: T1+ type: TABLE+ definition: ""+ comment: ""+ - text: T2+ type: TABLE+ definition: ""+ comment: ""+ - text: C1+ type: COLUMN+ definition: T1 | int, NOT NULL+ comment: ""+ - text: V1+ type: VIEW+ definition: ""+ comment: ""+- input: |-+ SELECT FROM basdkfjasldf;+ SELECT | FROM t1+ want:+ - text: SCHEMA1+ type: SCHEMA+ definition: ""+ comment: ""+ - text: SCHEMA2+ type: SCHEMA+ definition: ""+ comment: ""+ - text: SCHEMA3+ type: SCHEMA+ definition: ""+ comment: ""+ - text: T1+ type: TABLE+ definition: ""+ comment: ""+ - text: T2+ type: TABLE+ definition: ""+ comment: ""+ - text: C1+ type: COLUMN+ definition: T1 | int, NOT NULL+ comment: ""+ - text: V1+ type: VIEW+ definition: ""+ comment: ""+- input: SELECT | FROM (SELECT c1 FROM t1) cc1+ want:+ - text: SCHEMA1+ type: SCHEMA+ definition: ""+ comment: ""+ - text: SCHEMA2+ type: SCHEMA+ definition: ""+ comment: ""+ - text: SCHEMA3+ type: SCHEMA+ definition: ""+ comment: ""+ - text: CC1+ type: TABLE+ definition: ""+ comment: ""+ - text: T1+ type: TABLE+ definition: ""+ comment: ""+ - text: T2+ type: TABLE+ definition: ""+ comment: ""+ - text: C1+ type: COLUMN+ definition: T1 | int, NOT NULL+ comment: ""+ - text: V1+ type: VIEW+ definition: ""+ comment: ""+- input: SELECT cc1.| FROM t1 cc1 JOIN t2 on NOT cc1.c1 = t2.c1+ want:+ - text: C1+ type: COLUMN+ definition: T1 | int, NOT NULL+ comment: ""+- input: SELECT * from t1 cc1 JOIN t2 on cc1.c1 = t2.|+ want:+ - text: C1+ type: COLUMN+ definition: T2 | int, NOT NULL+ comment: ""+ - text: C2+ type: COLUMN+ definition: T2 | int, NOT NULL+ comment: ""- input: SELECT * from t1 cc1 JOIN t2 on cc1.|want:- text: C1