Skip to content

Commit

Permalink
Add query plans to the html
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Dec 12, 2024
1 parent ff2bae4 commit aa1ba18
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go/summarize/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ func renderPlansSection(md *markdown.MarkDown, analysis PlanAnalysis) error {
md.PrintTable(headers, rows)
md.NewLine()

err := renderQueryPlans(md, analysis.simpleRouted, planalyze.SimpleRouted.String())
err := renderQueryPlans(md, analysis.SimpleRoutedQ, planalyze.SimpleRouted.String())
if err != nil {
return err
}
return renderQueryPlans(md, analysis.complex, planalyze.Complex.String())
return renderQueryPlans(md, analysis.ComplexQ, planalyze.Complex.String())
}

func renderQueryPlans(md *markdown.MarkDown, queries []planalyze.AnalyzedQuery, title string) error {
Expand Down
4 changes: 2 additions & 2 deletions go/summarize/summarize-planalyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func summarizePlanAnalyze(s *Summary, data planalyze.Output) (err error) {
s.addPlanResult(data.SimpleRouted)
s.addPlanResult(data.Complex)

s.PlanAnalysis.simpleRouted = append(s.PlanAnalysis.simpleRouted, data.SimpleRouted...)
s.PlanAnalysis.complex = append(s.PlanAnalysis.complex, data.Complex...)
s.PlanAnalysis.SimpleRoutedQ = append(s.PlanAnalysis.SimpleRoutedQ, data.SimpleRouted...)
s.PlanAnalysis.ComplexQ = append(s.PlanAnalysis.ComplexQ, data.Complex...)
return nil
}
4 changes: 2 additions & 2 deletions go/summarize/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ type (
Unplannable int
Total int

simpleRouted []planalyze.AnalyzedQuery
complex []planalyze.AnalyzedQuery
SimpleRoutedQ []planalyze.AnalyzedQuery
ComplexQ []planalyze.AnalyzedQuery
}
)

Expand Down
41 changes: 41 additions & 0 deletions go/web/templates/summarize.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,47 @@ <h1>Query Analysis Report</h1>
</table>
</div>

<button class="collapsible">Query Plans</button>
<div class="content">
<h3>Simple Routed Queries</h3>
{{range $index, $query := .PlanAnalysis.SimpleRoutedQ}}
<table>
<thead>
<tr>
<th>Query</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">{{$query.QueryStructure}}</td>
</tr>
</tbody>
</table>
<pre>
{{- jsonToString $query.PlanOutput}}
</pre>
{{end}}

<h3>Complex Queries</h3>
{{range $index, $query := .PlanAnalysis.ComplexQ}}
<table>
<thead>
<tr>
<th>Query</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">{{$query.QueryStructure}}</td>
</tr>
</tbody>
</table>
<pre>
{{- jsonToString $query.PlanOutput}}
</pre>
{{end}}
</div>

<button class="collapsible">Top Queries</button>
<div class="content">
<table>
Expand Down
5 changes: 5 additions & 0 deletions go/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ type SummaryOutput struct {

func getFuncMap() template.FuncMap {
return template.FuncMap{
"jsonToString": func(j json.RawMessage) string {
var formattedJSON bytes.Buffer
_ = json.Indent(&formattedJSON, j, "", " ")
return formattedJSON.String()
},
"add": func(a, b int) int { return a + b },
"divide": func(a, b any) float64 {
if b == 0 || b == nil {
Expand Down

0 comments on commit aa1ba18

Please sign in to comment.