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 d1e9cd1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/sql/execinfrapb/flow_diagram.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,16 @@ func (post *PostProcessSpec) summary() []string {
return res
}

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 +532,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 d1e9cd1

Please sign in to comment.