Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(sql-editor): add sequence autocomplete support (#18533)
Vincent Huang2c904b2906e6
diff --git a/backend/api/lsp/completion.go b/backend/api/lsp/completion.goindex ed66ed02f6..02f6de4a84 100644--- a/backend/api/lsp/completion.go+++ b/backend/api/lsp/completion.go@@ -107,7 +107,7 @@ func generateSortText(_ lsp.CompletionParams, _ storepb.Engine, candidate parserreturn "02" + candidate.TextWithPriority()case parserbase.CandidateTypeTable, parserbase.CandidateTypeForeignTable:return "03" + candidate.TextWithPriority()- case parserbase.CandidateTypeView, parserbase.CandidateTypeMaterializedView:+ case parserbase.CandidateTypeView, parserbase.CandidateTypeMaterializedView, parserbase.CandidateTypeSequence:return "04" + candidate.TextWithPriority()case parserbase.CandidateTypeFunction:return "05" + candidate.TextWithPriority()@@ -137,6 +137,8 @@ func convertLSPCompletionItemKind(tp parserbase.CandidateType) lsp.CompletionItereturn lsp.FunctionCompletioncase parserbase.CandidateTypeView, parserbase.CandidateTypeMaterializedView:return lsp.VariableCompletion+ case parserbase.CandidateTypeSequence:+ return lsp.ConstantCompletiondefault:return lsp.TextCompletion}diff --git a/backend/plugin/parser/base/complete.go b/backend/plugin/parser/base/complete.goindex bdc36dd79c..848140e1a3 100644--- a/backend/plugin/parser/base/complete.go+++ b/backend/plugin/parser/base/complete.go@@ -29,6 +29,7 @@ const (CandidateTypeUser CandidateType = "USER"CandidateTypeCharset CandidateType = "CHARSET"CandidateTypeCollation CandidateType = "COLLATION"+ CandidateTypeSequence CandidateType = "SEQUENCE")// Candidate is the candidate for auto-completion.diff --git a/backend/plugin/parser/pg/completion.go b/backend/plugin/parser/pg/completion.goindex 6f5fa9cd2e..f6cf825b64 100644--- a/backend/plugin/parser/pg/completion.go+++ b/backend/plugin/parser/pg/completion.go@@ -376,6 +376,24 @@ func (m CompletionMap) insertViewsWithPrefix(c *Completer, schemas map[string]bo}}+func (m CompletionMap) insertSequencesWithPrefix(c *Completer, schemas map[string]bool, includeSchemaPrefix bool) {+ for schema := range schemas {+ if len(schema) == 0 {+ continue+ }+ for _, seq := range c.listSequences(schema) {+ text := c.quotedIdentifierIfNeeded(seq)+ if includeSchemaPrefix && schema != c.defaultSchema {+ text = c.quotedIdentifierIfNeeded(schema) + "." + text+ }+ m.Insert(base.Candidate{+ Type: base.CandidateTypeSequence,+ Text: text,+ })+ }+ }+}+func (m CompletionMap) insertColumns(c *Completer, schemas, tables map[string]bool) {if _, exists := c.metadataCache[c.defaultDatabase]; !exists {_, metadata, err := c.getMetadata(c.ctx, c.instanceID, c.defaultDatabase)@@ -491,6 +509,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]tableEntries := make(CompletionMap)columnEntries := make(CompletionMap)viewEntries := make(CompletionMap)+ sequenceEntries := make(CompletionMap)for token, value := range candidates.Tokens {if token < 0 {@@ -573,6 +592,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]includeSchemaPrefix := len(qualifier) == 0 && c.schemaNotSelectedtableEntries.insertTablesWithPrefix(c, schemas, includeSchemaPrefix)viewEntries.insertViewsWithPrefix(c, schemas, includeSchemaPrefix)+ sequenceEntries.insertSequencesWithPrefix(c, schemas, includeSchemaPrefix)}case pg.PostgreSQLParserRULE_columnref:schema, table, flags := c.determineColumnRef()@@ -713,6 +733,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]result = append(result, schemaEntries.toSlice()...)result = append(result, tableEntries.toSlice()...)result = append(result, viewEntries.toSlice()...)+ result = append(result, sequenceEntries.toSlice()...)result = append(result, columnEntries.toSlice()...)return result, nil@@ -1396,6 +1417,22 @@ func (c *Completer) listViews(schema string) []string {return schemaMeta.ListViewNames()}+func (c *Completer) listSequences(schema string) []string {+ if _, exists := c.metadataCache[c.defaultDatabase]; !exists {+ _, metadata, err := c.getMetadata(c.ctx, c.instanceID, c.defaultDatabase)+ if err != nil || metadata == nil {+ return nil+ }+ c.metadataCache[c.defaultDatabase] = metadata+ }++ schemaMeta := c.metadataCache[c.defaultDatabase].GetSchemaMetadata(schema)+ if schemaMeta == nil {+ return nil+ }+ return schemaMeta.ListSequenceNames()+}+func (c *Completer) quotedIdentifierIfNeeded(s string) string {if c.caretTokenIsQuoted {return sdiff --git a/backend/plugin/parser/pg/completion_test.go b/backend/plugin/parser/pg/completion_test.goindex 8b93aa273e..4216083ce5 100644--- a/backend/plugin/parser/pg/completion_test.go+++ b/backend/plugin/parser/pg/completion_test.go@@ -140,6 +140,14 @@ func getMetadataForTest(_ context.Context, _, databaseName string) (string, *mod`,},},+ Sequences: []*storepb.SequenceMetadata{+ {+ Name: "seq1",+ },+ {+ Name: "user_id_seq",+ },+ },},{Name: "test",@@ -171,6 +179,11 @@ func getMetadataForTest(_ context.Context, _, databaseName string) (string, *mod},},},+ Sequences: []*storepb.SequenceMetadata{+ {+ Name: "order_id_seq",+ },+ },},},}, nil, nil, storepb.Engine_POSTGRES, true /* isObjectCaseSensitive */), nildiff --git a/backend/plugin/parser/pg/test-data/test_completion.yaml b/backend/plugin/parser/pg/test-data/test_completion.yamlindex 62b46352b4..f5060aec50 100644--- a/backend/plugin/parser/pg/test-data/test_completion.yaml+++ b/backend/plugin/parser/pg/test-data/test_completion.yaml@@ -10,6 +10,18 @@type: SCHEMAdefinition: ""comment: ""+ - text: seq1+ type: SEQUENCE+ definition: ""+ comment: ""+ - text: test.order_id_seq+ type: SEQUENCE+ definition: ""+ comment: ""+ - text: user_id_seq+ type: SEQUENCE+ definition: ""+ comment: ""- text: t1type: TABLEdefinition: ""@@ -270,6 +282,18 @@type: SCHEMAdefinition: ""comment: ""+ - text: seq1+ type: SEQUENCE+ definition: ""+ comment: ""+ - text: test.order_id_seq+ type: SEQUENCE+ definition: ""+ comment: ""+ - text: user_id_seq+ type: SEQUENCE+ definition: ""+ comment: ""- text: t1type: TABLEdefinition: ""@@ -356,6 +380,18 @@type: SCHEMAdefinition: ""comment: ""+ - text: seq1+ type: SEQUENCE+ definition: ""+ comment: ""+ - text: test.order_id_seq+ type: SEQUENCE+ definition: ""+ comment: ""+ - text: user_id_seq+ type: SEQUENCE+ definition: ""+ comment: ""- text: t1type: TABLEdefinition: ""@@ -378,6 +414,10 @@comment: ""- input: SELECT * FROM test.|want:+ - text: order_id_seq+ type: SEQUENCE+ definition: ""+ comment: ""- text: autotype: TABLEdefinition: ""@@ -424,3 +464,26 @@type: VIEWdefinition: ""comment: ""+# Sequence-specific tests+- input: SELECT * FROM public.|+ want:+ - text: seq1+ type: SEQUENCE+ definition: ""+ comment: ""+ - text: user_id_seq+ type: SEQUENCE+ definition: ""+ comment: ""+ - text: t1+ type: TABLE+ definition: ""+ comment: ""+ - text: t2+ type: TABLE+ definition: ""+ comment: ""+ - text: v1+ type: VIEW+ definition: ""+ comment: ""diff --git a/backend/plugin/parser/plsql/completion.go b/backend/plugin/parser/plsql/completion.goindex 5e7e1ea0b6..504b03c7bf 100644--- a/backend/plugin/parser/plsql/completion.go+++ b/backend/plugin/parser/plsql/completion.go@@ -324,6 +324,17 @@ func (m CompletionMap) insertViews(c *Completer, schemas map[string]bool) {}}+func (m CompletionMap) insertSequences(c *Completer, schemas map[string]bool) {+ for schema := range schemas {+ for _, seq := range c.listSequences(schema) {+ m.Insert(base.Candidate{+ Type: base.CandidateTypeSequence,+ Text: c.quotedIdentifierIfNeeded(seq),+ })+ }+ }+}+func (m CompletionMap) insertTables(c *Completer, schemas map[string]bool) {for schema := range schemas {if len(schema) == 0 {@@ -462,6 +473,18 @@ func (c *Completer) listViews(schema string) []string {return c.metadataCache[schema].GetSchemaMetadata("").ListViewNames()}+func (c *Completer) listSequences(schema string) []string {+ if _, exists := c.metadataCache[schema]; !exists {+ _, metadata, err := c.getMetadata(c.ctx, c.instanceID, schema)+ if err != nil || metadata == nil {+ return nil+ }+ c.metadataCache[schema] = metadata+ }++ return c.metadataCache[schema].GetSchemaMetadata("").ListSequenceNames()+}+func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]base.Candidate, error) {keywordEntries := make(CompletionMap)runtimeFunctionEntries := make(CompletionMap)@@ -469,6 +492,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]tableEntries := make(CompletionMap)columnEntries := make(CompletionMap)viewEntries := make(CompletionMap)+ sequenceEntries := make(CompletionMap)for token, value := range candidates.Tokens {entry := c.parser.SymbolicNames[token]@@ -527,6 +551,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]tableEntries.insertTables(c, schemas)viewEntries.insertViews(c, schemas)+ sequenceEntries.insertSequences(c, schemas)}case plsql.PlSqlParserRULE_general_element:schema, table, flags := c.determineGeneralElementPartCandidates()@@ -556,6 +581,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]if flags&ObjectFlagsShowTables != 0 {tableEntries.insertTables(c, schemas)viewEntries.insertViews(c, schemas)+ sequenceEntries.insertSequences(c, schemas)for _, reference := range c.references {switch reference := reference.(type) {@@ -660,6 +686,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]result = append(result, tableEntries.toSlice()...)result = append(result, columnEntries.toSlice()...)result = append(result, viewEntries.toSlice()...)+ result = append(result, sequenceEntries.toSlice()...)return result, nil}diff --git a/backend/plugin/parser/plsql/completion_test.go b/backend/plugin/parser/plsql/completion_test.goindex fb58b8f50d..274026344f 100644--- a/backend/plugin/parser/plsql/completion_test.go+++ b/backend/plugin/parser/plsql/completion_test.go@@ -139,6 +139,14 @@ func getMetadataForTest(_ context.Context, _, databaseName string) (string, *mod`,},},+ Sequences: []*storepb.SequenceMetadata{+ {+ Name: "SEQ1",+ },+ {+ Name: "USER_ID_SEQ",+ },+ },},},}, nil, nil, storepb.Engine_ORACLE, true /* isObjectCaseSensitive */), nildiff --git a/backend/plugin/parser/plsql/test-data/test_completion.yaml b/backend/plugin/parser/plsql/test-data/test_completion.yamlindex 6c25206f75..90f5ecd701 100644--- a/backend/plugin/parser/plsql/test-data/test_completion.yaml+++ b/backend/plugin/parser/plsql/test-data/test_completion.yaml@@ -6,212 +6,311 @@type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: SELECT x.| FROM (SELECT * FROM t2) xwant:- text: C1type: COLUMNdefinition: ""comment: ""+ priority: 0- text: C2type: COLUMNdefinition: ""comment: ""+ priority: 0- input: WITH x AS (SELECT * FROM t2) SELECT x.| FROM x;want:- text: C1type: COLUMNdefinition: ""comment: ""+ priority: 0- text: C2type: COLUMNdefinition: ""comment: ""+ priority: 0- input: WITH x(x1, x2) AS (SELECT * FROM t2) SELECT x.| FROM x;want:- text: X1type: COLUMNdefinition: ""comment: ""+ priority: 0- text: X2type: COLUMNdefinition: ""comment: ""+ priority: 0- input: WITH x(x1, x2) AS (SELECT * FROM t2) SELECT | FROM xwant:- text: X1type: COLUMNdefinition: ""comment: ""+ priority: 0- text: X2type: COLUMNdefinition: ""comment: ""+ priority: 0- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: Xtype: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: SELECT c1 as eid, c2 as xid FROM t2 GROUP BY |want:- text: C1type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- text: C2type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- text: EIDtype: COLUMNdefinition: ""comment: ""+ priority: 0- text: XIDtype: COLUMNdefinition: ""comment: ""+ priority: 0- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: SELECT c1 as eid, c2 as xid FROM t2 ORDER BY |want:- text: C1type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- text: C2type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- text: EIDtype: COLUMNdefinition: ""comment: ""+ priority: 0- text: XIDtype: COLUMNdefinition: ""comment: ""+ priority: 0- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: SELECT c1 as eid FROM t1 ORDER BY |want:- text: C1type: COLUMNdefinition: SCHEMA1.T1 | int, NOT NULLcomment: ""+ priority: 0- text: EIDtype: COLUMNdefinition: ""comment: ""+ priority: 0- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: |-SELECT FROM basdkfjasldf;SELECT | FROM t1@@ -220,197 +319,292 @@type: COLUMNdefinition: SCHEMA1.T1 | int, NOT NULLcomment: ""+ priority: 0- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: SELECT | FROM (SELECT c1 FROM t1) cc1want:- text: C1type: COLUMNdefinition: ""comment: ""+ priority: 0- text: C1type: COLUMNdefinition: SCHEMA1.T1 | int, NOT NULLcomment: ""+ priority: 0- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: CC1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: SELECT cc1.| FROM t1 cc1 JOIN t2 on NOT cc1.c1 = t2.c1want:- text: C1type: COLUMNdefinition: SCHEMA1.T1 | int, NOT NULLcomment: ""+ priority: 0- input: SELECT * from t1 cc1 JOIN t2 on cc1.c1 = t2.|want:- text: C1type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- text: C2type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- input: SELECT * from t1 cc1 JOIN t2 on cc1.|want:- text: C1type: COLUMNdefinition: SCHEMA1.T1 | int, NOT NULLcomment: ""+ priority: 0- input: SELECT MAX(cc1.|) FROM t2 cc1want:- text: C1type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- text: C2type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- input: SELECT cc1.| FROM t2 cc1want:- text: C1type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- text: C2type: COLUMNdefinition: SCHEMA1.T2 | int, NOT NULLcomment: ""+ priority: 0- input: SELECT * FROM |want:- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: SELECT | FROM t1 xwant:- text: C1type: COLUMNdefinition: SCHEMA1.T1 | int, NOT NULLcomment: ""+ priority: 0- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: Xtype: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0- input: SELECT | FROM schema1.t1want:- text: C1type: COLUMNdefinition: SCHEMA1.T1 | int, NOT NULLcomment: ""+ priority: 0- text: SCHEMA1type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA2type: SCHEMAdefinition: ""comment: ""+ priority: 0- text: SCHEMA3type: SCHEMAdefinition: ""comment: ""+ priority: 0+ - text: SEQ1+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: USER_ID_SEQ+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: T1type: TABLEdefinition: ""comment: ""+ priority: 0- text: T2type: TABLEdefinition: ""comment: ""+ priority: 0- text: V1type: VIEWdefinition: ""comment: ""+ priority: 0diff --git a/backend/plugin/parser/tsql/completion.go b/backend/plugin/parser/tsql/completion.goindex 71eb8e41b8..7606415b66 100644--- a/backend/plugin/parser/tsql/completion.go+++ b/backend/plugin/parser/tsql/completion.go@@ -477,6 +477,50 @@ func (m CompletionMap) insertMetadataViews(c *Completer, linkedServer string, da}}+func (m CompletionMap) insertMetadataSequences(c *Completer, linkedServer string, database string, schema string) {+ if linkedServer != "" {+ return+ }++ databaseName, schemaName := c.defaultDatabase, c.defaultSchema+ if database != "" {+ databaseName = database+ }+ if schema != "" {+ schemaName = schema+ }+ if databaseName == "" || schemaName == "" {+ return+ }++ _, databaseMetadata, err := c.metadataGetter(c.ctx, c.instanceID, databaseName)+ if err != nil {+ return+ }+ if databaseMetadata == nil {+ return+ }+ for _, schema := range databaseMetadata.ListSchemaNames() {+ if strings.EqualFold(schema, schemaName) {+ schemaName = schema+ break+ }+ }++ schemaMetadata := databaseMetadata.GetSchemaMetadata(schemaName)+ if schemaMetadata == nil {+ return+ }+ for _, seq := range schemaMetadata.ListSequenceNames() {+ if _, ok := m[seq]; !ok {+ m[seq] = base.Candidate{+ Type: base.CandidateTypeSequence,+ Text: c.quotedIdentifierIfNeeded(seq),+ }+ }+ }+}+// quptedType is the type of quoted token, SQL Server allows quoted identifiers by different characters.// https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-ver16type quotedType int@@ -695,6 +739,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]tableEntries := make(CompletionMap)columnEntries := make(CompletionMap)viewEntries := make(CompletionMap)+ sequenceEntries := make(CompletionMap)for tokenCandidate, continuous := range candidates.Tokens {if tokenCandidate < 0 || tokenCandidate >= len(c.parser.SymbolicNames) {@@ -738,6 +783,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]if context.flags&objectFlagShowObject != 0 {tableEntries.insertMetadataTables(c, context.linkedServer, context.database, context.schema)viewEntries.insertMetadataViews(c, context.linkedServer, context.database, context.schema)+ sequenceEntries.insertMetadataSequences(c, context.linkedServer, context.database, context.schema)}if context.linkedServer == "" && context.database == "" && context.schema == "" && context.flags&objectFlagShowObject != 0 {// User do not specify the server, database and schema, and want us complete the objects, we should also insert the ctes.@@ -756,6 +802,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]if context.flags&objectFlagShowObject != 0 {tableEntries.insertMetadataTables(c, context.linkedServer, context.database, context.schema)viewEntries.insertMetadataViews(c, context.linkedServer, context.database, context.schema)+ sequenceEntries.insertMetadataSequences(c, context.linkedServer, context.database, context.schema)}if context.linkedServer == "" && context.database == "" && context.schema == "" && context.flags&objectFlagShowObject != 0 {// User do not specify the server, database and schema, and want us complete the objects, we should also insert the ctes.@@ -774,6 +821,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]if context.flags&objectFlagShowObject != 0 {tableEntries.insertMetadataTables(c, context.linkedServer, context.database, context.schema)viewEntries.insertMetadataViews(c, context.linkedServer, context.database, context.schema)+ sequenceEntries.insertMetadataSequences(c, context.linkedServer, context.database, context.schema)for _, reference := range c.references {switch reference := reference.(type) {case *base.PhysicalTableReference:@@ -894,6 +942,7 @@ func (c *Completer) convertCandidates(candidates *base.CandidatesCollection) ([]result = append(result, tableEntries.toSlice()...)result = append(result, columnEntries.toSlice()...)result = append(result, viewEntries.toSlice()...)+ result = append(result, sequenceEntries.toSlice()...)return result, nil}diff --git a/backend/plugin/parser/tsql/completion_test.go b/backend/plugin/parser/tsql/completion_test.goindex 5f227977cd..2287d42fad 100644--- a/backend/plugin/parser/tsql/completion_test.go+++ b/backend/plugin/parser/tsql/completion_test.go@@ -154,6 +154,14 @@ var databaseMetadatas = []*storepb.DatabaseSchemaMetadata{},},},+ Sequences: []*storepb.SequenceMetadata{+ {+ Name: "EmployeeIdSeq",+ },+ {+ Name: "OrderSeq",+ },+ },},{Name: "MySchema",diff --git a/backend/plugin/parser/tsql/test-data/test_completion.yaml b/backend/plugin/parser/tsql/test-data/test_completion.yamlindex f0ae37ce63..a5eb4e988f 100644--- a/backend/plugin/parser/tsql/test-data/test_completion.yaml+++ b/backend/plugin/parser/tsql/test-data/test_completion.yaml@@ -23,6 +23,16 @@definition: ""comment: ""priority: 0+ - text: EmployeeIdSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: OrderSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""@@ -91,6 +101,16 @@definition: ""comment: ""priority: 0+ - text: EmployeeIdSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: OrderSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""@@ -180,6 +200,16 @@definition: ""comment: ""priority: 0+ - text: EmployeeIdSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: OrderSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""@@ -243,6 +273,16 @@definition: ""comment: ""priority: 0+ - text: EmployeeIdSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: OrderSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""@@ -289,6 +329,16 @@definition: ""comment: ""priority: 0+ - text: EmployeeIdSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: OrderSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""@@ -307,6 +357,16 @@- description: Completion table in specify schemainput: SELECT * FROM dbo.|want:+ - text: EmployeeIdSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: OrderSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""@@ -340,6 +400,16 @@definition: ""comment: ""priority: 0+ - text: EmployeeIdSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0+ - text: OrderSeq+ type: SEQUENCE+ definition: ""+ comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""@@ -349,4 +419,4 @@type: TABLEdefinition: ""comment: ""- priority: 0\ No newline at end of file+ priority: 0diff --git a/backend/store/model/database.go b/backend/store/model/database.goindex 49823d937e..9a82d7807d 100644--- a/backend/store/model/database.go+++ b/backend/store/model/database.go@@ -459,6 +459,17 @@ func (s *SchemaMetadata) ListMaterializedViewNames() []string {return result}+// ListSequenceNames lists the sequence names.+func (s *SchemaMetadata) ListSequenceNames() []string {+ var result []string+ for _, sequence := range s.internalSequences {+ result = append(result, sequence.GetName())+ }++ slices.Sort(result)+ return result+}+// CreateTable creates a new table in the schema.// Returns the created TableMetadata or an error if the table already exists.func (s *SchemaMetadata) CreateTable(tableName string) (*TableMetadata, error) {