Skip to content

Commit

Permalink
feat: add file type to json output
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Nov 25, 2024
1 parent 6b3c7b1 commit 2781aa8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
8 changes: 5 additions & 3 deletions go/summarize/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ const (
traceFile
keysFile
dbInfoFile
transactionFile
)

var fileTypeMap = map[string]fileType{ //nolint:gochecknoglobals // this is instead of a const
"trace": traceFile,
"keys": keysFile,
"dbinfo": dbInfoFile,
"trace": traceFile,
"keys": keysFile,
"dbinfo": dbInfoFile,
"transactions": transactionFile,
}

// getFileType reads the first key-value pair from a JSON file and returns the type of the file
Expand Down
33 changes: 18 additions & 15 deletions go/testdata/small-slow-query-transactions.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
[
{
"query-signatures": [
"update tblA where foo = :0 and id = :1 set apa",
"update tblB where bar = :0 and id = :2 set monkey"
],
"predicates": [
"tblA.foo = 0",
"tblA.id = ?",
"tblB.bar = 0",
"tblB.id = ?"
],
"count": 2
}
]
{
"fileType": "transactions",
"signatures": [
{
"query-signatures": [
"update tblA where foo = :0 and id = :1 set apa",
"update tblB where bar = :0 and id = :2 set monkey"
],
"predicates": [
"tblA.foo = 0",
"tblA.id = ?",
"tblB.bar = 0",
"tblB.id = ?"
],
"count": 2
}
]
}
7 changes: 6 additions & 1 deletion go/transactions/transaction_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,10 @@ func (m *txSignatureMap) MarshalJSON() ([]byte, error) {
return signatures[i].Count > signatures[j].Count
})

return json.Marshal(signatures)
result := map[string]any{
"fileType": "transactions",
"signatures": signatures,
}

return json.Marshal(result)
}
3 changes: 3 additions & 0 deletions go/transactions/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ func TestRun(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, string(out), sb.String())
if t.Failed() {
_ = os.WriteFile("../testdata/expected/small-slow-query-transactions.json", []byte(sb.String()), 0o644)
}
}

0 comments on commit 2781aa8

Please sign in to comment.