-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathweak_alias.go
68 lines (57 loc) · 1.89 KB
/
weak_alias.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package skbtrace
// Helper for weak alias filters: picks whichever object is more likely
// to appear based on other filters and print statements
type builderObjectSet map[string]struct{}
type weakAliasRef interface {
Ref() *fieldAliasRef
Level() ErrorLevel
Resolve(fg *FieldGroup)
}
func (b *Builder) newBuildObjectSet(
filters [][]*ProcessedFilter, rows []string, hints []string,
) builderObjectSet {
boSet := make(builderObjectSet)
b.deduceFilterObjects(boSet, filters)
b.deduceDumpObjects(boSet, rows)
b.deduceDumpObjects(boSet, hints)
return boSet
}
func (b *Builder) deduceDumpObjects(boSet builderObjectSet, rows []string) {
if len(rows) == 0 {
return
}
for _, row := range rows {
if fgList, ok := b.fieldGroupMap[row]; ok {
boSet[fgList[0].Object] = struct{}{}
}
}
}
func (b *Builder) deduceFilterObjects(boSet builderObjectSet, filters [][]*ProcessedFilter) {
for _, filterChunk := range filters {
for _, filter := range filterChunk {
if filter.frefs[0].fg == nil {
continue
}
boSet[filter.frefs[0].fg.Object] = struct{}{}
}
}
}
// resolveWeakAliasRefs resolves field references in processed filters which do not have
// pointer to FieldGroup for filters which use fields with field aliases for which
// source object is not known due to weak aliasing logic. boSet contains set of objects
// which will be produced in this trace script due to dump rows, other filters, keys, etc.
// If deduction is failed due to lack of respective object hints, error is returned
func (b *Builder) resolveWeakAliasRefs(refs []weakAliasRef, boSet builderObjectSet) error {
loop:
for _, ref := range refs {
for _, fg := range ref.Ref().weakGroups {
if _, ok := boSet[fg.Object]; ok {
ref.Resolve(fg)
continue loop
}
}
return newErrorf(ref.Level(), ref.Ref().field.Name, nil,
"object cannot be deduced for weak alias from rows, filters and hints")
}
return nil
}