-
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 7 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 |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ public class CliSession { | |
| private String fetchSeparator = ""; | ||
| private boolean debug; | ||
| private boolean binary; | ||
| private boolean lenient = CoreProtocol.FIELD_MULTI_VALUE_LENIENCY; | ||
|
||
|
|
||
| public CliSession(HttpClient httpClient) { | ||
| this.httpClient = httpClient; | ||
|
|
@@ -68,6 +69,14 @@ public boolean isBinary() { | |
| return binary; | ||
| } | ||
|
|
||
| public boolean isLenient() { | ||
| return lenient; | ||
| } | ||
|
|
||
| public void setLenient(boolean lenient) { | ||
| this.lenient = lenient; | ||
| } | ||
|
|
||
| public void checkConnection() throws ClientException { | ||
| MainResponse response; | ||
| try { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| package org.elasticsearch.xpack.sql.cli.command; | ||
|
|
||
| import org.elasticsearch.xpack.sql.cli.CliTerminal; | ||
|
|
||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * lenient command, enables/disables fields multi-value leniency. | ||
| * ie. with lenient = true, in case of array values, return the first value, with no guarantee of consistent results. | ||
| * | ||
| */ | ||
| public class LenientCliCommand extends AbstractCliCommand { | ||
|
|
||
| public LenientCliCommand() { | ||
| super(Pattern.compile("lenient *= *(.+)", Pattern.CASE_INSENSITIVE)); | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean doHandle(CliTerminal terminal, CliSession cliSession, Matcher m, String line) { | ||
| cliSession.setLenient(Boolean.parseBoolean(m.group(1))); | ||
| terminal.line().text("lenient set to ").em(Boolean.toString(cliSession.isLenient())).end(); | ||
| return true; | ||
| } | ||
| } |
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