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

Query: Adds support for multi-value Group By query for LINQ #4481

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

leminh98
Copy link
Contributor

@leminh98 leminh98 commented May 13, 2024

Pull Request Template

Description

This PR adds the ability to translate LINQ query to SQL query with multiple items in the SQL select clause. This is achieved through the value clause using NewExpression

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] This change requires a documentation update

Closing issues

To automatically close an issue: closes #IssueNumber

@bartelink
Copy link
Contributor

Semi-related issues in case they are easy to address in the same block of work:

JOIN value IN root)) AS v2
GROUP BY root["id"]
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest,{"errors":[{"severity":"Error","location":{"start":129,"end":134},"code":"SC1001","message":"Syntax error, incorrect syntax near 'value'."}]},0x800A0B00]]></ErrorMessage>
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

This seems to indicate invalid query is being generated?

<SqlQuery><![CDATA[]]></SqlQuery>
<ErrorMessage><![CDATA[Expression with NodeType 'New' is not supported.]]></ErrorMessage>
<SqlQuery><![CDATA[
SELECT root["FamilyId"] AS familyId, ARRAY_LENGTH(root) AS familyIdCount
Copy link
Contributor

Choose a reason for hiding this comment

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

ARRAY_LENGTH(root)

Should this be COUNT(root)

JOIN v2 IN root)) AS v3
GROUP BY root["id"]
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest,{"errors":[{"severity":"Error","location":{"start":7,"end":9},"code":"SC2102","message":"Property reference 'v1' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."},{"severity":"Error","location":{"start":21,"end":23},"code":"SC2102","message":"Property reference 'v3' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."}]},0x800A0B00]]></ErrorMessage>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before. Seems like invalid query is being generated?

ORDER BY f["FamilyId"] ASC)) AS v1
GROUP BY root["id"]
]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest,{"errors":[{"severity":"Error","location":{"start":93,"end":98},"code":"SC1001","message":"Syntax error, incorrect syntax near 'value'."}]},0x800A0B00]]></ErrorMessage>
Copy link
Contributor

Choose a reason for hiding this comment

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

Invalid query?

SELECT VALUE root["id"]
FROM root) AS r0
GROUP BY r0
]]></SqlQuery>
</Output>
</Result>
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

Result

Can you please include the output resultset as well? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the data set is randomly generated. I don't think that would work with the baseline. Unless we fix the seed

<SqlQuery><![CDATA[]]></SqlQuery>
<ErrorMessage><![CDATA[Expression with NodeType 'New' is not supported.]]></ErrorMessage>
<SqlQuery><![CDATA[
SELECT r0 AS keyAlias, ARRAY_LENGTH(r0) AS count
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

ARRAY_LENGTH(r0)

Should this be COUNT?

<SqlQuery><![CDATA[]]></SqlQuery>
<ErrorMessage><![CDATA[Expression with NodeType 'New' is not supported.]]></ErrorMessage>
<SqlQuery><![CDATA[
SELECT root["id"] AS Key, root["id"] AS key
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

AS Key

Neat #Resolved

FROM root
GROUP BY root["id"]
ORDER BY root["Int"] ASC]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest,{"errors":[{"severity":"Error","location":{"start":99,"end":110},"code":"SC2103","message":"Property reference 'root[\"Int\"]' is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause."},{"severity":"Error","location":{"start":44,"end":48},"code":"SC2102","message":"Property reference 'root' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."}]},0x800A0B00]]></ErrorMessage>
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

Status Code: BadRequest,{"errors":[{"severity":"Error","location":{"start":99,"end":110},"code":"SC2103","message":"Property reference 'root["Int"]' is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause."},{"severity":"Error","location":{"start":44,"end":48},"code":"SC2102","message":"Property reference 'root' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."}]},0x800A0B00

Can you resolve these errors? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is expected errors since we don't support order by and group by togerther

FROM root
GROUP BY root["id"]
ORDER BY root["id"] DESC]]></SqlQuery>
<ErrorMessage><![CDATA[Status Code: BadRequest,{"errors":[{"severity":"Error","location":{"start":44,"end":48},"code":"SC2102","message":"Property reference 'root' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."}]},0x800A0B00]]></ErrorMessage>
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

Is there a way for customers to resolve this error? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

none other than not combining groupby and order by since we dont support it

@@ -1046,6 +1046,11 @@ public void TestGroupByMultiValueTranslation()
stringField = "abc"
})));

for(int i = 0; i < inputs.Count; i++)
{
inputs[i].ignoreOrderingForAnonymousTypeObject = true;
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

We should avoid this for ORDER BY queries. #Resolved

return queryResults.SequenceEqual(dataResults);
}

return queryResults.OrderBy(x => x).ToList().SequenceEqual(dataResults.OrderBy(x => x).ToList());
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

Ternary would be useful:
return ignoreOrdering?
. . . :
. . .; #Resolved

@@ -1046,6 +1046,11 @@ public void TestGroupByMultiValueTranslation()
stringField = "abc"
})));

for(int i = 0; i < inputs.Count; i++)
{
inputs[i].ignoreOrderingForAnonymousTypeObject = true;
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

ignoreOrderingForAnonymousTypeObject

I would pass this as an argument to the constructor rather than modifying after constructions. #Resolved

@@ -646,17 +651,21 @@ public class LinqTestInput : BaselineTestInput
// - unordered query since the results are not deterministics for LinQ results and actual query results
// - scenarios not supported in LINQ, e.g. sequence doesn't contain element.
internal bool skipVerification;

internal bool ignoreOrderingForAnonymousTypeObject;
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

readonly? #Resolved

Copy link
Contributor

@adityasa adityasa left a comment

Choose a reason for hiding this comment

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

🕐

throw new DocumentQueryException(string.Format(CultureInfo.CurrentCulture, ClientResources.ExpressionTypeIsNotSupported, ExpressionType.New));
break;
}
case ExpressionType.New:
Copy link
Contributor

@adityasa adityasa May 16, 2024

Choose a reason for hiding this comment

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

I am not able to make the 1:1 connection between new expression and multi-value group by.
IOW, it's not clear why every new expression here is a multi-value GROUP BY and vice-versa. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Enables automation to merge PRs QUERY
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants