[
https://issues.apache.org/jira/browse/CASSANDRA-19985?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18104922#comment-18104922
]
Brad Schoening commented on CASSANDRA-19985:
--------------------------------------------
[~arvindk12]
*OutputMode* was added but isn't used.
*Printers ignore the {{formatted_names}} they're passed.* Both
{{CsvTablePrinter.print_rows}} and {{JsonTablePrinter.print_rows}} accept
{{formatted_names}} and then use {{self._colnames}} stashed by
{{{}print_header{}}}. That creates an implicit ordering contract between the
two methods for no benefit — use the parameter and drop the state.
*Dead parameter.* {{row_count_offset}} on {{print_static_result}} is no longer
read anywhere in the body; the tabular printer maintains its own accumulator.
Remove it, or callers will keep passing {{num_rows}} into a void.
*JSON floats are being truncated to display precision.* The call passes
{{float_precision=self.display_float_precision}} (default 5) into
{{{}format_json_value{}}}. If that precision is applied before the native float
is emitted, {{--mode json}} silently rounds doubles to five significant digits
— almost certainly wrong for a format whose entire purpose is machine
consumption. Worth verifying and, if so, emitting full precision regardless of
display settings.
*CSV null representation.* {{col.strval}} for a null is the display
{{{}nullval{}}}, i.e. the literal string {{{}null{}}}, which is
indistinguishable from a text column containing "null". {{COPY TO}} uses an
empty field by default and makes it configurable. These should agree.
*Duplicate column names collapse in JSON.* {{{self._colnames[i]: val for i, val
in enumerate(row)}}} silently drops a column for {{{}SELECT id, id FROM t{}}}.
CSV handles it fine. Let's document it.
> Enhance CQLSH to support machine-readable output formatting
> -----------------------------------------------------------
>
> Key: CASSANDRA-19985
> URL: https://issues.apache.org/jira/browse/CASSANDRA-19985
> Project: Apache Cassandra
> Issue Type: New Feature
> Components: CQL/Interpreter
> Reporter: Brad Schoening
> Assignee: Arvind Kandpal
> Priority: Normal
> Attachments: json_formatters_example.py, test_json_formatting.py
>
> Time Spent: 1h 50m
> Remaining Estimate: 0h
>
> Existing CQLSH output formatting provides tabular formatting using grid-like
> separators and text alignment which is designed for user readability.
> When CQL is run for non-interactive tasks as part of a pipeline this
> formatting complicates the machine processing of the output. As an example,
> [Sqlite|https://www.sqlite.org/cli.html] has a command line flag -mode to
> switch between tablular, csv, and several other supported formats.
> This enhancement will provide a new mode argument which will initially offer
> tabular and csv output formats. Tabular will remain the default so there will
> be no change for existing users. In the future, other modes such as json and
> insert could be added.
> {noformat}
> --mode={tabular, csv}
> Specify an output display format. The default is tabular.
> {noformat}
> The existing Copy To can be used for exporting to CSV, but it doesn't allow
> for query criteria and thus isn't a general solution for this issue.
> In cqlshmain.py, the EXPAND CQLSH option which uses print_formatted_result()
> for result output is an example of alternative formatting.
> Paging will have to be properly managed. A good formatter should handle a
> stream of rows rather than requiring the entire list in memory, especially
> for large SELECT * queries.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]