Skip to content

Implementation of simple_query_string - #54

Closed
Yury-Fridlyand wants to merge 3 commits into
dev-simple_query_string-#192from
dev-simple_query_string-#192-impl
Closed

Yury-Fridlyand wants to merge 3 commits into
dev-simple_query_string-#192from
dev-simple_query_string-#192-impl

Conversation

@Yury-Fridlyand

Copy link
Copy Markdown

Description

Backend implementation of simple_query_string function, see opensearch-project#192
Require SQL/PPL parser update (#53) to support end-to-end flow

TODOs:

  • tests
  • new test data
  • rework on argument parser

Issues Resolved

^

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

private static FunctionResolver simple_query_string() {
FunctionName funcName = BuiltinFunctionName.SIMPLE_QUERY_STRING.getName();
// At most field, query, and all optional parameters
// TODO 16 ? See org.opensearch.index.query.SimpleQueryStringBuilder.class

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Close this TODO

}
}
}
} No newline at end of file

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Add a blank line


var lst = arr.toList().stream().map(String::valueOf).collect(Collectors.toList());
var res = new HashMap<String, Float>();
//var builder = ImmutableMap.builder();

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Should we use ImmutableMap? The return value has to be Map<String, Float>, so in that case we need to convert immutable map to mutable one.

Comment on lines +110 to +112
var parts = elem.split("\\^");
var weight = Float.parseFloat(parts[parts.length - 1]);
var field = Arrays.stream(parts).limit(parts.length - 1).collect(Collectors.joining("^"));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

  1. Should we support multiple ^ character?
  2. The exception message would be unclear for the end user if string ends with ^ or there is no float after ^.
  3. ^ may be a part of the string, so it should be escaped.

private Map<String, Float> parseFields(String fields) {
try {
// TODO support elements wrapped by single quotes
var arr = new JSONArray(fields);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Teh JSON parser doesn't work for 2 reasons:

  1. it doesn't support single quotes
  2. it doesn't parse the carot (^) character.
    We should consider abandoning this direction and using the lex parser to read the array.

@Yury-Fridlyand

Copy link
Copy Markdown
Author

Closed as of #61.

@Yury-Fridlyand
Yury-Fridlyand deleted the dev-simple_query_string-#192-impl branch May 31, 2022 21:51
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.

2 participants