Skip to content

Commit

Permalink
sql: add missing specs to plan diagrams
Browse files Browse the repository at this point in the history
This change allows missing specs (e.g., RestoreDataSpec and
SplitAndScatterSpec) to be shown in plan diagrams. Before this change a
plan involving these types would result in an error generating the
diagrams. Also added a test to make sure future specs implement the
`diagramCellType` interface, which is required to generate diagrams.

Release note: None
  • Loading branch information
rharding6373 committed Feb 18, 2022
1 parent 4996177 commit 607034a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/sql/execinfrapb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ go_test(
"//pkg/sql/types",
"//pkg/util/leaktest",
"//pkg/util/optional",
"@com_github_stretchr_testify//require",
],
)

Expand Down
26 changes: 26 additions & 0 deletions pkg/sql/execinfrapb/flow_diagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,17 @@ func (post *PostProcessSpec) summary() []string {
return res
}

// summary implements the diagramCellType interface.
func (c *RestoreDataSpec) summary() (string, []string) {
return "RestoreDataSpec", []string{}
}

// summary implements the diagramCellType interface.
func (c *SplitAndScatterSpec) summary() (string, []string) {
detail := fmt.Sprintf("%d chunks", len(c.Chunks))
return "SplitAndScatterSpec", []string{detail}
}

// summary implements the diagramCellType interface.
func (c *ReadImportDataSpec) summary() (string, []string) {
ss := make([]string, 0, len(c.Uri))
Expand All @@ -522,6 +533,21 @@ func (c *ReadImportDataSpec) summary() (string, []string) {
return "ReadImportData", ss
}

// summary implements the diagramCellType interface.
func (s *StreamIngestionDataSpec) summary() (string, []string) {
return "StreamIngestionData", []string{}
}

// summary implements the diagramCellType interface.
func (s *StreamIngestionFrontierSpec) summary() (string, []string) {
return "StreamIngestionFrontier", []string{}
}

// summary implements the diagramCellType interface.
func (s *IndexBackfillMergerSpec) summary() (string, []string) {
return "IndexBackfillMerger", []string{}
}

// summary implements the diagramCellType interface.
func (s *ExportSpec) summary() (string, []string) {
return "Exporter", []string{s.Destination}
Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/execinfrapb/flow_diagram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/stretchr/testify/require"
)

// compareDiagrams verifies that two JSON strings decode to equal diagramData
Expand Down Expand Up @@ -404,3 +405,10 @@ func TestPlanDiagramJoin(t *testing.T) {

compareDiagrams(t, s, expected)
}

func TestProcessorsImplementDiagramCellType(t *testing.T) {
pcu := reflect.ValueOf(ProcessorCoreUnion{})
for i := 0; i < pcu.NumField(); i++ {
require.Implements(t, (*diagramCellType)(nil), pcu.Field(i).Interface())
}
}

0 comments on commit 607034a

Please sign in to comment.