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

More improvements to the way CLI handles comments in multi-line statements #2241

Merged

Conversation

big-andy-coates
Copy link
Contributor

Description

Following on from @vcrfxia insights in the last pr: #2214 (review), this PR adds more improvements to the way the CLI handles inline comments.

It can now handle something like this example being cut and paste into the CLI:

SELECT -- a comment
   -- another comment
   foo, -- cos we really like comments
   -- can't get enough of 'em
   bar -- love'em
   -- best thing since sliced bread
FROM -- better than fake news
x;

To support I've enhanced the CommentStripper to handle multi-line statements with embedded comments.

I've also had to switch the JLineReader to not replace new lines with spaces. So if the input contains multiple lines, so does the output. But the parser is fine with this. History also still works, though a single history item can now span multiple lines, e.g. running:

ksql>show
> -- awesome, another comment.
> streams;

Works, and then you can list history, which shows the command over multiple lines:

ksql> history
1: show
-- awesome, another comment.
streams;

Testing done

Added appropriate unit test and manual sanity testing.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

Copy link
Contributor

@vcrfxia vcrfxia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @big-andy-coates . Super comprehensive comment support! LGTM.


private String parse() {
final String firstPart = strip();
if (done()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this isn't wrapped into the while-loop below is so we avoid creating a StringBuilder instance when the line contains no comments, yes? How expensive is it to create a StringBuilder instance? (Trying to improve my understanding of when such optimizations make sense.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most lines won't have comments, hence I added this early out as its easy to do.

One could argue this is 'premature optimisation' - especially considering this is, in general, reacting to someone typing at a keyboard and hence performance isn't really an issue. So asking me to remove this would be a valid point.

@blueedgenick
Copy link
Contributor

Pretty slick-looking Andy! But i'm not sure i like the trade-off here of giving up good history presentation (i.e. the way it works today, which i think is likely the most 'expected' way for such a thing to work) to get even better inline commenting. Is there a way to resolve that tension by tweaking the impl here ? If not, i'd personally vote against making this particular change.

@big-andy-coates big-andy-coates requested a review from a team December 12, 2018 13:07
@big-andy-coates
Copy link
Contributor Author

Hey @blueedgenick,

You're feedback welcome as always!

I had a quick look at the current CLI and it too reports multiple line history over multiple lines, (by bad, I'd not checked this wasn't already the case):

version 5.0.x gives:

ksql>show \
streams;
...

ksql>history
1080: ...
1081: show \
streams;
1082: history

With the change to drop line continuation char this now becomes:

ksql>show 
streams;
...

ksql>history
1080: ...
1081: show 
streams;
1082: history

So, there isn't really any change to history output here!

@blueedgenick
Copy link
Contributor

@big-andy-coates fair point! ideally the history lines would get condensed into a single-line presentation (which for some reason i thought they already were, but that could just be a sign of the state of my memory). And of course once condensed into a single line it doesn't make sense to have the embedded comments any more... not saying we shouldn't preserve the comments, as entered, in the command topic - i'm only addressing the presentation of the local history file entries here. WDYT ?

@miguno
Copy link
Contributor

miguno commented Dec 13, 2018

ideally the history lines would get condensed into a single-line presentation (which for some reason i thought they already were, but that could just be a sign of the state of my memory)

Agreed, this is a cosmetic change. I wouldn't block this PR on it. Rather, we should file a separate GH ticket to consider improving the presentation of the (local) history of commands.

Copy link
Contributor

@rmoff rmoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@big-andy-coates
Copy link
Contributor Author

Hey @blueedgenick,

Personally, I think a multi-line command should be displayed in the history output over multiple lines. However, I don't feel strongly about it. As @miguno suggests, how about raising an issue with details of how you think it should work?

You could mark the issue as good first issue / help wanted as it would be a nice contained issue for the community to work on.

Copy link
Contributor

@dguy dguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth adding a test to CliTest ?
LGTM

@big-andy-coates
Copy link
Contributor Author

@dguy

Is it worth adding a test to CliTest ?

I'm happy with the test coverage. Combination of JLineReaderTest and KsqlParserTest should be sufficient.

@big-andy-coates big-andy-coates merged commit 734dc4f into confluentinc:master Dec 13, 2018
@big-andy-coates big-andy-coates deleted the more_line_continuation branch December 13, 2018 11:55
hasnat added a commit to hasnat/ksql that referenced this pull request Dec 23, 2018
* fork/master: (107 commits)
  copy-edited (confluentinc#2299)
  copy-edited (confluentinc#2299)
  remove unused map from command store `getRestoreCommands` (confluentinc#2296)
  Speed up integration tests. (confluentinc#2288)
  Move KSQL Clickstream demo to Examples repo (confluentinc#2270)
  Bump Confluent to 5.1.1-SNAPSHOT, Kafka to 2.1.1-SNAPSHOT
  Set Confluent to 5.1.0, Kafka to 2.1.0-cp1.
  Add ServiceContext (confluentinc#2243)
  Update to use CCL (confluentinc#2278)
  Remove redundant intro sentence in README.md (confluentinc#2277)
  Switch to use CCL (confluentinc#2275)
  Update readme for CCL (confluentinc#2276)
  Minor: add Hamcrest matchers for KsqlRestException and KsqlErrorMessage (confluentinc#2273)
  Update per relicensing (confluentinc#2274)
  CP-584: 5.1.0 changelog (confluentinc#2267)
  add null checks to min, max, and count aggregates; call Math.min/max for consistency (confluentinc#2246)
  Return and accept command topic offsets via REST API (confluentinc#2159)
  MINOR: Fix bug encountered when restoring RUN SCRIPT command. (again) (confluentinc#2265)
  More improvements to the way the CLI handles inline comments in multi-line statements. (confluentinc#2241)
  Fix issue where Avro subject does not exist (confluentinc#2260)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants