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

Update for SQL and PPL parser to accept simple_query_string #53

Conversation

Yury-Fridlyand
Copy link

@Yury-Fridlyand Yury-Fridlyand commented May 12, 2022

Description

SQL and PPL parser update to support simple_query_string, see opensearch-project#192
Require #54 to support end-to-end flow.

TODO:

  • tests
  • rework on AstExpressionBuilder.java x2

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.

@Yury-Fridlyand Yury-Fridlyand requested a review from a team May 12, 2022 18:27
field=relevanceArgValue COMMA query=relevanceArgValue
field=relevanceField COMMA query=relevanceQuery
(COMMA relevanceArg)* RT_PRTHS
| relevanceFunctionNameEx LT_PRTHS
Copy link
Author

Choose a reason for hiding this comment

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

Should we rename it? Like relevanceFunctionType1Name and relevanceFunctionType2Name.
Or maybe to make relevanceExpressionType1 and relevanceExpressionType2.

Choose a reason for hiding this comment

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

Please be explicit with your naming as possible. Type1 and Type2 don't mean anything. If there's an order associated with the types in the list (and no other way to differentiate the types) we can call them first and second or something similar.

Choose a reason for hiding this comment

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

Let's change it to have separate rule for single-field relevance functions and a separate rule for multi-field relevance functions.

This way we can avoid the cumbersome ?: in AstExpressionBuilder. Instead there will be one method to visit single field relevance functions and another to visit multi-field relevance functions.

Comment on lines 335 to 345
// all the arguments are defaulted to string values
// to skip environment resolving and function signature resolving
ImmutableList.Builder<UnresolvedExpression> builder = ImmutableList.builder();
ParserRuleContext field = ctx.field;
if (field == null)
field = ctx.fields;
builder.add(new UnresolvedArgument("field",
new Literal(StringUtils.unquoteText(ctx.field.getText()), DataType.STRING)));
new Literal(StringUtils.unquoteText(field.getText()), DataType.STRING)));
builder.add(new UnresolvedArgument("query",
new Literal(StringUtils.unquoteText(ctx.query.getText()), DataType.STRING)));
ctx.relevanceArg().forEach(v -> builder.add(new UnresolvedArgument(
Copy link
Author

Choose a reason for hiding this comment

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

  1. Should we create 2 different functions as relevanceArguments?
  2. Should we skip StringUtils.unquoteText for fields?

@MaxKsyunz
Copy link

Could you please make the SQL Java CI actions pass?

Signed-off-by: Yury Fridlyand <[email protected]>
@Yury-Fridlyand
Copy link
Author

Could you please make the SQL Java CI actions pass?

dc75ce8 fixes code style, rest failures require tests.

@@ -332,8 +336,12 @@ private List<UnresolvedExpression> relevanceArguments(RelevanceExpressionContext
// all the arguments are defaulted to string values
// to skip environment resolving and function signature resolving
ImmutableList.Builder<UnresolvedExpression> builder = ImmutableList.builder();
ParserRuleContext field = ctx.field;
if (field == null) {

Choose a reason for hiding this comment

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

use conditions to define the ParseRuleContext, for example:
ParserRuleContext field = ctx.field != null ? ctx.field : ctx.fields;

@@ -357,6 +358,8 @@ BIT_XOR_OP: '^';
DOT: '.';
LR_BRACKET: '(';
RR_BRACKET: ')';
LT_SQR_PRTHS: '[';

Choose a reason for hiding this comment

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

where's this name coming from?
Just wondering why not something like: LR_SQUARE_BRACKET and RR_SQUARE_BRACKET

@@ -362,8 +364,12 @@ public UnresolvedExpression visitConvertedDataType(

@Override
public UnresolvedExpression visitRelevanceFunction(RelevanceFunctionContext ctx) {
ParserRuleContext func = ctx.relevanceFunctionNameEx();
Copy link

@acarbonetto acarbonetto May 12, 2022

Choose a reason for hiding this comment

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

ParserRuleContext func = ctx.relevanceFunctionNameEx() != null ctx.relevanceFunctionNameEx() : ctx.relevanceFunctionName();

@@ -393,8 +399,12 @@ private List<UnresolvedExpression> relevanceArguments(RelevanceFunctionContext c
// all the arguments are defaulted to string values
// to skip environment resolving and function signature resolving
ImmutableList.Builder<UnresolvedExpression> builder = ImmutableList.builder();
ParserRuleContext field = ctx.field;

Choose a reason for hiding this comment

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

ParserRuleContext field = ctx.field != null ctx.field : ctx.field2;

field=relevanceArgValue COMMA query=relevanceArgValue
field=relevanceField COMMA query=relevanceQuery
(COMMA relevanceArg)* RT_PRTHS
| relevanceFunctionNameEx LT_PRTHS

Choose a reason for hiding this comment

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

Let's change it to have separate rule for single-field relevance functions and a separate rule for multi-field relevance functions.

This way we can avoid the cumbersome ?: in AstExpressionBuilder. Instead there will be one method to visit single field relevance functions and another to visit multi-field relevance functions.

MaxKsyunz and others added 7 commits May 13, 2022 14:40
rejectMultipleStars test is failing right now.
Run it only if WIP_TEST environment variable is set to something.

Signed-off-by: MaxKsyunz <[email protected]>
It now only accepts ['*'] or ['*'] or a list of quoted identifiers.

Skip a test for an existing bug in match implementation unless
env variable GITHUB_ISSUE is set to 182 -- the ticket # it was
added under.

Signed-off-by: MaxKsyunz <[email protected]>
@Yury-Fridlyand
Copy link
Author

Closed as of #61.

@Yury-Fridlyand Yury-Fridlyand deleted the dev-simple_query_string-#192-sql-simple 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.

3 participants