diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/AggregateQueryTests.AggregateMixedTypes_baseline.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/AggregateQueryTests.AggregateMixedTypes_baseline.xml index e7f3e96c19..71f90623cc 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/AggregateQueryTests.AggregateMixedTypes_baseline.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Query/AggregateQueryTests.AggregateMixedTypes_baseline.xml @@ -1,4 +1,4 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + makeListResult = inputDocuments + .Select(doc => + { + if (!doc.TryGetValue(aggregateTestArgs.PartitionKey, out CosmosElement cosmosElement)) + { + Assert.Fail("Failed to get partition key from document"); + } + + return cosmosElement; + }) + .ToList(); + + IReadOnlyList makeSetResult = makeListResult.Distinct().ToList(); + AggregateQueryArguments[] aggregateQueryArgumentsList = new AggregateQueryArguments[] { new AggregateQueryArguments( @@ -237,6 +314,14 @@ private static AggregateQueryArguments[] CreateAggregateQueryArguments( aggregateOperator: "COUNT", expectedValue: CosmosNumber64.Create(inputDocuments.Count()), predicate: "true"), + new AggregateQueryArguments( + aggregateOperator: "MAKELIST", + expectedValue: CosmosArray.Create(makeListResult), // construct cosmos array from linq result + predicate: "true"), + new AggregateQueryArguments( + aggregateOperator: "MAKESET", + expectedValue: CosmosArray.Create(makeSetResult), // construct cosmos array from linq result + predicate: "true"), new AggregateQueryArguments( aggregateOperator: "MAX", expectedValue: CosmosString.Create("xyz"), @@ -392,6 +477,32 @@ async Task ImplementationAsync( Assert.Fail($"Something went wrong with query: {query}, ex: {ex}"); } } + + string[] arrayAggregateQueries = new string[] + { + $"SELECT VALUE MAKELIST(c.{uniqueField}) FROM c WHERE c.{uniqueField} = {valueOfInterest}", + $"SELECT VALUE MAKESET(c.{uniqueField}) FROM c WHERE c.{uniqueField} = {valueOfInterest}", + }; + + foreach (string query in arrayAggregateQueries) + { + try + { + List items = await QueryTestsBase.RunQueryAsync( + container, + query, + new QueryRequestOptions() + { + MaxConcurrency = 10, + }); + + Assert.IsTrue((items.Single() is CosmosArray result) && result.Equals(CosmosArray.Create(CosmosNumber64.Create(valueOfInterest)))); + } + catch (Exception ex) + { + Assert.Fail($"Something went wrong with query: {query}, ex: {ex}"); + } + } } } @@ -527,7 +638,7 @@ private async Task TestQueryCrossPartitionAggregateFunctionsWithMixedTypesHelper args.UndefinedKey }; - string[] aggregateOperators = new string[] { "AVG", "MIN", "MAX", "SUM", "COUNT" }; + string[] aggregateOperators = new string[] { "AVG", "MIN", "MAKELIST", "MAKESET", "MAX", "SUM", "COUNT" }; string[] typeCheckFunctions = new string[] { "IS_ARRAY", "IS_BOOL", "IS_NULL", "IS_NUMBER", "IS_OBJECT", "IS_STRING", "IS_DEFINED", "IS_PRIMITIVE" }; List queries = new List(); foreach (string aggregateOperator in aggregateOperators) @@ -609,10 +720,19 @@ FROM c { Assert.AreEqual(1, items.Count); CosmosElement aggregateResult = items.First(); - if(aggregateResult is not CosmosUndefined) { - writer.WriteCData(items.Single().ToString()); + if ((formattedQuery.Contains("MAKELIST") || formattedQuery.Contains("MAKESET")) + && (aggregateResult is CosmosArray aggregateResultArray)) + { + CosmosElement[] normalizedAggregateResult = aggregateResultArray.ToArray(); + Array.Sort(normalizedAggregateResult); + writer.WriteCData(CosmosArray.Create(normalizedAggregateResult).ToString()); + } + else + { + writer.WriteCData(items.Single().ToString()); + } } }