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

feat: new CLI parameter to execute a command and quit (without CLI interaction) #6267

Merged
merged 2 commits into from
Oct 2, 2020

Conversation

spena
Copy link
Member

@spena spena commented Sep 21, 2020

Description

Fixes #4981

Adds a new paramter to the CLI to execute a command and quit. This without having to interact with the CLI console.

sergio@pop-os:~/Development/ksql$ time ./bin/ksql -e "show streams;"

 Stream Name         | Kafka Topic                 | Format 
------------------------------------------------------------
 KSQL_PROCESSING_LOG | default_ksql_processing_log | JSON   
 TOPIC1              | topic1                      | JSON   
------------------------------------------------------------

real	0m2.250s
user	0m4.604s
sys	0m0.185s
sergio@pop-os:~/Development/ksql$ ./bin/ksql -e "set 'auto.offset.reset'='earliest'; select * from topic1 emit changes;"
Successfully changed local property 'auto.offset.reset' to 'earliest'. Use the UNSET command to revert your change.
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|ID                                                                                                                                                                                                                               |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|1                                                                                                                                                                                                                                |
^CQuery terminated

You can use a different output format to easily parse the command result. For instance, JSON:

$ ./bin/ksql -e "show streams" --output JSON | jq '.[].streams' | jq '.[].name'
"TOPIC1"
"KSQL_PROCESSING_LOG"
"S1"

Testing done

Added unit tests
Verified manually

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 #")

@spena spena requested a review from a team September 21, 2020 18:06
@colinhicks
Copy link
Contributor

Adds a new paramter to the CLI to execute a command and quit. This without having to interact with the CLI console.

Just to clarify: For streaming results like push queries without a limit clause, you need to also issue ctrl+c to interrupt the console, correct?

@colinhicks
Copy link
Contributor

  • Add new parameter to remove headers and columns from the command output
  • Add new parameter to change command output format (i.e. comma-separated and tab-separated)

It might be worth considering a flag to send the raw JSON to stdout. This way it could be piped to other scripts like jq for such formatting.

@spena
Copy link
Member Author

spena commented Sep 21, 2020

@colinhicks Ctrl+C is part of the stream. The example of the Description shows the ^Query terminated line that was caused by the Ctrl+C.

Copy link
Contributor

@rodesai rodesai left a comment

Choose a reason for hiding this comment

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

LGTM other than a couple minor comments inline. Also, is there a place in the docs we can add this?

@SuppressWarnings("unused") // Accessed via reflection
@Option(
name = {EXECUTE_OPTION, EXECUTE_SHORT_OPTION},
description = "Execute a command and quit.")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the user may not understand "command" - maybe "run one or more ksql statements and quit."?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

} catch (final EndOfFileException exception) {
// Ignore - only used by runInteractively() to exit the CLI
} catch (final Exception exception) {
LOGGER.error("", exception);
Copy link
Contributor

Choose a reason for hiding this comment

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

why the empty log message?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@spena spena requested a review from a team September 28, 2020 14:44
Copy link
Contributor

@agavra agavra left a comment

Choose a reason for hiding this comment

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

LGTM, I think @rodesai meant to check the green tick

@spena spena merged commit 0d60246 into confluentinc:master Oct 2, 2020
@spena spena deleted the cli_exec_command branch October 2, 2020 13:20
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.

Add CLI parameter to execute commands without KSQL interative
4 participants