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
6 changes: 6 additions & 0 deletions cmd/query/result_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func printExecutionResult(w io.Writer, r executionResult) {
fmt.Fprintf(w, "State: %s\n", r.State)
return
}
// Withheld rows come back as a notice without data; a table would read as
// an empty result.
if r.Data == nil && r.Notice != "" {
fmt.Fprintln(w, r.Notice)
return
}
Comment thread
rahuldotiyer marked this conversation as resolved.
Resolved
var columns []string
total := 0
credits := ""
Expand Down
6 changes: 5 additions & 1 deletion cmd/query/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ func runResults(cmd *cobra.Command, args []string) error {
}
w := cmd.OutOrStdout()
if output.FormatFromCmd(cmd) == output.FormatJSON {
return output.PrintRawJSON(w, raw)
// A failed stored run still fails the command, so scripts see it.
if err := output.PrintRawJSON(w, raw); err != nil {
return err
}
return res.Err()
}
if err := res.Err(); err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions cmd/query/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,19 @@ func TestResultsWithheldRowsShowTheNotice(t *testing.T) {
out, err := runResults(fake, "42")
require.NoError(t, err)
assert.Contains(t, out, "Rows withheld: licensed dataset")
assert.NotContains(t, out, "0 of 0 rows")
}

func TestResultsFailedRunIsAnError(t *testing.T) {
fake := &dunemcptest.Fake{Results: map[string]string{"getLatestQueryResult": `{"queryId":42,
"executionId":"01E","state":"FAILED","errorMessage":"line 1: syntax error"}`}}
_, err := runResults(fake, "42")
assert.EqualError(t, err, "execution 01E failed: line 1: syntax error")

// -o json prints the result and still fails, so scripts see the failure.
out, err := runResults(fake, "42", "-o", "json")
assert.EqualError(t, err, "execution 01E failed: line 1: syntax error")
assert.Contains(t, out, `"state": "FAILED"`)
}

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