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: column order (#15904)
rebelice476ba1203e32
diff --git a/backend/api/lsp/completion.go b/backend/api/lsp/completion.goindex 8aadd86bee..7763e62b76 100644--- a/backend/api/lsp/completion.go+++ b/backend/api/lsp/completion.go@@ -100,24 +100,24 @@ func (h *Handler) handleTextDocumentCompletion(ctx context.Context, _ *jsonrpc2.func generateSortText(_ lsp.CompletionParams, _ storepb.Engine, candidate parserbase.Candidate) string {switch candidate.Type {case parserbase.CandidateTypeColumn:- return "01" + candidate.Text+ return "01" + candidate.TextWithPriority()case parserbase.CandidateTypeSchema:- return "02" + candidate.Text+ return "02" + candidate.TextWithPriority()case parserbase.CandidateTypeTable, parserbase.CandidateTypeForeignTable:- return "03" + candidate.Text+ return "03" + candidate.TextWithPriority()case parserbase.CandidateTypeView, parserbase.CandidateTypeMaterializedView:- return "04" + candidate.Text+ return "04" + candidate.TextWithPriority()case parserbase.CandidateTypeFunction:- return "05" + candidate.Text+ return "05" + candidate.TextWithPriority()case parserbase.CandidateTypeKeyword:switch candidate.Text {case "SELECT", "SHOW", "SET", "FROM", "WHERE":- return "09" + candidate.Text+ return "09" + candidate.TextWithPriority()default:- return "10" + candidate.Text+ return "10" + candidate.TextWithPriority()}default:- return "10" + string(candidate.Type) + candidate.Text+ return "10" + string(candidate.Type) + candidate.TextWithPriority()}}diff --git a/backend/plugin/parser/base/complete.go b/backend/plugin/parser/base/complete.goindex abd08596a1..bdc36dd79c 100644--- a/backend/plugin/parser/base/complete.go+++ b/backend/plugin/parser/base/complete.go@@ -37,6 +37,12 @@ type Candidate struct {Type CandidateTypeDefinition stringComment string+ // The smaller the number, the higher the priority.+ Priority int+}++func (c Candidate) TextWithPriority() string {+ return fmt.Sprintf("%d.%s", c.Priority, c.Text)}func (c Candidate) String() string {diff --git a/backend/plugin/parser/tsql/completion.go b/backend/plugin/parser/tsql/completion.goindex 0a83c69d23..4400472ad8 100644--- a/backend/plugin/parser/tsql/completion.go+++ b/backend/plugin/parser/tsql/completion.go@@ -295,6 +295,7 @@ func (m CompletionMap) insertAllColumns(c *Completer) {Text: c.quotedIdentifierIfNeeded(column.Name),Definition: definition,Comment: comment,+ Priority: c.getPriority(c.defaultDatabase, schema, table),}}}@@ -302,6 +303,23 @@ func (m CompletionMap) insertAllColumns(c *Completer) {}}+func (c *Completer) getPriority(database string, schema string, table string) int {+ if database == "" {+ database = c.defaultDatabase+ }+ if schema == "" {+ schema = c.defaultSchema+ }+ if c.referenceMap == nil {+ return 1+ }+ if c.referenceMap[fmt.Sprintf("%s.%s.%s", database, schema, table)] {+ // The higher priority.+ return 0+ }+ return 1+}+func (m CompletionMap) insertMetadataColumns(c *Completer, linkedServer string, database string, schema string, table string) {if linkedServer != "" {return@@ -370,6 +388,7 @@ func (m CompletionMap) insertMetadataColumns(c *Completer, linkedServer string,Text: c.quotedIdentifierIfNeeded(column.Name),Definition: definition,Comment: comment,+ Priority: c.getPriority(c.defaultDatabase, schema, table),}}}@@ -482,6 +501,7 @@ type Completer struct {// references is the flattened table references.// It's helpful to look up the table reference.references []base.TableReference+ referenceMap map[string]boolcteCache map[int][]*base.VirtualTableReferencecteTables []*base.VirtualTableReferencecaretTokenIsQuoted quotedType@@ -1260,8 +1280,25 @@ func notEmptySQLCount(list []base.SingleSQL) int {}func (c *Completer) takeReferencesSnapshot() {+ if c.referenceMap == nil {+ c.referenceMap = make(map[string]bool)+ }for _, references := range c.referencesStack {c.references = append(c.references, references...)+ for _, reference := range references {+ if r, ok := reference.(*base.PhysicalTableReference); ok {+ database := r.Database+ if database == "" {+ database = c.defaultDatabase+ }+ schema := r.Schema+ if schema == "" {+ schema = c.defaultSchema+ }+ tableID := fmt.Sprintf("%s.%s.%s", database, schema, r.Table)+ c.referenceMap[tableID] = true+ }+ }}}diff --git a/backend/plugin/parser/tsql/test-data/test_completion.yaml b/backend/plugin/parser/tsql/test-data/test_completion.yamlindex dce6d39edb..7546dd97a5 100644--- a/backend/plugin/parser/tsql/test-data/test_completion.yaml+++ b/backend/plugin/parser/tsql/test-data/test_completion.yaml@@ -7,26 +7,32 @@type: DATABASEdefinition: ""comment: ""+ priority: 0- text: Schooltype: DATABASEdefinition: ""comment: ""+ priority: 0- text: MySchematype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: dbotype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""comment: ""+ priority: 0- text: Employeestype: TABLEdefinition: ""comment: ""+ priority: 0- description: Column alias can be used in order by clauseinput: SELECT Id AS IdAlias, Name FROM Employees ORDER BY |;want:@@ -34,54 +40,67 @@type: COLUMNdefinition: Company.dbo.Address | int, NOT NULLcomment: ""+ priority: 1- text: Idtype: COLUMNdefinition: Company.MySchema.SalaryLevel | int, NOT NULLcomment: ""+ priority: 1- text: Idtype: COLUMNdefinition: Company.dbo.Employees | int, NOT NULLcomment: ""+ priority: 0- text: IdAliastype: COLUMNdefinition: ""comment: ""+ priority: 0- text: Nametype: COLUMNdefinition: Company.dbo.Employees | varchar, NOT NULLcomment: ""+ priority: 0- text: SalaryUpBoundtype: COLUMNdefinition: Company.MySchema.SalaryLevel | int, NOT NULLcomment: ""+ priority: 1- text: Streettype: COLUMNdefinition: Company.dbo.Address | varchar, NOT NULLcomment: ""+ priority: 1- text: Companytype: DATABASEdefinition: ""comment: ""+ priority: 0- text: Schooltype: DATABASEdefinition: ""comment: ""+ priority: 0- text: MySchematype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: dbotype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""comment: ""+ priority: 0- text: Employeestype: TABLEdefinition: ""comment: ""+ priority: 0- description: Table alias referenced by select iteminput: SELECT tableAlias.| FROM Employees AS tableAlias;want:@@ -89,10 +108,12 @@type: COLUMNdefinition: Company.dbo.Employees | int, NOT NULLcomment: ""+ priority: 0- text: Nametype: COLUMNdefinition: Company.dbo.Employees | varchar, NOT NULLcomment: ""+ priority: 0- description: Full column name considering CTEinput: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT MyCTE_01.| FROM MyCTE_01;want:@@ -100,10 +121,12 @@type: COLUMNdefinition: ""comment: ""+ priority: 0- text: Nametype: COLUMNdefinition: ""comment: ""+ priority: 0- description: Full column nameinput: SELECT | FROM Employees;want:@@ -111,50 +134,62 @@type: COLUMNdefinition: Company.dbo.Address | int, NOT NULLcomment: ""+ priority: 1- text: Idtype: COLUMNdefinition: Company.MySchema.SalaryLevel | int, NOT NULLcomment: ""+ priority: 1- text: Idtype: COLUMNdefinition: Company.dbo.Employees | int, NOT NULLcomment: ""+ priority: 0- text: Nametype: COLUMNdefinition: Company.dbo.Employees | varchar, NOT NULLcomment: ""+ priority: 0- text: SalaryUpBoundtype: COLUMNdefinition: Company.MySchema.SalaryLevel | int, NOT NULLcomment: ""+ priority: 1- text: Streettype: COLUMNdefinition: Company.dbo.Address | varchar, NOT NULLcomment: ""+ priority: 1- text: Companytype: DATABASEdefinition: ""comment: ""+ priority: 0- text: Schooltype: DATABASEdefinition: ""comment: ""+ priority: 0- text: MySchematype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: dbotype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""comment: ""+ priority: 0- text: Employeestype: TABLEdefinition: ""comment: ""+ priority: 0- description: Asterisk appearred in select item listinput: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT |.* FROM MyCTE_01 JOIN dbo.Address ON MyCTE_01.EmployeeID = dbo.Address.EmployeeIDwant:@@ -162,54 +197,67 @@type: COLUMNdefinition: Company.dbo.Address | int, NOT NULLcomment: ""+ priority: 0- text: Idtype: COLUMNdefinition: Company.MySchema.SalaryLevel | int, NOT NULLcomment: ""+ priority: 1- text: Idtype: COLUMNdefinition: Company.dbo.Employees | int, NOT NULLcomment: ""+ priority: 0- text: Nametype: COLUMNdefinition: Company.dbo.Employees | varchar, NOT NULLcomment: ""+ priority: 0- text: SalaryUpBoundtype: COLUMNdefinition: Company.MySchema.SalaryLevel | int, NOT NULLcomment: ""+ priority: 1- text: Streettype: COLUMNdefinition: Company.dbo.Address | varchar, NOT NULLcomment: ""+ priority: 0- text: Companytype: DATABASEdefinition: ""comment: ""+ priority: 0- text: Schooltype: DATABASEdefinition: ""comment: ""+ priority: 0- text: MySchematype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: dbotype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""comment: ""+ priority: 0- text: Employeestype: TABLEdefinition: ""comment: ""+ priority: 0- text: MyCTE_01type: TABLEdefinition: ""comment: ""+ priority: 0- description: Completion should not consider CTE if no schema specifiedinput: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT * FROM MySchema.|want:@@ -217,6 +265,7 @@type: TABLEdefinition: ""comment: ""+ priority: 0- description: Completion should consider CTE if no schema specifiedinput: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT * FROM |want:@@ -224,30 +273,37 @@type: DATABASEdefinition: ""comment: ""+ priority: 0- text: Schooltype: DATABASEdefinition: ""comment: ""+ priority: 0- text: MySchematype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: dbotype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""comment: ""+ priority: 0- text: Employeestype: TABLEdefinition: ""comment: ""+ priority: 0- text: MyCTE_01type: TABLEdefinition: ""comment: ""+ priority: 0- description: Completion table in specify schemainput: SELECT * FROM dbo.|want:@@ -255,10 +311,12 @@type: TABLEdefinition: ""comment: ""+ priority: 0- text: Employeestype: TABLEdefinition: ""comment: ""+ priority: 0- description: Completion table for simple selectinput: SELECT * FROM |want:@@ -266,23 +324,29 @@type: DATABASEdefinition: ""comment: ""+ priority: 0- text: Schooltype: DATABASEdefinition: ""comment: ""+ priority: 0- text: MySchematype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: dbotype: SCHEMAdefinition: ""comment: ""+ priority: 0- text: Addresstype: TABLEdefinition: ""comment: ""+ priority: 0- text: Employeestype: TABLEdefinition: ""comment: ""+ priority: 0