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

Make explain of ProjectOperator with alias show both name and alias info #2911

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

qianheng-aws
Copy link
Contributor

@qianheng-aws qianheng-aws commented Aug 7, 2024

Description

Add name information as well in the explain of ProjectOperator with alias, so user can identify whether the field in his plan comes from the right source.

POST _plugins/_sql/_explain
{
  "query": "SELECT (FlightTimeMin + 1) as FlightTimeMinPlusOne FROM opensearch_dashboards_sample_data_flights LIMIT 5"
}


#Before this PR
{
  "root": {
    "name": "ProjectOperator",
    "description": {
      "fields": "[FlightTimeMinPlusOne]"
    },
    "children": [
      {
        "name": "OpenSearchIndexScan",
        "description": {
          "request": """OpenSearchQueryRequest(indexName=opensearch_dashboards_sample_data_flights, sourceBuilder={"from":0,"size":5,"timeout":"1m","_source":{"includes":["FlightTimeMin"],"excludes":[]}}, searchDone=false)"""
        },
        "children": []
      }
    ]
  }
}

#With this PR
{
  "root": {
    "name": "ProjectOperator",
    "description": {
      "fields": "[(FlightTimeMin + 1) AS FlightTimeMinPlusOne]"
    },
    "children": [
      {
        "name": "OpenSearchIndexScan",
        "description": {
          "request": """OpenSearchQueryRequest(indexName=opensearch_dashboards_sample_data_flights, sourceBuilder={"from":0,"size":5,"timeout":"1m","_source":{"includes":["FlightTimeMin"],"excludes":[]}}, searchDone=false)"""
        },
        "children": []
      }
    ]
  }
}

Related Issues

Resolves #2901

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

dai-chen
dai-chen previously approved these changes Aug 7, 2024
Copy link
Collaborator

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!

@dai-chen dai-chen added the enhancement New feature or request label Aug 7, 2024
@@ -60,6 +60,6 @@ public <T, C> T accept(ExpressionNodeVisitor<T, C> visitor, C context) {

@Override
public String toString() {
return getNameOrAlias();
return Strings.isNullOrEmpty(alias) ? name : name + " AS " + alias;
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you should add a new method getNameWithAlias() in this class similar to getNameOrAlias().
And I have some concerns when to use getNameOrAlias() and when to use getNameWithAlias()?
Could you deep dive in it?

Copy link
Contributor Author

@qianheng-aws qianheng-aws Aug 9, 2024

Choose a reason for hiding this comment

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

getNameOrAlias are used to get the field name to use in other operator. While in its toString, I just want to add more info than the field name, and it won't break the usage since it's just for explanation, no execution affection.

I think we don't need to add such a new function as it will only be used in this toString method if added, we should add it unless it can be reused in other places as well.

Copy link
Member

Choose a reason for hiding this comment

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

we should add it unless it can be reused in other places as well.

I doubt are there any other places to replace to getNameWithAlias either as toString does. Can you help to confirm them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having scanned over all the usage of getNameOrAlias, I don't see any other places need to be replaced. They are all related to execution.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @qianheng-aws . @dai-chen Can u help to double confirm it since u are the author of this class?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I can't recall the specific details. I think it should be safe to change the toString method only.


String result =
explainQuery(
String.format("SELECT (age + 1) AS agePlusOne FROM %s LIMIT 10", TEST_INDEX_ACCOUNT));
Copy link
Member

@LantaoJin LantaoJin Aug 9, 2024

Choose a reason for hiding this comment

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

Could you overwrite some more complex cases:

  1. SELECT <field-list> <alias-list> (compound)
  2. SELECT field as alias1, alias1 as alias2, alias2 as alias3 (nested alias)
  3. SELECT 1 as existing-field from t (override)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Does SQL support such syntax? Or do you mean filed1 as alias1, filed2 as alias2?
  2. Seems SQL don't support nested alias.
  3. ditto.

Copy link
Member

@LantaoJin LantaoJin Aug 9, 2024

Choose a reason for hiding this comment

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

  1. Compound case means not only contains pure fields but also contains fields with alias
  2. It should be a bug if it's unsupported. Translate to PPL, it should be a multiple-rename pipeline.
  3. Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I see. We have such cases in UT. Maybe make this IT be the compound case as well.
  2. yeah. PPL supports while SQL doesn't.

Copy link
Member

Choose a reason for hiding this comment

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

For 2 and 3, could you create two issues for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but I think they may be the same cause. It's because we only use ProjectOperator instead of EvalOperator for SQL, while project don't support update and evaluate nested fields like eval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Create a new issue to bring out this problem here: #2933

Signed-off-by: Heng Qian <[email protected]>
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.50%. Comparing base (7e73f12) to head (460189e).
Report is 39 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #2911   +/-   ##
=========================================
  Coverage     94.49%   94.50%           
- Complexity     5230     5236    +6     
=========================================
  Files           514      515    +1     
  Lines         14771    14791   +20     
  Branches        978      978           
=========================================
+ Hits          13958    13978   +20     
  Misses          772      772           
  Partials         41       41           
Flag Coverage Δ
sql-engine 94.50% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add more details in the explain for ProjectOperator
3 participants