Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/server/spanner/dsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,14 @@ func isCuratedHierarchy(svg string) bool {
return strings.HasPrefix(svg, "dc/g/UN") || strings.HasPrefix(svg, "dc/g/SDG")
}

// isCustomHierarchy checks if the SVG is part of a non-base DC.
func isCustomHierarchy(svg string) bool {
return !strings.HasPrefix(svg, "dc/")
}
Comment on lines +816 to +819

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The name isCustomHierarchy is potentially misleading because "Custom" is already used in the codebase (e.g., CustomSVGPrefix = "dc/g/Custom_") to refer to local custom SVGs, which do start with dc/. Since this function specifically checks for SVGs from a non-base Data Commons instance (which do not start with dc/), renaming it to isNonBaseDCHierarchy or isExternalHierarchy would be much clearer and prevent future confusion. Additionally, adding a check for an empty string makes the helper more robust.

Suggested change
// isCustomHierarchy checks if the SVG is part of a non-base DC.
func isCustomHierarchy(svg string) bool {
return !strings.HasPrefix(svg, "dc/")
}
// isNonBaseDCHierarchy checks if the SVG is part of a non-base DC.
func isNonBaseDCHierarchy(svg string) bool {
return svg != "" && !strings.HasPrefix(svg, "dc/")
}
References
  1. Ensure that function docstrings accurately reflect the function's signature and return values.


// getSpecializedEntity returns the specialized entity for a child SVG given its parent SVG.
func getSpecializedEntity(parent, child, childName string) string {
if !strings.Contains(child, "_") || isCuratedHierarchy(child) { // Child is likely curated.
if childName != "" && (!strings.Contains(child, "_") || isCuratedHierarchy(child) || isCustomHierarchy(child)) { // Child is likely curated.
return childName
}
Comment on lines 822 to 825

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the call to use the renamed isNonBaseDCHierarchy function for clarity.

Suggested change
func getSpecializedEntity(parent, child, childName string) string {
if !strings.Contains(child, "_") || isCuratedHierarchy(child) { // Child is likely curated.
if childName != "" && (!strings.Contains(child, "_") || isCuratedHierarchy(child) || isCustomHierarchy(child)) { // Child is likely curated.
return childName
}
func getSpecializedEntity(parent, child, childName string) string {
if childName != "" && (!strings.Contains(child, "_") || isCuratedHierarchy(child) || isNonBaseDCHierarchy(child)) { // Child is likely curated.
return childName
}

parentParts := processSvgId(parent)
Expand Down
Loading