Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(completion): definition for mssql column (#12520)

rebelice70607cb14971
diff --git a/backend/plugin/parser/tsql/completion.go b/backend/plugin/parser/tsql/completion.go
index 0d087e8c46..6c2838e711 100644
--- a/backend/plugin/parser/tsql/completion.go
+++ b/backend/plugin/parser/tsql/completion.go
@@ -318,9 +318,16 @@ func (m CompletionMap) insertMetadataColumns(c *Completer, linkedServer string,
tableMetadata := schemaMetadata.GetTable(table)
for _, column := range tableMetadata.GetColumns() {
if _, ok := m[column.Name]; !ok {
+ definition := fmt.Sprintf("%s | %s", table, column.Type)
+ if !column.Nullable {
+ definition += ", NOT NULL"
+ }
+ comment := column.UserComment
m[column.Name] = base.Candidate{
- Type: base.CandidateTypeColumn,
- Text: c.quotedIdentifierIfNeeded(column.Name),
+ Type: base.CandidateTypeColumn,
+ Text: c.quotedIdentifierIfNeeded(column.Name),
+ Definition: definition,
+ Comment: comment,
}
}
}
diff --git a/backend/plugin/parser/tsql/completion_test.go b/backend/plugin/parser/tsql/completion_test.go
index 8551b77574..19cc7625e6 100644
--- a/backend/plugin/parser/tsql/completion_test.go
+++ b/backend/plugin/parser/tsql/completion_test.go
@@ -110,9 +110,11 @@ var databaseMetadatas = []*storepb.DatabaseSchemaMetadata{
Columns: []*storepb.ColumnMetadata{
{
Name: "Id",
+ Type: "int",
},
{
Name: "Name",
+ Type: "varchar",
},
},
},
@@ -121,9 +123,11 @@ var databaseMetadatas = []*storepb.DatabaseSchemaMetadata{
Columns: []*storepb.ColumnMetadata{
{
Name: "EmployeeId",
+ Type: "int",
},
{
Name: "Street",
+ Type: "varchar",
},
},
},
@@ -137,9 +141,11 @@ var databaseMetadatas = []*storepb.DatabaseSchemaMetadata{
Columns: []*storepb.ColumnMetadata{
{
Name: "Id",
+ Type: "int",
},
{
Name: "SalaryUpBound",
+ Type: "int",
},
},
},
@@ -158,9 +164,11 @@ var databaseMetadatas = []*storepb.DatabaseSchemaMetadata{
Columns: []*storepb.ColumnMetadata{
{
Name: "Id",
+ Type: "int",
},
{
Name: "ParentName",
+ Type: "varchar",
},
},
},
diff --git a/backend/plugin/parser/tsql/test-data/test_completion.yaml b/backend/plugin/parser/tsql/test-data/test_completion.yaml
index 7b4a74d8fb..fdf5b252cf 100644
--- a/backend/plugin/parser/tsql/test-data/test_completion.yaml
+++ b/backend/plugin/parser/tsql/test-data/test_completion.yaml
@@ -27,11 +27,11 @@
comment: ""
- text: EmployeeId
type: COLUMN
- definition: ""
+ definition: Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: ""
+ definition: Employees | int, NOT NULL
comment: ""
- text: IdAlias
type: COLUMN
@@ -39,22 +39,22 @@
comment: ""
- text: Name
type: COLUMN
- definition: ""
+ definition: Employees | varchar, NOT NULL
comment: ""
- text: Street
type: COLUMN
- definition: ""
+ definition: Address | varchar, NOT NULL
comment: ""
- description: Table alias referenced by select item
input: SELECT tableAlias.| FROM Employees AS tableAlias;
want:
- text: Id
type: COLUMN
- definition: ""
+ definition: Employees | int, NOT NULL
comment: ""
- text: Name
type: COLUMN
- definition: ""
+ definition: Employees | varchar, NOT NULL
comment: ""
- description: Full column name considering CTE
input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT MyCTE_01.| FROM MyCTE_01;
@@ -96,19 +96,19 @@
comment: ""
- text: EmployeeId
type: COLUMN
- definition: ""
+ definition: Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: ""
+ definition: Employees | int, NOT NULL
comment: ""
- text: Name
type: COLUMN
- definition: ""
+ definition: Employees | varchar, NOT NULL
comment: ""
- text: Street
type: COLUMN
- definition: ""
+ definition: Address | varchar, NOT NULL
comment: ""
- description: Asterisk appearred in select item list
input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT |.* FROM MyCTE_01 JOIN dbo.Address ON MyCTE_01.EmployeeID = dbo.Address.EmployeeID
@@ -143,19 +143,19 @@
comment: ""
- text: EmployeeId
type: COLUMN
- definition: ""
+ definition: Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: ""
+ definition: Employees | int, NOT NULL
comment: ""
- text: Name
type: COLUMN
- definition: ""
+ definition: Employees | varchar, NOT NULL
comment: ""
- text: Street
type: COLUMN
- definition: ""
+ definition: Address | varchar, NOT NULL
comment: ""
- description: Completion should not consider CTE if no schema specified
input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT * FROM MySchema.|
@@ -166,11 +166,11 @@
comment: ""
- text: Id
type: COLUMN
- definition: ""
+ definition: SalaryLevel | int, NOT NULL
comment: ""
- text: SalaryUpBound
type: COLUMN
- definition: ""
+ definition: SalaryLevel | int, NOT NULL
comment: ""
- description: Completion should consider CTE if no schema specified
input: WITH MyCTE_01 AS (SELECT * FROM dbo.Employees) SELECT * FROM |
@@ -205,19 +205,19 @@
comment: ""
- text: EmployeeId
type: COLUMN
- definition: ""
+ definition: Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: ""
+ definition: Employees | int, NOT NULL
comment: ""
- text: Name
type: COLUMN
- definition: ""
+ definition: Employees | varchar, NOT NULL
comment: ""
- text: Street
type: COLUMN
- definition: ""
+ definition: Address | varchar, NOT NULL
comment: ""
- description: Completion table in specify schema
input: SELECT * FROM dbo.|
@@ -232,19 +232,19 @@
comment: ""
- text: EmployeeId
type: COLUMN
- definition: ""
+ definition: Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: ""
+ definition: Employees | int, NOT NULL
comment: ""
- text: Name
type: COLUMN
- definition: ""
+ definition: Employees | varchar, NOT NULL
comment: ""
- text: Street
type: COLUMN
- definition: ""
+ definition: Address | varchar, NOT NULL
comment: ""
- description: Completion table for simple select
input: SELECT * FROM |
@@ -275,17 +275,17 @@
comment: ""
- text: EmployeeId
type: COLUMN
- definition: ""
+ definition: Address | int, NOT NULL
comment: ""
- text: Id
type: COLUMN
- definition: ""
+ definition: Employees | int, NOT NULL
comment: ""
- text: Name
type: COLUMN
- definition: ""
+ definition: Employees | varchar, NOT NULL
comment: ""
- text: Street
type: COLUMN
- definition: ""
+ definition: Address | varchar, NOT NULL
comment: ""