MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / getRefLabelFromConstraint

Method getRefLabelFromConstraint

dgraph/cmd/migrate/dump.go:267–293  ·  view source on GitHub ↗

getRefLabelFromConstraint returns a ref label based on a foreign key constraint. Consider the foreign key constraint foreign key (person_company, person_employee_id) references person (company, employee_id) and a row with the following values in the table Google, 100, 50.0 (salary) where Google is t

(foreignTableInfo *sqlTable,
	constraint *fkConstraint)

Source from the content-addressed store, hash-verified

265// the refLabel will use the foreign table name, foreign column names and the local row's values,
266// yielding the value of _:person_company_Google_employee_id_100
267func (row *sqlRow) getRefLabelFromConstraint(foreignTableInfo *sqlTable,
268 constraint *fkConstraint) (string, error) {
269 if constraint.foreignIndices == nil {
270 foreignKeyColumnNames := make(map[string]string)
271 for _, part := range constraint.parts {
272 foreignKeyColumnNames[part.columnName] = part.remoteColumnName
273 }
274
275 constraint.foreignIndices = getColumnIndices(row.tableInfo,
276 func(info *sqlTable, column string) bool {
277 _, ok := foreignKeyColumnNames[column]
278 return ok
279 })
280
281 // replace the column names to be the foreign column names
282 for _, colIdx := range constraint.foreignIndices {
283 colIdx.name = foreignKeyColumnNames[colIdx.name]
284 }
285 }
286
287 return createLabel(&ref{
288 allColumns: foreignTableInfo.columns,
289 refColumnIndices: constraint.foreignIndices,
290 tableName: foreignTableInfo.tableName,
291 colValues: row.values,
292 })
293}

Callers 1

outputConstraintsMethod · 0.80

Calls 2

getColumnIndicesFunction · 0.85
createLabelFunction · 0.85

Tested by

no test coverage detected