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: avoid special line at the end of CSV/TSV output #20835

Merged
merged 2 commits into from Feb 7, 2018

Conversation

knz
Copy link
Contributor

@knz knz commented Dec 18, 2017

Fixes #18584.

Prior to this patch, the csv/tsv formatters would end a table with a
row count. This is not great for interoperability with external tools
which may expect to be able to redirect the table output to a file and
open that directly in a csv/tsv reader, where the final row count
would be incorrectly interpreted as an extra row.

This patch changes the behavior by omitting the row count altogether
for csv/tsv output.

Release note (cli change): when printing tabular results as CSV or
TSV, no final row count is emitted. This is intended to increase
interoperability with external tools.

@knz knz requested a review from a team as a code owner December 18, 2017 20:49
@knz knz requested a review from a team December 18, 2017 20:49
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jordanlewis
Copy link
Member

Oo, can you include an example of the before/after for the end-user in the PR?

@bdarnell
Copy link
Member

Review status: 0 of 9 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


pkg/cli/flags.go, line 369 at r5 (raw file):

		f := cmd.Flags()
		VarFlag(f, &cliCtx.tableDisplayFormat, cliflags.TableDisplayFormat)
		BoolFlag(f, &cliCtx.displayRowCounts, cliflags.DisplayRowCounts, cliCtx.displayRowCounts)

In my mind the row count is a part of the pretty format and not something that can be toggled on/off independently. This knob and the associated implementation of row counts for every format seem like unnecessary complexity to me.


Comments from Reviewable

@knz
Copy link
Contributor Author

knz commented Dec 18, 2017

Review status: 0 of 9 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


pkg/cli/flags.go, line 369 at r5 (raw file):

Previously, bdarnell (Ben Darnell) wrote…

In my mind the row count is a part of the pretty format and not something that can be toggled on/off independently. This knob and the associated implementation of row counts for every format seem like unnecessary complexity to me.

I started making it configurable for csv/tsv (there are legitimate cases where we want a row count for them) and then I wasn't happy with having it configurable form csv/tsv. In particular it became clear that at least the html and records formatters should also have it. But then for orthogonality in docs I figured that it should be the same everywhere so the explanation remains simple. What do you think?


Comments from Reviewable

@bdarnell
Copy link
Member

Review status: 0 of 9 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


pkg/cli/flags.go, line 369 at r5 (raw file):

Previously, knz (kena) wrote…

I started making it configurable for csv/tsv (there are legitimate cases where we want a row count for them) and then I wasn't happy with having it configurable form csv/tsv. In particular it became clear that at least the html and records formatters should also have it. But then for orthogonality in docs I figured that it should be the same everywhere so the explanation remains simple. What do you think?

What is that use case? The reason I was thinking it was format-specific was because I couldn't think of any time you'd want anything but CSV/TSV data when using those formats.


Comments from Reviewable

@knz knz changed the title cli: improve the table formatters cli: print an empty line after CSV/TSV table printouts Feb 2, 2018
@knz
Copy link
Contributor Author

knz commented Feb 2, 2018

I have removed all commits but the last and simplified the implementation. PTAL.


Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion.


pkg/cli/flags.go, line 369 at r5 (raw file):

Previously, bdarnell (Ben Darnell) wrote…

What is that use case? The reason I was thinking it was format-specific was because I couldn't think of any time you'd want anything but CSV/TSV data when using those formats.

Okay, removed, PTAL.


Comments from Reviewable

@knz knz force-pushed the 20171218-row-counts branch 4 times, most recently from b985932 to e5d54ae Compare February 2, 2018 18:25
@knz knz requested a review from a team February 2, 2018 18:25
@knz knz force-pushed the 20171218-row-counts branch 3 times, most recently from f344099 to 5b4da8c Compare February 2, 2018 20:00
@bdarnell
Copy link
Member

bdarnell commented Feb 5, 2018

Reviewed 9 of 9 files at r7.
Review status: all files reviewed at latest revision, 2 unresolved discussions, all commit checks successful.


pkg/cli/format_table.go, line 289 at r7 (raw file):

func (p *csvReporter) doneRows(w io.Writer, seenRows int) error {
	p.csvWriter.Flush()
	// Ensure that there is a separator, in case multiple csv/tsv tables

Even a blank line can make things more complicated for readers. For example, python's csv.reader will return an empty list for the blank line, so reading code needs to explicitly handle it. We shouldn't add a blank line in the common case of a single query. If we want a separator, we should only use it when there are multiple queries. But even then I don't think it's worth the effort - executing multiple queries in a single CLI invocation and using CSV output seems like a very unusual workflow.


Comments from Reviewable

Prior to this patch, the csv/tsv formatters would end a table with a
row count. This is not great for interoperability with external tools
which may expect to be able to redirect the table output to a file and
open that directly in a csv/tsv reader, where the final row count
would be incorrectly interpreted as an extra row.

This patch changes the behavior by omitting the row count altogether
for csv/tsv output.

Release note (cli change): when printing tabular results as CSV or
TSV, no final row count is emitted. This is intended to increase
interoperability with external tools.
@knz knz changed the title cli: print an empty line after CSV/TSV table printouts cli: avoid special line at the end of CSV/TSV output Feb 7, 2018
@knz
Copy link
Contributor Author

knz commented Feb 7, 2018

Removed the empty line as suggested. PTAL

@knz
Copy link
Contributor Author

knz commented Feb 7, 2018

TFYR!

@knz knz merged commit 673fb4b into cockroachdb:master Feb 7, 2018
@knz knz deleted the 20171218-row-counts branch February 7, 2018 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants