Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: handle rows and error #45833

Closed
RaduBerinde opened this issue Mar 7, 2020 · 11 comments · Fixed by #46124
Closed

cli: handle rows and error #45833

RaduBerinde opened this issue Mar 7, 2020 · 11 comments · Fixed by #46124
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Comments

@RaduBerinde
Copy link
Member

I have a usecase for a statement which can return some information as a result, as well as an error.

In the cli, depending on the display format, these rows may or may not show up:

We should make these all consistent and always show the rows even if we do receive an error.

I tested this with the code below for a specific statement in the sql executor:

		res.DisableBuffering()
		for i := 1; i < 10; i++ {
			res.AddRow(ctx, tree.Datums{tree.NewDString(fmt.Sprintf("some text %d", i))})
		}
		err := fmt.Errorf("FOO BAR")
		res.SetError(err)
		return makeErrEvent(err)
@knz
Copy link
Contributor

knz commented Mar 7, 2020

Do you have a specific preference for returning results + error, as opposed to results + notice? (#45679)

I am asking because even though we could teach our CLI shell to report both partial results and error, this is not simple to do with every driver. If you plan to deliver a functionality usable cross-client, notices are the best way to go.

@knz knz added A-cli C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) labels Mar 7, 2020
@RaduBerinde
Copy link
Member Author

For some background, I'm working on a new EXPLAIN BUNDLE statement which runs the query (similarly to EXPLAIN ANALYZE) and then returns some information text with a URL to a zip bundle which contains a bunch of information. I think results + notice would actually work great here (it would allow us to still return the original results).

The question is what do we do in case of an error? Currently we just return the error. Ideally we'd still create the bundle and return the information about it. We don't want to eat the error because that would prevent auto-retries. Is it possible to return error + notice? Otherwise I might just wrap the error to add the detail about the bundle.

@RaduBerinde
Copy link
Member Author

I tried it and the notice doesn't show up when there's an error. That behavior seems consistent with psql so we probably don't want to change it.

@knz
Copy link
Contributor

knz commented Mar 8, 2020

The question is what do we do in case of an error?

Put the link to the plan as a DETAIL or HINT field in the error payload!

@RaduBerinde
Copy link
Member Author

Yeah that's what I meant when I mentioned wrapping the error. I think that would work nicely.

@RaduBerinde
Copy link
Member Author

There is a related issue here: where does a Notice show up (assuming it was added on the server-side after the results)? With the default formatter (as well as tsv, csv), it shows up before the results which is a little surprising (and not sure what happens with tsv/csv when the buffer gets flushed - does it show up in the middle?!). With raw, records, html it shows up at the end.

I'm worried that if the query returns many results, the notice will be missed if it is not at the end.

@knz
Copy link
Contributor

knz commented Mar 8, 2020

We can enhance the SQL shell to repeat the notices at the end if there was more than a screenful of result rows.

@RaduBerinde
Copy link
Member Author

Why not always show it at the end (at least in the case where the server sends the notice after the results)?

@knz
Copy link
Contributor

knz commented Mar 8, 2020

Why not always show it at the end (at least in the case where the server sends the notice after the results)?

yeah in the case where the notice arrives after the first result row, I agree. But there could be a notice to inform a user that the first result is going to take a while to arrive, and that notice should be delivered immediately.

@knz
Copy link
Contributor

knz commented Mar 14, 2020

I discovered that the code always delays notices until the end already.
So there is no more work here after #45872. closing.

@knz knz closed this as completed Mar 14, 2020
@knz knz reopened this Mar 14, 2020
@knz
Copy link
Contributor

knz commented Mar 14, 2020

woops no I talked too soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants