Skip to content

Add Support for Field Star in Nested Function. - #278

Merged
forestmvey merged 2 commits into
integ-nested-all-fieldsfrom
dev-nested-all-fields
Jun 23, 2023
Merged

forestmvey merged 2 commits into
integ-nested-all-fieldsfrom
dev-nested-all-fields

Conversation

@forestmvey

Copy link
Copy Markdown

Description

Add support for using the * at end of field parameter in the nested function. All nested fields under supplied path will be expanded as column identifiers. Grammar has been added to only support the AllTupleFields usage with the nested function since this change will effect field usage in all queries and needs further planning with V2 implementation.

Example Queries

SELECT nested(message.*) from nested_objects;

Issues Resolved

Portion of Issue: 1111

Changes From Legacy

  • Path parameter is redundant therefore not supported in parser and will fallback to legacy engine.

Edge Cases

Queries that produce repeating column identifiers like:

SELECT nested(field.*), nested(field.innerField) ...

Or

SELECT nested(field.*), nested(field.*) ...

Will result in error:

{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Multiple entries with same key: nested(message.info)=\"a\" and nested(message.info)=\"a\"",
    "type": "IllegalArgumentException"
  },
  "status": 400
}

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.

@codecov

codecov Bot commented Jun 19, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #278 (35bab09) into integ-nested-all-fields (6c3744e) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@                      Coverage Diff                      @@
##             integ-nested-all-fields     #278      +/-   ##
=============================================================
+ Coverage                      97.29%   97.30%   +0.01%     
- Complexity                      4408     4425      +17     
=============================================================
  Files                            388      388              
  Lines                          10944    10996      +52     
  Branches                         774      780       +6     
=============================================================
+ Hits                           10648    10700      +52     
  Misses                           289      289              
  Partials                           7        7              
Flag Coverage Δ
sql-engine 97.30% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...ain/java/org/opensearch/sql/analysis/Analyzer.java 100.00% <100.00%> (ø)
...rg/opensearch/sql/analysis/ExpressionAnalyzer.java 100.00% <100.00%> (ø)
...va/org/opensearch/sql/analysis/NestedAnalyzer.java 100.00% <100.00%> (ø)
...nsearch/sql/analysis/SelectExpressionAnalyzer.java 100.00% <100.00%> (ø)
...a/org/opensearch/sql/analysis/TypeEnvironment.java 100.00% <100.00%> (ø)
...rg/opensearch/sql/analysis/symbol/SymbolTable.java 100.00% <100.00%> (ø)
...pensearch/sql/sql/parser/AstExpressionBuilder.java 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@forestmvey
forestmvey force-pushed the dev-nested-all-fields branch from 8c65c16 to dba24ea Compare June 19, 2023 19:18
TypeEnvironment environment = context.peek();
Map<String, ExprType> lookupAllTupleFields =
environment.lookupAllTupleFields(Namespace.FIELD_NAME);
environment.resolve(new Symbol(Namespace.FIELD_NAME, node.getPath()));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

does this work with aliases? I think we need to consider resolving the nested symbol with alias instead of path if an alias if given.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider re-using this for when we want to deal with PartiQL tables. We will want to have multiple symbol tables for joins, nested, etc. Being able to generate a 'nested' symbol table from an existing table would be beneficial for PartiQL syntax.

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.

allTupleFields like allFields is not supported with aliases. It wouldn't make sense as the column identifiers are expanded. I think resolving with the alias would always throw a semantic exception as the alias isn't stored in the FIELD_NAME portion to the symbolTable.

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.

Don't think I fully understand what you mean about generating symbol tables for partiql. I see for joins but what is a nested symbol table?

@Yury-Fridlyand

Yury-Fridlyand commented Jun 20, 2023 •

Copy link
Copy Markdown

These fails:

SELECT upper(nested(message.*)) from nested-type;
SELECT nested(message.*) + 42 from nested-type;
  1. Should we support 1?
  2. 2 should be rejected by SQL parser: nested(<arg-with-*>) can't be an argument for [all] functions, only specific ones

@Yury-Fridlyand

Yury-Fridlyand commented Jun 20, 2023 •

Copy link
Copy Markdown
SELECT nested(message.*) from nested-type limit 4;

returns 5 rows

+------------------------+---------------------------+----------------------+
| nested(message.author) | nested(message.dayOfWeek) | nested(message.info) |
+------------------------+---------------------------+----------------------+
| keyword                | long                      | keyword              |
+------------------------+---------------------------+----------------------+
| e                      | 1                         | a                    |
| f                      | 2                         | b                    |
| g                      | 1                         | c                    |
| h                      | 4                         | c                    |
| i                      | 5                         | a                    |
+------------------------+---------------------------+----------------------+

Probably, you shouldn't push down limit when nested is present.

UPD

It is not a bug introduced by this feature, it present on main already. Created opensearch-project#1764 to track.

@forestmvey forestmvey closed this Jun 21, 2023
@forestmvey forestmvey reopened this Jun 21, 2023
@forestmvey

Copy link
Copy Markdown
Author

I added safeguards for these cases. Now they return UnsupportedOperationException.

@Yury-Fridlyand Yury-Fridlyand left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you add ITs with incorrect usages of nested-with-star? Maybe a doctest too.

@MitchellGale
MitchellGale self-requested a review June 23, 2023 17:22
@forestmvey
forestmvey force-pushed the dev-nested-all-fields branch from 7895f78 to 35bab09 Compare June 23, 2023 20:47
@forestmvey
forestmvey merged commit c306bf2 into integ-nested-all-fields Jun 23, 2023
@forestmvey
forestmvey deleted the dev-nested-all-fields branch June 23, 2023 21:23
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.

6 participants