MCPcopy Create free account
hub / github.com/bytebase/bytebase / getNormalColumnsLower

Function getNormalColumnsLower

backend/plugin/parser/tidb/restore.go:94–121  ·  view source on GitHub ↗

getNormalColumnsLower returns a lowercased set of regular (non- generated) column names for the given table. Used by updateMutatesTable to determine whether an unqualified SET column belongs to the target table — without this, multi-table UPDATEs where unqualified SETs reference columns of the joine

(ctx context.Context, rCtx base.RestoreContext, database, table string)

Source from the content-addressed store, hash-verified

92// where unqualified SETs reference columns of the joined-but-not-
93// target table would be mis-classified as mutating the target.
94func getNormalColumnsLower(ctx context.Context, rCtx base.RestoreContext, database, table string) (map[string]bool, error) {
95 if rCtx.GetDatabaseMetadataFunc == nil {
96 return nil, errors.Errorf("GetDatabaseMetadataFunc is nil")
97 }
98 _, metadata, err := rCtx.GetDatabaseMetadataFunc(ctx, rCtx.InstanceID, database)
99 if err != nil {
100 return nil, errors.Wrapf(err, "failed to get database metadata for %s", database)
101 }
102 if metadata == nil {
103 return nil, errors.Errorf("database metadata is nil for %s", database)
104 }
105 schema := metadata.GetSchemaMetadata("")
106 if schema == nil {
107 return nil, errors.Errorf("schema is nil for %s", database)
108 }
109 tableMetadata := schema.GetTable(table)
110 if tableMetadata == nil {
111 return nil, errors.Errorf("table metadata is nil for %s.%s", database, table)
112 }
113 result := make(map[string]bool)
114 for _, col := range tableMetadata.GetProto().Columns {
115 if col == nil || col.Generation != nil {
116 continue
117 }
118 result[strings.ToLower(col.Name)] = true
119 }
120 return result, nil
121}
122
123// findMatchingDMLs returns ALL UPDATE/DELETE nodes in the parsed statement
124// list that reference the target table. The single-DML form (return-on-

Callers 1

GenerateRestoreSQLFunction · 0.85

Calls 5

ErrorfMethod · 0.80
GetSchemaMetadataMethod · 0.80
GetTableMethod · 0.45
GetProtoMethod · 0.45

Tested by

no test coverage detected