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 Distribution for MakeList and MakeSet #4490

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e443aa3
added MakeList and MakeSet aggregators
ezrahaleva-msft May 14, 2024
db1872a
Added MakeList and MakeSet to AggregateQueryTests.cs
ezrahaleva-msft May 24, 2024
b84e8e2
Adjust Aggregators
ezrahaleva-msft Jun 3, 2024
f42c7ec
Add Array Aggregate Continuation Token Test
ezrahaleva-msft Jun 3, 2024
2cb739c
Added group by coverage for MakeList and MakeSet
ezrahaleva-msft Jun 3, 2024
7c863d4
address comments
ezrahaleva-msft Jun 4, 2024
ff6637c
cleaning
ezrahaleva-msft Jun 4, 2024
a2c6d44
Refactored test to better detect when to ignore result order
ezrahaleva-msft Jun 5, 2024
1c82431
cleaning
ezrahaleva-msft Jun 6, 2024
8353971
cleaning, update baseline
ezrahaleva-msft Jun 6, 2024
2758e0b
cleaning
ezrahaleva-msft Jun 6, 2024
61059ac
removed old comment
ezrahaleva-msft Jun 6, 2024
57f6311
cleaning/refactoring
ezrahaleva-msft Jun 10, 2024
2c1c051
Merge branch 'master' into users/ezrahaleva/MakeListDistribution
ezrahaleva-msft Jun 11, 2024
51f5d12
cleaning
ezrahaleva-msft Jun 11, 2024
5fcb089
Add explicit cases to hit continuation token limit.
ezrahaleva-msft Jun 14, 2024
6522334
Added additional case to GroupBy tests
ezrahaleva-msft Jun 14, 2024
0defd1a
cleaning
ezrahaleva-msft Jun 14, 2024
eec3632
cleaning
ezrahaleva-msft Jun 17, 2024
918c35e
cleaning, updated baseline test
ezrahaleva-msft Jun 18, 2024
4dc9f9d
cleaning, updated baseline test
ezrahaleva-msft Jun 18, 2024
f05d33f
Added coverage to QueryPlanBaselineTests.cs
ezrahaleva-msft Jun 19, 2024
710fc76
refactored
ezrahaleva-msft Jun 20, 2024
be853ce
Merge branch 'master' into users/ezrahaleva/MakeListDistribution
ezrahaleva-msft Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ internal enum AggregateOperator
Average,
Count,
Max,
MakeList,
MakeSet,
Min,
Sum,
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.Pipeline.Aggregate.Aggregators
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.CosmosElements.Numbers;
using Microsoft.Azure.Cosmos.Query.Core.Exceptions;
using Microsoft.Azure.Cosmos.Query.Core.Monads;

internal sealed class MakeListAggregator : IAggregator
{
private readonly List<CosmosElement> globalList;

private MakeListAggregator(CosmosArray initialList)
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
{
this.globalList = new List<CosmosElement>();
foreach (CosmosElement setItem in initialList)
{
this.globalList.Add(setItem);
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
}

public void Aggregate(CosmosElement localList)
{
if (!(localList is CosmosArray cosmosArray))
{
throw new ArgumentException($"{nameof(localList)} must be an array.");
}

foreach (CosmosElement listItem in cosmosArray)
{
this.globalList.Add(listItem);
}
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved

public CosmosElement GetResult()
{
CosmosElement[] cosmosElementArray = new CosmosElement[this.globalList.Count];
this.globalList.CopyTo(cosmosElementArray);
return CosmosArray.Create(cosmosElementArray);
}

public string GetContinuationToken()
{
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
return this.globalList.ToString();
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved

public static TryCatch<IAggregator> TryCreate(CosmosElement continuationToken)
{
CosmosArray partialList;
if (continuationToken != null)
{
if (!(continuationToken is CosmosArray cosmosPartialList))
{
return TryCatch<IAggregator>.FromException(
new MalformedContinuationTokenException($@"Invalid MakeList continuation token: ""{continuationToken}""."));
}

partialList = cosmosPartialList;
}
else
{
partialList = CosmosArray.Empty;
}

return TryCatch<IAggregator>.FromResult(
new MakeListAggregator(initialList: partialList));
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved

public CosmosElement GetCosmosElementContinuationToken()
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
{
CosmosElement[] cosmosElementArray = new CosmosElement[this.globalList.Count];
this.globalList.CopyTo(cosmosElementArray);
return CosmosArray.Create(cosmosElementArray);
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.Pipeline.Aggregate.Aggregators
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Microsoft.Azure.Cosmos.CosmosElements;
using Microsoft.Azure.Cosmos.CosmosElements.Numbers;
using Microsoft.Azure.Cosmos.Query.Core.Exceptions;
using Microsoft.Azure.Cosmos.Query.Core.Monads;

internal sealed class MakeSetAggregator : IAggregator
{
private readonly HashSet<CosmosElement> globalSet;

private MakeSetAggregator(CosmosArray initialSet)
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
{
this.globalSet = new HashSet<CosmosElement>();
foreach (CosmosElement setItem in initialSet)
{
this.globalSet.Add(setItem);
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
}

public void Aggregate(CosmosElement localSet)
{
if (!(localSet is CosmosArray cosmosArray))
{
throw new ArgumentException($"{nameof(localSet)} must be an array.");
}

foreach (CosmosElement setItem in cosmosArray)
{
this.globalSet.Add(setItem);
}
}

public CosmosElement GetResult()
{
CosmosElement[] cosmosElementArray = new CosmosElement[this.globalSet.Count];
this.globalSet.CopyTo(cosmosElementArray);
return CosmosArray.Create(cosmosElementArray);
}

public string GetContinuationToken()
{
return this.globalSet.ToString();
}

public static TryCatch<IAggregator> TryCreate(CosmosElement continuationToken)
{
CosmosArray partialSet;
if (continuationToken != null)
{
if (!(continuationToken is CosmosArray cosmosPartialSet))
{
return TryCatch<IAggregator>.FromException(
new MalformedContinuationTokenException($@"Invalid MakeSet continuation token: ""{continuationToken}""."));
}

partialSet = cosmosPartialSet;
}
else
{
partialSet = CosmosArray.Empty;
}

return TryCatch<IAggregator>.FromResult(
new MakeSetAggregator(initialSet: partialSet));
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved

public CosmosElement GetCosmosElementContinuationToken()
{
CosmosElement[] cosmosElementArray = new CosmosElement[this.globalSet.Count];
this.globalSet.CopyTo(cosmosElementArray);
return CosmosArray.Create(cosmosElementArray);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ public static TryCatch<AggregateValue> TryCreate(
tryCreateAggregator = CountAggregator.TryCreate(continuationToken);
break;

case AggregateOperator.MakeList:
tryCreateAggregator = MakeListAggregator.TryCreate(continuationToken);
break;

case AggregateOperator.MakeSet:
tryCreateAggregator = MakeSetAggregator.TryCreate(continuationToken);
break;

case AggregateOperator.Max:
tryCreateAggregator = MinMaxAggregator.TryCreateMaxAggregator(continuationToken);
break;
Expand All @@ -381,7 +389,6 @@ public static TryCatch<AggregateValue> TryCreate(
case AggregateOperator.Sum:
tryCreateAggregator = SumAggregator.TryCreate(continuationToken);
break;

ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
default:
throw new ArgumentException($"Unknown {nameof(AggregateOperator)}: {aggregateOperator}.");
}
Expand Down
Loading
Loading