Skip to content

Commit 7e518ba

Browse files
authored
Prefer custom SVG when getting stat var node hierarchy path (#980)
1 parent 77b63d7 commit 7e518ba

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

internal/server/v1/variable/ancestors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package variable
1616

1717
import (
1818
"context"
19+
"strings"
1920

2021
pb "github.com/datacommonsorg/mixer/internal/proto"
2122
"github.com/datacommonsorg/mixer/internal/server/resource"
@@ -42,6 +43,13 @@ func Ancestors(
4243
for {
4344
if parents, ok := cache.ParentSvg[curr]; ok {
4445
curr = parents[0]
46+
for _, parent := range parents {
47+
// Prefer parent from custom import group
48+
if strings.HasPrefix(parent, "dc/g/Custom_") {
49+
curr = parent
50+
break
51+
}
52+
}
4553
if curr == statvar.SvgRoot {
4654
break
4755
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"ancestors": [
3+
"dc/g/Custom_Atmosphere_Pollutant-CarbonMonoxide",
4+
"dc/g/Custom_Atmosphere_Pollutant",
5+
"dc/g/Custom_Atmosphere",
6+
"dc/g/Custom_Environment",
7+
"dc/g/Custom_Root"
8+
]
9+
}

internal/server/v1/variable/golden/variable_ancestors_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func TestVariableAncestors(t *testing.T) {
5050
"Count_Person_FoodInsecure",
5151
"memdb.json",
5252
},
53+
{
54+
"Max_Concentration_AirPollutant_CO",
55+
"custom.json",
56+
},
5357
} {
5458
resp, err := mixer.VariableAncestors(ctx, &pb.VariableAncestorsRequest{
5559
Node: c.node,
@@ -83,7 +87,7 @@ func TestVariableAncestors(t *testing.T) {
8387

8488
if err := test.TestDriver(
8589
"VariableAncestors",
86-
&test.TestOption{UseCache: true, UseMemdb: true},
90+
&test.TestOption{UseCache: true, UseMemdb: true, UseCustomTable: true},
8791
testSuite,
8892
); err != nil {
8993
t.Errorf("TestDriver() = %s", err)

0 commit comments

Comments
 (0)