Skip to content

Commit

Permalink
Prefer custom SVG when getting stat var node hierarchy path (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
shifucun authored Nov 9, 2022
1 parent 77b63d7 commit 7e518ba
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/server/v1/variable/ancestors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package variable

import (
"context"
"strings"

pb "github.com/datacommonsorg/mixer/internal/proto"
"github.com/datacommonsorg/mixer/internal/server/resource"
Expand All @@ -42,6 +43,13 @@ func Ancestors(
for {
if parents, ok := cache.ParentSvg[curr]; ok {
curr = parents[0]
for _, parent := range parents {
// Prefer parent from custom import group
if strings.HasPrefix(parent, "dc/g/Custom_") {
curr = parent
break
}
}
if curr == statvar.SvgRoot {
break
}
Expand Down
9 changes: 9 additions & 0 deletions internal/server/v1/variable/golden/ancestors/custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ancestors": [
"dc/g/Custom_Atmosphere_Pollutant-CarbonMonoxide",
"dc/g/Custom_Atmosphere_Pollutant",
"dc/g/Custom_Atmosphere",
"dc/g/Custom_Environment",
"dc/g/Custom_Root"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func TestVariableAncestors(t *testing.T) {
"Count_Person_FoodInsecure",
"memdb.json",
},
{
"Max_Concentration_AirPollutant_CO",
"custom.json",
},
} {
resp, err := mixer.VariableAncestors(ctx, &pb.VariableAncestorsRequest{
Node: c.node,
Expand Down Expand Up @@ -83,7 +87,7 @@ func TestVariableAncestors(t *testing.T) {

if err := test.TestDriver(
"VariableAncestors",
&test.TestOption{UseCache: true, UseMemdb: true},
&test.TestOption{UseCache: true, UseMemdb: true, UseCustomTable: true},
testSuite,
); err != nil {
t.Errorf("TestDriver() = %s", err)
Expand Down

0 comments on commit 7e518ba

Please sign in to comment.