Repository navigation
Conversation
|
@GumpacG Thanks for working on this PoC! A high level question is: can/should we implement this in some way which can support standard PartiQL/SQL++ as well? As you many know, Here is my random thoughts on how to support PartiQL and then we can discuss if we can do the same for First, AST will look like: After analyzed/planned: (Q for After optimized with If some solution like above makes sense, the question is: can we treat Otherwise, I'm afraid that:
|
|
|
||
| nestedField | ||
| : qualifiedName | ||
| | stringLiteral (DOT stringLiteral)* |
There was a problem hiding this comment.
Although legacy supports this, I think we may consider deprecate it.
If so, we just need a nestedFunctionName rule under scalarFunctionName?
There was a problem hiding this comment.
@dai-chen If we go in this direction we would have to merge to 3.x since this will be a breaking change. This also means that legacy will have to be deprecated in 3.x instead of 2.x.
Another option would be to support string arguments in 2.x in order to deprecate in 2.x. Then we can push a change for 3.x that will change the behaviour.
What do you think?
There was a problem hiding this comment.
Sure. Are we doing the same in relevancy search function? I recall we have similar issue discussed last time. If we go this direction for relevancy function, probably we can do this breaking change in 3.x together?
@GumpacG Sure. I was thinking it would be great if we can have single code path after logical plan. I also don't want to make it complicated at this point, so I'm good if the code changes are not too much and easy to refactor when introducing PartQL support in V2 in future. Btw, here are 2 sample queries previously we have limitation. Could you confirm if any chance to support in current approach in V2?
Thanks! |
|
We are still pretty early on in the implementation of the |
| public boolean isNested() { | ||
| return this.toString().contains("."); | ||
| } |
There was a problem hiding this comment.
I'm wondering, rather than check in this tricky way as what legacy does, should we add nested data type? Because in V2 engine, we have strict semantic check mechanism and can define function signature, ex. nested(nestDataType).
There was a problem hiding this comment.
We have added stricter parser grammar for the nested function. We could extend the Field class for nested types, or add some functionality through optional arguments in a new Field constructor. Are either of these options what you had in mind?
| public T visitNestedFunction(NestedFunction node, C context) { | ||
| return visitChildren(node, context); | ||
| } |
There was a problem hiding this comment.
So nested function is special node just like highlight function. Any chance to make it just a regular function registered to function repository? How can we move this to opensearch module? As discussed, all OpenSearch specific functions including relevancy search and highlight should be moved out of core soon.
There was a problem hiding this comment.
Has been updated as a regular function. I am not sure which approach will be needed for moving necessary functions to the opensearch module.
e994e67 to
508cbcc
Compare
|
We have added some logic for a naive implementation of nested in a Supported aggregation query: sequenceDiagram
participant SQLService
participant ParserBaseRoot
participant AstExpressionBuilder
participant QueryService
participant Analyzer
participant Unnested
participant ExpressionAnalyzer
participant Planner
participant DefaultImplementor
participant AggregationQueryBuilder
SQLService->>ParserBaseRoot:visitRoot
ParserBaseRoot->>AstExpressionBuilder:visitNestedFunction
AstExpressionBuilder-->>ParserBaseRoot:Function
ParserBaseRoot-->>SQLService:UnresolvedPlan
SQLService->>QueryService:analyze
QueryService->>Analyzer:visitProject
Analyzer->>Unnested:accept
Unnested->>ExpressionAnalyzer:visitFunction
ExpressionAnalyzer-->>Unnested:Function
Unnested-->>Analyzer:LogicalNested
Analyzer-->>QueryService:UnresolvedPlan
QueryService->>Planner:plan
Planner->>DefaultImplementor:visitProject
DefaultImplementor->>AggregationQueryBuilder:buildAggregationBuilder
AggregationQueryBuilder-->>DefaultImplementor:NestedAggregationBuilder:MetricParser
DefaultImplementor->>OpenSearchRequestBuilder:pushDownAggregation
DefaultImplementor-->>Planner:PhysicalPlan
Planner-->>QueryService:PhysicalPlan
QueryService-->>SQLService:PhysicalPlan
|
Thanks for this in-depth comment for an implementation that can work with PartiQL. We have updated the code with this implementation in mind. Further down the road we should be able to share this implementation with PartiQL. Please let us know what you think of the new implementation and if it was more what you had in mind. |
Codecov Report❌ Patch coverage is ❌ Your project status has failed because the head coverage (96.26%) is below the target coverage (99.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1210 +/- ##
============================================
- Coverage 98.36% 96.26% -2.11%
- Complexity 3643 3644 +1
============================================
Files 343 348 +5
Lines 9017 9227 +210
Branches 585 605 +20
============================================
+ Hits 8870 8882 +12
- Misses 142 334 +192
- Partials 5 11 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@forestmvey Thanks for the update! Will take another look. Meanwhile I dived into the relation between PartiQL and SQL Lateral Join. Will share my thoughts for your reference shortly. |
|
87d836a to
e5fdf25
Compare
|
@forestmvey @MaxKsyunz I shared my recent finding for how to better support PartiQL in V2 engine here for your future reference: #1104 (comment). According to my investigation, considering PartiQL unnest grammar as a special case of ANSI SQL Lateral Join seems a good solution. However, one of the blocker in v2 engine is currently we only support symbol resolving from a single table in Analyzer. In the short term, I think we're good to migrate nested function in v2 first in this PR. We can discuss further later. Thanks! |
|
@dai-chen as discussed regarding arrays of objects, we want to follow PartiQL behaviour. However, it is still unclear if we should flatten or not. With the examples below, would you be able let us know which direction we should go? Legacy BehaviourLegacy behaviour for the query With data ( PartiQL behaviourTest data: Query: Query: |
|
@GumpacG Thanks for the context! I will double check. |
Signed-off-by: Guian Gumpac <[email protected]> Signed-off-by: forestmvey <[email protected]>
Signed-off-by: Guian Gumpac <[email protected]>
Signed-off-by: forestmvey <[email protected]>
Signed-off-by: Guian Gumpac <[email protected]>
e5fdf25 to
da8a674
Compare
|
@GumpacG I think there are problems in your data and query
|
|
@dai-chen thanks for clarifying. I modified my PartiQL data to reflect our test data and V2 nested implementation should include flattening. Including an example here for reference. As a result #1305 should be closed as legacy behaviour is expected. PartiQL data: PartiQL query and result: |
|
Closing this as the spike and POC are done. |
Description
This proposal will outline a suggestion for the scope and implementation of the nested function in the V2 engine. This Draft PR is only meant for discussion and not to be merged.
Requirements
nestedin the new engine needs to support all functionality ofnestedin the legacy engine. This includes:nestedinSELECT,WHERE,GROUP BY. example queries:SELECT nested(message.info) FROM multi_nestedSELECT nested(message.*) FROM multi_nestedSELECT nested(message.info) FROM multi_nested WHERE nested('message', message.info = 'a' OR message.info = 'a')SELECT * FROM opensearch-sql_test_index_nested_type WHERE nested(message.info)='b';SELECT nested(message.info) FROM multi_nested GROUP BY nested(message.info)SELECT nested(message.info) FROM multi_nested GROUP BY message.infoalias of the result should be the argument of the
nestedfunctionnestedin function calls likeSELECT nested(message.info) FROM multi_nested WHERE wildcardquery(nested(message.info), 'z*')multilevel nested field queries like
SELECT nested(message.author.address.street) FROM opensearch-sql_test_index_multi_nestedmultiple nested functions in one query which is a limitation on elasticsearch like
SELECT nested(message.author.address.street), nested(message.info), nested(message.dayOfWeek) FROM opensearch-sql_test_index_multi_nestednestedaccepts strings as arguments for identifiers (This still needs to be investigated if it should not be supported). Example queries are:SELECT nested("field.subield") FROM test;SELECT nested("field"."subield") FROM test;SELECT nested('field.subield') FROM test;SELECT nested('field'.'subield') FROM test;Limitations
If we decide to not support strings as argument, then this will become a breaking change for 3.x
Implementation
The new SQL engine implementation of nested function will be similar to the implementation of nested function in legacy. The logical plan builder implementation will be the same. Legacy’s logical plan builder is a part of NestedFieldProjection while the new engine will contain it in OpenSearchRequestBuilder. This is currently implemented in this PoC for
nestedin only theSELECTclause. Implementation fornestedinWHEREandGROUP BYmay be different.Proof of Concept
The PoC does not satisfy all requirements for nested in
SELECT. It only supports an end to end implementation ofSELECT nested(message.info) FROM opensearch-sql_test_index_nested_type;. Further testing and support for more cases will be added once we are in agreement of the PoC.SQL queries to support for each stage of implementation
Schedule
nestedfunction working inSELECT,WHERE, andGROUP BYIssues Resolved
#1111
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.