Skip to content
Merged
Show file tree
Hide file tree
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
62 changes: 42 additions & 20 deletions cmd/hclexp/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,26 +409,27 @@ type indexData struct {
}

type objectData struct {
Title string
Base string // URL prefix for links (manifest mode); "" in single mode
Label string // schema label shown in the nav (manifest mode); "" otherwise
Database string
Kind string
KindLabel string
Name string
View string // "html" | "ddl" | "hcl"
HTMLHref string
DDLHref string
HCLHref string
Props []kv
Tables []tableSection
Query string
RawSQL string
Code string // rendered DDL or HCL for those views
FlowAnchor string // anchor on /flows when this object participates in a flow
Problems []problemView
DependsOn []objLink
DependedBy []objLink
Title string
Base string // URL prefix for links (manifest mode); "" in single mode
Label string // schema label shown in the nav (manifest mode); "" otherwise
Database string
Kind string
KindLabel string
Name string
View string // "html" | "ddl" | "hcl"
HTMLHref string
DDLHref string
HCLHref string
Props []kv
Tables []tableSection
Projections []projectionView
Query string
RawSQL string
Code string // rendered DDL or HCL for those views
FlowAnchor string // anchor on /flows when this object participates in a flow
Problems []problemView
DependsOn []objLink
DependedBy []objLink
}

// columnCollapseLimit is the row count above which a collapsible column list is
Expand Down Expand Up @@ -563,6 +564,7 @@ func (s *webServer) buildHTMLView(data *objectData, db *hclload.DatabaseSpec, ki
if sec, ok := constraintsSection(t.Constraints); ok {
data.Tables = append(data.Tables, sec)
}
data.Projections = projectionViews(t.Projections)
case hclload.KindMaterializedView:
mv := findMaterializedView(db, name)
if mv == nil {
Expand Down Expand Up @@ -770,6 +772,26 @@ func constraintsSection(cs []hclload.ConstraintSpec) (tableSection, bool) {
return sec, true
}

// projectionView is a table projection rendered on the object page: its name and
// canonical SELECT, shown as a query block like a materialized view's query.
type projectionView struct {
Name string
Query string
}

// projectionViews maps a table's projections to their rendered views. Returns
// nil when the table has none (the template omits the section).
func projectionViews(ps []hclload.ProjectionSpec) []projectionView {
if len(ps) == 0 {
return nil
}
views := make([]projectionView, 0, len(ps))
for _, p := range ps {
views = append(views, projectionView{Name: p.Name, Query: p.Query})
}
return views
}

func dictAttributesSection(attrs []hclload.DictionaryAttribute) tableSection {
sec := tableSection{Title: "Attributes", Headers: []string{"name", "type", "default", "expression"}}
for _, a := range attrs {
Expand Down
4 changes: 4 additions & 0 deletions cmd/hclexp/web/object.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ <h2>{{.Title}}{{if .Collapsible}} <span class="count">{{len .Rows}}</span>{{end}
</table>
{{end}}

{{if .Projections}}<h2>Projections</h2>
{{range .Projections}}<h3 class="proj">{{.Name}}</h3><pre class="code">{{.Query}}</pre>{{end}}
{{end}}

{{if .Query}}<h2>Query</h2><pre class="code">{{.Query}}</pre>{{end}}
{{if .RawSQL}}<h2>SQL</h2><pre class="code">{{.RawSQL}}</pre>{{end}}
{{else}}
Expand Down
12 changes: 12 additions & 0 deletions cmd/hclexp/web_sections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ func TestWebSections_ConstraintsSection(t *testing.T) {
}, sec)
}

func TestWebSections_ProjectionViews(t *testing.T) {
assert.Nil(t, projectionViews(nil))

views := projectionViews(sectionsSchema().Databases[0].Tables[0].Projections)
assert.Equal(t, []projectionView{
{Name: "proj_by_ts", Query: "SELECT ts, id ORDER BY ts"},
}, views)
}

func TestWebSections_BuildHTMLViewNotFound(t *testing.T) {
srv, err := newWebServer(sectionsSchema())
require.NoError(t, err)
Expand Down Expand Up @@ -247,6 +256,9 @@ func TestWebSections_TablePage(t *testing.T) {
assert.Contains(t, body, "Constraints")
assert.Contains(t, body, "c_positive")
assert.Contains(t, body, "assume")
assert.Contains(t, body, "Projections")
assert.Contains(t, body, "proj_by_ts")
assert.Contains(t, body, "SELECT ts, id ORDER BY ts")
}

func TestWebSections_MaterializedViewPage(t *testing.T) {
Expand Down
Loading