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 18 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 @@ -8,6 +8,8 @@ internal enum AggregateOperator
{
Average,
Count,
MakeList,
MakeSet,
Max,
Min,
Sum,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.Pipeline.Aggregate.Aggregators
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
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 listItem in initialList)
{
this.globalList.Add(listItem);
}
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.");
}

this.globalList.AddRange(cosmosArray.ToList<CosmosElement>());
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved

public CosmosElement GetResult()
{
return CosmosArray.Create(this.globalList);
}
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
{
return this.GetResult();
}
ezrahaleva-msft marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Query.Core.Pipeline.Aggregate.Aggregators
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
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.");
}

this.globalSet.UnionWith(cosmosArray.ToList<CosmosElement>());
}

public CosmosElement GetResult()
{
return CosmosArray.Create(this.globalSet);
}

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()
{
return this.GetResult();
}
}
}
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 Down
Loading