Skip to content

Commit

Permalink
Render tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ejcx committed Dec 27, 2024
1 parent 10e4a65 commit 9c54cf0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
18 changes: 2 additions & 16 deletions pql.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,22 +485,8 @@ func (sub *subquery) write(ctx *exprContext, sb *strings.Builder) error {
// Use the identifier name
sb.WriteString(id.Parts[0].Name)
}
sb.WriteString("' as \"render_")

// Simplified property naming
switch strings.ToLower(prop.Name.Name) {
case "xaxis", "x":
sb.WriteString("xaxis")
case "yaxis", "y":
sb.WriteString("yaxis")
case "title":
sb.WriteString("title")
case "series":
sb.WriteString("series")
default:
sb.WriteString("prop_")
sb.WriteString(prop.Name.Name)
}
sb.WriteString("' as \"render_prop_")
sb.WriteString(prop.Name.Name)
sb.WriteString("\"")
}

Expand Down
11 changes: 11 additions & 0 deletions testdata/Goldens/Render/input.pql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
StormEvents
| project State, EventType, DamageProperty
| extend foo=1
| summarize TotalDamage=sum(DamageProperty) by State
| sort by TotalDamage desc
| limit 10
| render barchart with (
title="Property Damage by State",
xtitle="State",
ytitle="Total Damage ($)"
)
5 changes: 5 additions & 0 deletions testdata/Goldens/Render/output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
State,TotalDamage,render_type,render_prop_title,render_prop_xtitle,render_prop_ytitle
FLORIDA,6200000,barchart,Property Damage by State,State,Total Damage ($)
MISSISSIPPI,20000,barchart,Property Damage by State,State,Total Damage ($)
GEORGIA,2000,barchart,Property Damage by State,State,Total Damage ($)
ATLANTIC SOUTH,0,barchart,Property Damage by State,State,Total Damage ($)
10 changes: 10 additions & 0 deletions testdata/Goldens/Render/output.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
WITH "__subquery0" AS (SELECT "State" AS "State", "EventType" AS "EventType", "DamageProperty" AS "DamageProperty" FROM "StormEvents"),
"__subquery1" AS (SELECT *, 1 AS "foo" FROM "__subquery0"),
"__subquery2" AS (SELECT "State" AS "State", sum("DamageProperty") AS "TotalDamage" FROM "__subquery1" GROUP BY "State"),
"__subquery3" AS (SELECT * FROM "__subquery2" ORDER BY "TotalDamage" DESC NULLS LAST LIMIT 10)
SELECT *,
'barchart' as "render_type",
'Property Damage by State' as "render_prop_title",
'State' as "render_prop_xtitle",
'Total Damage ($)' as "render_prop_ytitle"
FROM "__subquery3";
Empty file.

0 comments on commit 9c54cf0

Please sign in to comment.