[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17851515#comment-17851515 ] Arun Ganesh commented on CASSANDRA-19150: - [~bschoeni], Thanks for the review! I'm sorry I was not available for a while because of my finals. #2 and #3 sounds good. For #4, I don't have the exact count because I don't have a paid CircleCI account, and I can see some dtests using the cqlsh output (like this [one|https://github.com/apache/cassandra-dtest/blob/trunk/json_test.py]). Regarding #1, everything except "This could be generalized to a multi-value map for types" sounds good, because I see a lot of inline uses of the color map, like {code:python} coloredval = colormap['text'] + bits_to_turn_red_re.sub(tbr, bval) + colormap['reset'] {code} Changing this map to include the alignment too would require changes in a lot of places. Let me update my PR. > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc, test_output.txt, > test_output_old.txt > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17849363#comment-17849363 ] Brad Schoening commented on CASSANDRA-19150: [~arkn98] any thoughts on the above? > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc, test_output.txt, > test_output_old.txt > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17833950#comment-17833950 ] Brad Schoening commented on CASSANDRA-19150: [~arkn98] Ok, I see your point. Reviewing the code, I wonder if it would be tidier to consolidate the formatting into a map like DEFAULT_VALUE_COLORS which maps types to color formats. This could be generalized to a multi-value map for types -> ( color, alignment). For example: {code:java} TYPE_FORMATS = { 'default': (YELLOW, LEFT), 'text': (YELLOW, LEFT), 'int': (GREEN, RIGHT)} color, algn = TYPE_FORMATS['int']{code} > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc, test_output.txt, > test_output_old.txt > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17832655#comment-17832655 ] Arun Ganesh commented on CASSANDRA-19150: - [~bschoeni], It's a catch-22. To use {{print("{0:x}".format(i))}} to align values in the column, we should know {{x}}, which should be the length of the longest value in the column (either the longest value or the column header). And, you cannot know {{x}} without converting them to strings in the first place. I believe that's why we don't use {{"{}".format()}} in cqlsh. Instead, we convert all values to strings first (e.g., [here|https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/formatting.py:251], [here|https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/formatting.py:331], [here|https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/formatting.py:349], and so on), and later pad it manually to the max-width of each column. > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc, test_output.txt, > test_output_old.txt > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17832601#comment-17832601 ] Brad Schoening commented on CASSANDRA-19150: [~arkn98] in reviewing your questions, I came across [PEP 3101|https://peps.python.org/pep-3101/#standard-format-specifiers] which introduces new alignment specifiers: * '<' - Forces the field to be left-aligned within the available space (This is the default.) * '>' - Forces the field to be right-aligned within the available space. when I ran this test it seems to default to right align numbers and left align text. {code:java} for i in (1,'x',0.0): print("{0:5}".format(i)) 1 x 0.0 {code} > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc, test_output.txt, > test_output_old.txt > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17832516#comment-17832516 ] Arun Ganesh commented on CASSANDRA-19150: - [~bschoeni] [~smiklosovic] Sorry for the delay again. See [^test_output_old.txt] and [^test_output.txt] for the before and after. These are some things I'd like to discuss before I write/fix the tests: 1. Does the design look okay? Or, should I use a map-lookup to get type->alignment values? 2. Should nulls be treated separately (like all null values align left), or should they be treated according to the type of the field (like nulls in vectors align right, nulls in maps align left, etc.)? 3. How should I align user-types and collections: left or right? I chose right because we were aligning everything to the right before. 4. Breaking all tests that depend on cqlsh, including downstream apps, doesn't seem like a great thing to do. Also, C* devs should not be burdened with type-alignment when they write tests---there should be a way to turn type-based alignment on/off. I suggest that we also introduce the `ALIGNMENT` command from the original description of this ticket. It can have `LEFT|RIGHT|DEFAULT` options. `DEFAULT` will align the output based on the types. 5. Should I document the alignment for the different types somewhere? > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc, test_output.txt, > test_output_old.txt > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17830288#comment-17830288 ] Brad Schoening commented on CASSANDRA-19150: [~arkn98] ah, yes, the tests will have to be fixed. Manually adding whitespace is one way. Using a matching regex with \s+ could be another. > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17830032#comment-17830032 ] Arun Ganesh commented on CASSANDRA-19150: - Ping [~bschoeni] [~smiklosovic] The patch is almost ready. Just a quick question. The patch will break almost every test that depends on the cqlsh output. How should I go about fixing them? > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17827951#comment-17827951 ] Arun Ganesh commented on CASSANDRA-19150: - Additionally, # I noticed some deadcode. There are multiple places with code like this, {code:java} return bval if colormap is NO_COLOR_MAP else ... {code} When the {{--no-color}} flag is passed, or the tty is "dumb", we do this {code:python} if addcolor is False: colormap = empty_colormap {code} where {{{}empty_colormap = defaultdict(lambda: ''){}}}. The {{NO_COLOR_MAP}} is just a plain {{{}dict(){}}}. {{colormap is NO_COLOR_MAP}} will always be {{{}False{}}}. {code:python} $ python3 Python 3.8.18 (default, Dec 16 2023, 04:10:16) >>> from collections import defaultdict >>> a = defaultdict(lambda: '') >>> b = dict() >>> a is b False{code} # I found two formatter functions for the `duration` type. Is there a difference between `Duration` and `duration`? {code:python} formatter_for('duration')(format_integer_type) . . . @formatter_for('Duration') def format_value_duration(val, colormap, **_): return format_python_formatted_type(duration_as_str(val.months, val.days, val.nanoseconds), colormap, 'duration'){code} The second one is picked up always. > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org
[jira] [Commented] (CASSANDRA-19150) Align values in rows in CQLSH right for numbers, left for text
[ https://issues.apache.org/jira/browse/CASSANDRA-19150?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17827947#comment-17827947 ] Arun Ganesh commented on CASSANDRA-19150: - Sorry, I took a while to get back to this. I have a draft PR ready. I have two items to discuss: # I'd like some feedback on the design. The formatter for each type will request whatever alignment it wants like this, (I'm yet to do this on the PR) {code:java} return FormattedValue(val, coloredval, displaywidth, alignment=Alignment.LEFT){code} # I'm planning to use the following left/right alignment for the different types (inspired from psql). |*Type*|*Alignment*| |default|right| |blob/bytearray|left| |decimal|right| |uuid/timeuuid|left| |inet|left| |bool|left| |float/double|right| |text/unicode/ascii|left| |set/list/map|right| |user types|right| When the expand mode is enabled, everything is aligned to the left, just like in psql. > Align values in rows in CQLSH right for numbers, left for text > -- > > Key: CASSANDRA-19150 > URL: https://issues.apache.org/jira/browse/CASSANDRA-19150 > Project: Cassandra > Issue Type: Improvement > Components: CQL/Interpreter >Reporter: Stefan Miklosovic >Assignee: Arun Ganesh >Priority: Low > Fix For: 5.x > > Attachments: Screenshot 2023-12-04 at 00.38.16.png, Screenshot > 2023-12-09 at 16.58.25.png, signature.asc > > Time Spent: 20m > Remaining Estimate: 0h > > *Updated* Jan 17 2024 after dev discussion > Change CQLSH to left-align text while continue to right-align numbers. This > will match how Postgres shell and Excel treat alignment of text and number. > - > *Original* > We need to make this > [https://github.com/apache/cassandra/blob/trunk/pylib/cqlshlib/cqlshmain.py#L1101] > configurable so values in columns are either all on left or on right side of > the column (basically change col.rjust to col.ljust). > By default, it would be like it is now but there would be configuration > property in cqlsh for that as well as a corresponding CQLSH command > (optional), something like > {code:java} > ALIGNMENT LEFT|RIGHT > {code} > cc [~bschoeni] -- This message was sent by Atlassian Jira (v8.20.10#820010) - To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org