Skip to content

Commit

Permalink
source-sqlserver: Exclude computed columns from discovery too
Browse files Browse the repository at this point in the history
Since we neither backfill nor replicate the values of computed
columns it would be a little silly to continue mentioning them
in the discovered schemas.
  • Loading branch information
willdonnelly committed Oct 1, 2024
1 parent 360739e commit b27d9fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 0 additions & 4 deletions source-sqlserver/.snapshots/TestComputedColumn-discovery
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ Binding 0:
"null"
]
},
"computed": {
"type": "string",
"description": "(source type: non-nullable varchar(64))"
},
"id": {
"type": "integer",
"description": "(source type: non-nullable int)"
Expand Down
16 changes: 12 additions & 4 deletions source-sqlserver/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ func (db *sqlserverDatabase) discoverTables(ctx context.Context) (map[sqlcapture
table.OmitBinding = true
}
tableMap[streamID] = table

if details, ok := table.ExtraDetails.(*sqlserverTableDiscoveryDetails); ok {
details.ComputedColumns = computedColumns[streamID]
}
}
for _, column := range columns {
var streamID = sqlcapture.JoinStreamID(column.TableSchema, column.TableName)
Expand Down Expand Up @@ -99,6 +95,18 @@ func (db *sqlserverDatabase) discoverTables(ctx context.Context) (map[sqlcapture
tableMap[id] = info
}

// Add computed columns information
for streamID, table := range tableMap {
if details, ok := table.ExtraDetails.(*sqlserverTableDiscoveryDetails); ok {
details.ComputedColumns = computedColumns[streamID]
}
for _, columnName := range computedColumns[streamID] {
var info = table.Columns[columnName]
info.OmitColumn = true
table.Columns[columnName] = info
}
}

// For tables which have no primary key but have a valid secondary index,
// fill in that secondary index as the 'primary key' for our purposes.
for streamID, indexColumns := range secondaryIndexes {
Expand Down
4 changes: 4 additions & 0 deletions sqlcapture/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func DiscoverCatalog(ctx context.Context, db Database) ([]*pc.Response_Discovere
// Build `properties` schemas for each table column.
var properties = make(map[string]*jsonschema.Schema)
for _, column := range table.Columns {
if column.OmitColumn {
continue // Skip adding properties corresponding to omitted columns
}

var jsonType, err = db.TranslateDBToJSONType(column)
if err != nil {
// Unhandled types are translated to the catch-all schema {} but with
Expand Down
1 change: 1 addition & 0 deletions sqlcapture/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,5 @@ type ColumnInfo struct {
IsNullable bool // True if the column can contain nulls.
DataType interface{} // The datatype of this column. May be a string name or a more complex struct.
Description *string // Stored description of the column, if any.
OmitColumn bool // True if the column should be omitted from discovery JSON schema generation.
}

0 comments on commit b27d9fa

Please sign in to comment.