You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem?
The nested query is supported in the legacy engine and not the V2 engine. As Legacy engine is becoming deprecated we need to support this functionality in the V2 engine.
Example:
SELECT nested(message.info) FROM nested_objects;
SELECT * FROM nested_objects WHERE nested(message.info)='b';
SELECT nested(message.info) FROM nested_objects ORDER BY nested(message.info);
SELECT nested(message.*) FROM nested_objects;
What solution would you like?
Port over functionality for the nested query to the V2 engine with the same functionality as in Legacy.
Update 2023-04-25: Discussed this with Forest offline.
@dai-chen I'd like to follow-up on this comment. As I understand it these two queries are to be equivalent
SELECT nested(message.info), name FROM table SELECT m.info, t.name FROM table AS t, t.message AS m.
In particular, for table like
message
name
{info : 1 }
nameA
[{info : 2}, {info : 3}]
nameB
the result will be
message.info
name
1
nameA
2
nameB
3
nameB
What's the use case for the cartesian product behaviour? As an end-user, I'd expect SELECT <expression> FROM table to return SELECT COUNT(*) FROM table number of results. For UIs, complex relationships usually shown in a parent-child arrangement, so I'd expect to have deal with complex properties like message.info.
Hi @dai-chen and @penghuo, nested(field.*) needs to be supported and some grammar changes are required. Below are options that were most reasonable out of many that were explored.
A new rule is proposed in order to add a new node that is similar to AllFields and will be used in SymbolTable to find all fields with the same path as the argument (e.g. field.* will include field.subfield1, field.subfield2,...). The proposed rule is to have an allTupleFields which can be used for both object and nested types when we begin to support SELECT field.*.
less/no refactoring when adding support for partiQL and is used in the following clauses:
SELECT
WHERE
GROUP BY
ORDER BY
HAVING
FROM clause is not affected
Supports:
SELECT message.* FROM nested
SELECT nested(message.*) FROM nested
May introduce errors or worse, invalid results like:
opensearchsql> SELECT * FROM nested_table GROUP BY message.*;
fetched rows / total rows = 0/0
+---------------------+----------------+------------------+
| message.dayOfWeek | message.info | message.author |
|---------------------+----------------+------------------|
+---------------------+----------------+------------------+
opensearchsql> SELECT * FROM nested_table GROUP BY myNum.*;
fetched rows / total rows = 0/0
2. Specific case only for nestedAllFunctionCall in functionCall
Isolated implementation for star within nested function which shouldn’t affect other functions
Supports
SELECT nested(message.*) FROM nested
Doesn’t support PartiQL which may lead to some refactoring when implementing PartiQL support.
3. allTupleFields in functionArg
functionArg
: expression
| allTupleFields
Only affects functions
Supports
SELECT nested(message.*) FROM nested
May introduce errors based on user errors for queries like
SELECT abs(int0.*) FROM calcs
Additional Context:
Option 1:
This change has the same effect as adding allTupleFields to columnName as it is only used in the expressionAtom. PartiQL implementation can be started in order for this option to reduce the risks. Implementing PartiQL could take a great amount of effort as it depends on updating indexScans to support table aliases.
Option 2:
This option seems the safest in the meantime while PartiQL support is yet to start. Value is added in the short term while refactoring if needed in the future is minimal. This may not need to be refactor, if it does then it is just a matter of removing it from the grammar.
Option 3:
This option has the risk of option 1 without its benefits of avoiding PartiQL refactoring in the future.
Activity
[-][FEATURE] Add Support for Nested Query[/-][+][FEATURE] Add Support for Nested Function[/+]MaxKsyunz commentedon Mar 21, 2023
Update 2023-04-25: Discussed this with Forest offline.
@dai-chen I'd like to follow-up on this comment. As I understand it these two queries are to be equivalent
SELECT nested(message.info), name FROM tableSELECT m.info, t.name FROM table AS t, t.message AS m.In particular, for
tablelikemessagename{info : 1 }nameA[{info : 2}, {info : 3}]nameBthe result will be
1nameA2nameB3nameBWhat's the use case for the cartesian product behaviour? As an end-user, I'd expect
SELECT <expression> FROM tableto returnSELECT COUNT(*) FROM tablenumber of results. For UIs, complex relationships usually shown in a parent-child arrangement, so I'd expect to have deal with complex properties likemessage.info.forestmvey commentedon Apr 25, 2023
Demo video for nested function use in SELECT clause.
nested_select_clause_demo.mp4
GumpacG commentedon Apr 27, 2023
Hi @dai-chen and @penghuo,
nested(field.*)needs to be supported and some grammar changes are required. Below are options that were most reasonable out of many that were explored.A new rule is proposed in order to add a new node that is similar to
AllFieldsand will be used inSymbolTableto find all fields with the same path as the argument (e.g. field.* will include field.subfield1, field.subfield2,...). The proposed rule is to have anallTupleFieldswhich can be used for bothobjectandnestedtypes when we begin to supportSELECT field.*.Options for grammar changes:
allTupleFieldsinexpressionAtomallTupleFieldsinfunctionCallallTupleFieldsinfunctionArgOption details:
expressionAtom : allTupleFields #allTupleFieldsExpressionAtomfunctionCall : nestedFunctionName LR_BRACKET allTupleFields RR_BRACKET #nestedAllFunctionCallfunctionArg : expression | allTupleFieldsAdditional Context:
Option 1:
This change has the same effect as adding
allTupleFieldstocolumnNameas it is only used in theexpressionAtom. PartiQL implementation can be started in order for this option to reduce the risks. Implementing PartiQL could take a great amount of effort as it depends on updating indexScans to support table aliases.Option 2:
This option seems the safest in the meantime while PartiQL support is yet to start. Value is added in the short term while refactoring if needed in the future is minimal. This may not need to be refactor, if it does then it is just a matter of removing it from the grammar.
Option 3:
This option has the risk of option 1 without its benefits of avoiding PartiQL refactoring in the future.
GumpacG commentedon Apr 27, 2023
Discussed offline and agreed on option 2.
cc: @penghuo, @dai-chen
[-][FEATURE] Add Support for Nested Function[/-][+][FEATURE] P0 Nested Function Support[/+]acarbonetto commentedon Jul 4, 2023
Phase 2 support: #1806