Skip to content

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

Merged
merged 13 commits into from
Feb 16, 2022

Conversation

luigidellaquila
Copy link
Contributor

@luigidellaquila luigidellaquila commented Feb 10, 2022

Add lenient = true/false command to CLI client to allow execution of lenient queries on multi-value fields.

Fixes #67436

@luigidellaquila luigidellaquila added >enhancement :Analytics/SQL SQL querying Team:QL (Deprecated) Meta label for query languages team labels Feb 10, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@elasticsearchmachine
Copy link
Collaborator

Hi @luigidellaquila, I've created a changelog YAML for you.

@astefan astefan requested a review from Luegg February 10, 2022 16:57
Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

Looked at half of the code and, before proceeding further, I am wondering if lenient shouldn't have been a command (to be used inside the CLI) and not a CLI option (to be used as a parameter when the CLI is started).

@@ -102,6 +103,11 @@ public Cli(CliTerminal cliTerminal) {
.withRequiredArg()
.ofType(Boolean.class)
.defaultsTo(Boolean.parseBoolean(System.getProperty("cli.check", "true")));
this.lenientOption = parser.acceptsAll(
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the already existent commands and options for CLI, I would have inclined to make lenient a command and not a cli option. For example, fetch_size is a command (FetchSizeCliCommand class). The command can be executed multiple times during the life of the cli and an user can change the leniency with each query executed.

Copy link
Contributor

@bpintea bpintea Feb 10, 2022

Choose a reason for hiding this comment

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

From the session configuration point of view (and maybe consistency?), this would make indeed sense.
From a practical POV, not sure if changing this behavior on a query-by-query case would be as useful, but for those users that use the CLI integrated into other scripts, having it as an argument might be preferred.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, having a command would make it much more flexible, I'm implementing it now.
Do you think it makes sense to keep both (ie. the command AND the cli option) or should we just have the command?

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't make sense to have it in both places. We are not doing this for any setting/config so far. Please, implement it as a command only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I removed the CLI option and replaced it with a command for now (lenient = true/false).
In case we decide to go with both, re-enabling the option is straight forward.

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

Looking better. Left few more comments.

Comment on lines 25 to 27
private boolean debug;
private boolean binary;
private boolean lenient = CoreProtocol.FIELD_MULTI_VALUE_LENIENCY;
Copy link
Contributor

Choose a reason for hiding this comment

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

There are more and more commands and configuration settings to set. I think it's worth considering taking all these out in a separate class, like SqlConfiguration one for example, and the CliSession to contain a reference to this configuration instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it makes sense. Just wondering if it makes sense to have a separate PR for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@luigidellaquila
Copy link
Contributor Author

@elasticmachine update branch

@luigidellaquila
Copy link
Contributor Author

@elasticmachine update branch

Copy link
Contributor

@Luegg Luegg left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

Thank you for incorporating the reviews. I've left two more comments.

@@ -37,4 +37,14 @@ public void testSelectWithWhere() throws IOException {
assertThat(readLine(), RegexMatcher.matches("\\s*2\\s*\\|\\s*test_value2\\s*"));
assertEquals("", readLine());
}

Copy link
Contributor

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 false scenario as well (the one that generates an error).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM - the only comment I would make is to rename CliSession#getConfiguration to cfg or configuration() since the config object is internal and final and cannot be set.
I'm late to this PR and it seems to be CliSession == CliConfiguration at the stage (CliSession doesn't really add anything extra and it has the same scope as configuration); however in the future there might be other things to add to it so I'm fine with the refactoring.

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

@luigidellaquila luigidellaquila merged commit e6abd9f into elastic:master Feb 16, 2022
weizijun added a commit to weizijun/elasticsearch that referenced this pull request Feb 16, 2022
…ijun/elasticsearch into fix-none-tsdb-index-dimension-tests

* 'fix-none-tsdb-index-dimension-tests' of github.com:weizijun/elasticsearch: (37 commits)
  [docs] Mention JDK 17 in the Contributing docs (elastic#84018)
  Fix GeoIpDownloader startup during rolling upgrade (elastic#84000)
  Script: Fields API for Dense Vector (elastic#83550)
  Move InferenceConfigUpdate under VersionedNamedWriteable (elastic#84022)
  [ML] Fix license feature test cleanup (elastic#84020)
  Replace deprecated api in artifact transforms (elastic#84015)
  QL: Add leniency option to SQL CLI (elastic#83795)
  [Stack Monitoring] add kibana_stats version alias to -mb template (elastic#83930)
  Optimize spliterator for ImmutableOpenMap (elastic#83899)
  Feature usage actions for archive (elastic#83931)
  Use latch to speedup multi feature migration test (elastic#84007)
  Make action names available in NodeClient (elastic#83919)
  [DOCS] Re-add HTTP proxy setings from elastic#82737 (elastic#84001)
  Add CI matrix configuration for snapshot BWC versions (elastic#83990)
  Update YAML Rest tests to check for product header on all responses (elastic#83290)
  TSDB: Add time series aggs cancellation (elastic#83492)
  [DOCS] Fix percolate query headings (elastic#83988)
  [DOCS] Move tip for percolate query example (elastic#83972)
  Simplify LocalExporter cleaner function to fix failing tests (elastic#83812)
  [GCE Discovery] Correcly handle large zones with 500 or more instances (elastic#83785)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/SQL SQL querying >enhancement Team:QL (Deprecated) Meta label for query languages team v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL: CLI: query fails to run against multi-value fields / arrays
7 participants