- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
QL: Add leniency option to SQL CLI #83795
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
Changes from 4 commits
58de769
              36740fe
              4905bbe
              fbdb378
              68e197c
              db58495
              2e8b6f0
              88a55b8
              876fbb9
              0a1aacd
              01fdbb4
              55ee671
              42dde1e
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 83795 | ||
| summary: Add leniency option to SQL CLI | ||
| area: SQL | ||
| type: enhancement | ||
| issues: | ||
| - 67436 | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -40,6 +40,7 @@ public class Cli extends Command { | |
| private final OptionSpec<Boolean> checkOption; | ||
| private final OptionSpec<String> connectionString; | ||
| private final OptionSpec<Boolean> binaryCommunication; | ||
| private final OptionSpec<Boolean> lenientOption; | ||
|  | ||
| /** | ||
| * Use this VM Options to run in IntelliJ or Eclipse: | ||
|  | @@ -102,6 +103,11 @@ public Cli(CliTerminal cliTerminal) { | |
| .withRequiredArg() | ||
| .ofType(Boolean.class) | ||
| .defaultsTo(Boolean.parseBoolean(System.getProperty("cli.check", "true"))); | ||
| this.lenientOption = parser.acceptsAll( | ||
|          | ||
| Arrays.asList("l", "lenient"), | ||
| "Lenient and return first value for fields with multiple values" | ||
|         
                  luigidellaquila marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| ).withRequiredArg().ofType(Boolean.class).defaultsTo(Boolean.parseBoolean(System.getProperty("cli.lenient", "false"))); | ||
|  | ||
|         
                  luigidellaquila marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| this.connectionString = parser.nonOptions("uri"); | ||
| } | ||
|  | ||
|  | @@ -110,6 +116,7 @@ protected void execute(org.elasticsearch.cli.Terminal terminal, OptionSet option | |
| boolean debug = options.has("d") || options.has("debug"); | ||
| boolean binary = binaryCommunication.value(options); | ||
| boolean checkConnection = checkOption.value(options); | ||
| boolean lenient = this.lenientOption.value(options); | ||
| List<String> args = connectionString.values(options); | ||
| if (args.size() > 1) { | ||
| throw new UserException(ExitCodes.USAGE, "expecting a single uri"); | ||
|  | @@ -120,17 +127,18 @@ protected void execute(org.elasticsearch.cli.Terminal terminal, OptionSet option | |
| throw new UserException(ExitCodes.USAGE, "expecting a single keystore file"); | ||
| } | ||
| String keystoreLocationValue = args.size() == 1 ? args.get(0) : null; | ||
| execute(uri, debug, binary, keystoreLocationValue, checkConnection); | ||
| execute(uri, debug, binary, keystoreLocationValue, checkConnection, lenient); | ||
| } | ||
|  | ||
| private void execute(String uri, boolean debug, boolean binary, String keystoreLocation, boolean checkConnection) throws Exception { | ||
| private void execute(String uri, boolean debug, boolean binary, String keystoreLocation, boolean checkConnection, boolean lenient) | ||
| throws Exception { | ||
| CliCommand cliCommand = new CliCommands( | ||
| new PrintLogoCommand(), | ||
| new ClearScreenCliCommand(), | ||
| new FetchSizeCliCommand(), | ||
| new FetchSeparatorCliCommand(), | ||
| new ServerInfoCliCommand(), | ||
| new ServerQueryCliCommand() | ||
| new ServerQueryCliCommand(lenient) | ||
| ); | ||
| try { | ||
| ConnectionBuilder connectionBuilder = new ConnectionBuilder(cliTerminal); | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would create a test class just for this command. And, apart from the test you have below, I'd test the
falsescenario as well (the one that generates an error).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done