Beispiel #1
0
 public override void WriteNumber64Value(Number64 value)
 {
     if (value.IsInteger)
     {
         this.writer.WriteValue(Number64.ToLong(value));
     }
     else
     {
         this.writer.WriteValue(Number64.ToDouble(value));
     }
 }
 /// <inheritdoc />
 public override void WriteNumberValue(Number64 value)
 {
     if (value.IsInteger)
     {
         this.WriteIntegerInternal(Number64.ToLong(value));
     }
     else
     {
         this.WriteDoubleInternal(Number64.ToDouble(value));
     }
 }
            /// <inheritdoc />
            public override Number64 GetNumber64Value(IJsonNavigatorNode node)
            {
                if (!(node is NumberNode numberNode))
                {
                    throw new ArgumentException($"{node} was not of type: {nameof(NumberNode)}.");
                }

                Number64 value = JsonTextParser.GetNumberValue(numberNode.BufferedToken.Span);

                return(value);
            }
            private static int ParseQueryState(QueryState state)
            {
                if (state == default)
                {
                    return(0);
                }

                CosmosObject parsedContinuationToken = CosmosObject.Parse(((CosmosString)state.Value).Value);
                int          continuationCount       = (int)Number64.ToLong(((CosmosNumber64)parsedContinuationToken["continuationCount"]).Value);

                return(continuationCount);
            }
Beispiel #5
0
            /// <inheritdoc />
            public override void WriteNumberValue(Number64 value)
            {
                if (value.IsInteger)
                {
                    this.WriteIntegerInternal(Number64.ToLong(value));
                }
                else
                {
                    this.WriteDoubleInternal(Number64.ToDouble(value));
                }

                this.bufferedContexts.Peek().Count++;
            }
Beispiel #6
0
        /// <summary>
        /// Reads the next number token but returns null at the end of an array.
        /// </summary>
        /// <returns>The next number token but returns null at the end of an array.</returns>
        private double?ReadNumberValue()
        {
            this.Read();
            if (this.jsonReader.CurrentTokenType == JsonTokenType.EndArray)
            {
                return(null);
            }

            Number64 value       = this.jsonReader.GetNumberValue();
            double   doubleValue = Number64.ToDouble(value);

            return(doubleValue);
        }
Beispiel #7
0
        private static CosmosElement PerformUnaryNumberOperation(
            Func <double, double> unaryOperation,
            CosmosElement operand)
        {
            if (!(operand is CosmosNumber operandAsNumber))
            {
                return(Undefined);
            }

            double result = unaryOperation(Number64.ToDouble(operandAsNumber.Value));

            return(CosmosNumber64.Create(result));
        }
Beispiel #8
0
        private static int GetResponseCount(Stream stream)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                CosmosObject element = CosmosObject.CreateFromBuffer(memoryStream.ToArray());
                if (!element.TryGetValue("_count", out CosmosElement value))
                {
                    Assert.Fail();
                }

                return((int)Number64.ToLong(((CosmosNumber)value).Value));
            }
        }
        public static MockQueryPipelineStage Create(
            IReadOnlyList <IReadOnlyList <CosmosElement> > pages,
            CosmosElement continuationToken)
        {
            MockQueryPipelineStage stage = new MockQueryPipelineStage(pages);

            if (continuationToken != null)
            {
                CosmosNumber index = continuationToken as CosmosNumber;
                stage.PageIndex = Number64.ToLong(index.Value);
            }

            return(stage);
        }
Beispiel #10
0
        public bool Visit(CosmosNumber cosmosNumber)
        {
            if (cosmosNumber.Value.IsInteger)
            {
                return(false);
            }

            double value = Number64.ToDouble(cosmosNumber.Value);

            return
                (double.IsInfinity(value) ||
                 double.IsNaN(value) ||
                 double.IsNegativeInfinity(value) ||
                 double.IsPositiveInfinity(value));
        }
Beispiel #11
0
        public override double?AsFloatingPoint()
        {
            double?value;

            if (this.IsFloatingPoint)
            {
                value = Number64.ToDouble(this.GetValue());
            }
            else
            {
                value = null;
            }

            return(value);
        }
Beispiel #12
0
        public override long?AsInteger()
        {
            long?value;

            if (this.IsInteger)
            {
                value = Number64.ToLong(this.GetValue());
            }
            else
            {
                value = null;
            }

            return(value);
        }
        /// <summary>
        /// Reads the next number token but returns null at the end of an array.
        /// </summary>
        /// <returns>The next number token but returns null at the end of an array.</returns>
        private double?ReadNumberValue()
        {
            this.Read();
            double?value;

            if (this.jsonReader.CurrentTokenType == JsonTokenType.EndArray)
            {
                value = null;
            }
            else
            {
                value = Number64.ToDouble(this.jsonReader.GetNumberValue());
            }

            return(value);
        }
        /// <summary>
        /// Adds a local sum to the global sum.
        /// </summary>
        /// <param name="localSum">The local sum.</param>
        public void Aggregate(CosmosElement localSum)
        {
            // If someone tried to add an undefined just set the globalSum to NaN and it will stay that way for the duration of the aggregation.
            if (localSum == null)
            {
                this.globalSum = double.NaN;
            }
            else
            {
                if (!(localSum is CosmosNumber cosmosNumber))
                {
                    throw new ArgumentException("localSum must be a number.");
                }

                this.globalSum += Number64.ToDouble(cosmosNumber.Value);
            }
        }
Beispiel #15
0
        public override SqlObject VisitLiteralScalarExpression([NotNull] sqlParser.LiteralScalarExpressionContext context)
        {
            Contract.Requires(context != null);
            Contract.Requires(context.ChildCount == 1);
            Contract.Requires(context.children[0].ChildCount == 1);

            TerminalNodeImpl terminalNode = (TerminalNodeImpl)(context.children[0].GetChild(0));

            SqlLiteralScalarExpression sqlLiteralScalarExpression;

            switch (terminalNode.Symbol.Type)
            {
            case sqlParser.STRING_LITERAL:
                string value = CstToAstVisitor.GetStringValueFromNode(terminalNode);
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create(value));
                break;

            case sqlParser.NUMERIC_LITERAL:
                Number64 number64 = CstToAstVisitor.GetNumber64ValueFromNode(terminalNode);
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(number64));
                break;

            case sqlParser.K_TRUE:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(true));
                break;

            case sqlParser.K_FALSE:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.Create(false));
                break;

            case sqlParser.K_NULL:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlNullLiteral.Create());
                break;

            case sqlParser.K_UNDEFINED:
                sqlLiteralScalarExpression = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());
                break;

            default:
                throw new ArgumentOutOfRangeException($"Unknown symbol type: {terminalNode.Symbol.Type}");
            }

            return(sqlLiteralScalarExpression);
        }
Beispiel #16
0
        private static CosmosElement PerformBinaryNumberOperation(
            Func <double, double, double> operation,
            CosmosElement left,
            CosmosElement right)
        {
            if (!(left is CosmosNumber leftAsNumber))
            {
                return(Undefined);
            }

            if (!(right is CosmosNumber rightAsNumber))
            {
                return(Undefined);
            }

            double result = operation(Number64.ToDouble(leftAsNumber.Value), Number64.ToDouble(rightAsNumber.Value));

            return(CosmosNumber64.Create(result));
        }
        public async Task DCount()
        {
            List <CosmosObject> documents = new List <CosmosObject>();

            for (int i = 0; i < 250; i++)
            {
                documents.Add(CosmosObject.Parse($"{{\"pk\" : {i}, \"val\": {i % 49} }}"));
            }

            List <CosmosElement> documentsQueried = await ExecuteQueryAsync(
                query : "SELECT VALUE COUNT(1) FROM (SELECT DISTINCT VALUE c.val FROM c)",
                documents : documents);

            Assert.AreEqual(expected: 1, actual: documentsQueried.Count);
            Assert.IsTrue(documentsQueried[0] is CosmosNumber);
            CosmosNumber result = documentsQueried[0] as CosmosNumber;

            Assert.AreEqual(expected: 49, actual: Number64.ToLong(result.Value));
        }
        public static SqlNumberLiteral Create(Number64 number64)
        {
            SqlNumberLiteral sqlNumberLiteral;

            if (number64.IsDouble)
            {
                if (!SqlNumberLiteral.FrequentDoubles.TryGetValue(Number64.ToDouble(number64), out sqlNumberLiteral))
                {
                    sqlNumberLiteral = new SqlNumberLiteral(number64);
                }
            }
            else
            {
                if (!SqlNumberLiteral.FrequentLongs.TryGetValue(Number64.ToLong(number64), out sqlNumberLiteral))
                {
                    sqlNumberLiteral = new SqlNumberLiteral(number64);
                }
            }

            return(sqlNumberLiteral);
        }
        public override SqlObject VisitLiteral([NotNull] sqlParser.LiteralContext context)
        {
            TerminalNodeImpl terminalNode = (TerminalNodeImpl)context.children[0];

            SqlLiteral sqlLiteral;

            switch (terminalNode.Symbol.Type)
            {
            case sqlParser.STRING_LITERAL:
                string value = CstToAstVisitor.GetStringValueFromNode(terminalNode);
                sqlLiteral = SqlStringLiteral.Create(value);
                break;

            case sqlParser.NUMERIC_LITERAL:
                Number64 number64 = CstToAstVisitor.GetNumber64ValueFromNode(terminalNode);
                sqlLiteral = SqlNumberLiteral.Create(number64);
                break;

            case sqlParser.K_TRUE:
                sqlLiteral = SqlBooleanLiteral.Create(true);
                break;

            case sqlParser.K_FALSE:
                sqlLiteral = SqlBooleanLiteral.Create(false);
                break;

            case sqlParser.K_NULL:
                sqlLiteral = SqlNullLiteral.Create();
                break;

            case sqlParser.K_UNDEFINED:
                sqlLiteral = SqlUndefinedLiteral.Create();
                break;

            default:
                throw new ArgumentOutOfRangeException($"Unknown symbol type: {terminalNode.Symbol.Type}");
            }

            return(sqlLiteral);
        }
            /// <summary>
            /// Initializes a new instance of the AverageInfo class.
            /// </summary>
            public static TryCatch <AverageInfo> TryCreateFromCosmosElement(CosmosElement cosmosElement)
            {
                if (cosmosElement == null)
                {
                    throw new ArgumentNullException($"{nameof(cosmosElement)} must not be null.");
                }

                if (!(cosmosElement is CosmosObject cosmosObject))
                {
                    return(TryCatch <AverageInfo> .FromException(
                               new ArgumentException($"{nameof(cosmosElement)} must be an object.")));
                }

                double?sum;

                if (cosmosObject.TryGetValue(SumName, out CosmosElement sumPropertyValue))
                {
                    if (!(sumPropertyValue is CosmosNumber cosmosSum))
                    {
                        return(TryCatch <AverageInfo> .FromException(
                                   new ArgumentException($"value for the {SumName} field was not a number")));
                    }

                    sum = Number64.ToDouble(cosmosSum.Value);
                }
                else
                {
                    sum = null;
                }

                if (!cosmosObject.TryGetValue(CountName, out CosmosNumber cosmosCount))
                {
                    return(TryCatch <AverageInfo> .FromException(
                               new ArgumentException($"value for the {CountName} field was not a number")));
                }

                long count = Number64.ToLong(cosmosCount.Value);

                return(TryCatch <AverageInfo> .FromResult(new AverageInfo(sum, count)));
            }
Beispiel #21
0
        public override Output ExecuteTest(Input input)
        {
            CosmosElement value = input.PartitionKeyValue;

            PartitionKeyHash partitionKeyHashV1;
            PartitionKeyHash partitionKeyHashV2;

            switch (value)
            {
            case null:
                partitionKeyHashV1 = PartitionKeyHash.V1.HashUndefined();
                partitionKeyHashV2 = PartitionKeyHash.V2.HashUndefined();
                break;

            case CosmosNull cosmosNull:
                partitionKeyHashV1 = PartitionKeyHash.V1.HashNull();
                partitionKeyHashV2 = PartitionKeyHash.V2.HashNull();
                break;

            case CosmosBoolean cosmosBoolean:
                partitionKeyHashV1 = PartitionKeyHash.V1.Hash(cosmosBoolean.Value);
                partitionKeyHashV2 = PartitionKeyHash.V2.Hash(cosmosBoolean.Value);
                break;

            case CosmosString cosmosString:
                partitionKeyHashV1 = PartitionKeyHash.V1.Hash(cosmosString.Value);
                partitionKeyHashV2 = PartitionKeyHash.V2.Hash(cosmosString.Value);
                break;

            case CosmosNumber cosmosNumber:
                partitionKeyHashV1 = PartitionKeyHash.V1.Hash(Number64.ToDouble(cosmosNumber.Value));
                partitionKeyHashV2 = PartitionKeyHash.V2.Hash(Number64.ToDouble(cosmosNumber.Value));
                break;

            default:
                throw new ArgumentOutOfRangeException($"Unknown {nameof(CosmosElement)} type: {value.GetType()}.");
            }

            return(new Output(partitionKeyHashV1, partitionKeyHashV2));
        }
        public static TryCatch <IAggregator> TryCreate(CosmosElement requestContinuationToken)
        {
            double partialSum;

            if (requestContinuationToken != null)
            {
                if (!(requestContinuationToken is CosmosNumber cosmosNumber))
                {
                    return(TryCatch <IAggregator> .FromException(
                               new MalformedContinuationTokenException($"Malformed {nameof(SumAggregator)} continuation token: {requestContinuationToken}")));
                }

                partialSum = Number64.ToDouble(cosmosNumber.Value);
            }
            else
            {
                partialSum = 0.0;
            }

            return(TryCatch <IAggregator> .FromResult(
                       new SumAggregator(partialSum)));
        }
Beispiel #23
0
        /// <summary>
        /// Adds a local sum to the global sum.
        /// </summary>
        /// <param name="localSum">The local sum.</param>
        public void Aggregate(CosmosElement localSum)
        {
            if (double.IsNaN(this.globalSum))
            {
                // Global sum is undefined and nothing is going to change that.
                return;
            }

            // If someone tried to add an undefined just set the globalSum to NaN and it will stay that way for the duration of the aggregation.
            if (localSum == null)
            {
                this.globalSum = double.NaN;
                return;
            }

            if (!(localSum is CosmosNumber cosmosNumber))
            {
                throw new ArgumentException("localSum must be a number.");
            }

            this.globalSum += Number64.ToDouble(cosmosNumber.Value);
        }
Beispiel #24
0
        public static TryCatch <IAggregator> TryCreate(CosmosElement continuationToken)
        {
            long partialCount;

            if (continuationToken != null)
            {
                if (!(continuationToken is CosmosNumber cosmosPartialCount))
                {
                    return(TryCatch <IAggregator> .FromException(
                               new MalformedContinuationTokenException($@"Invalid count continuation token: ""{continuationToken}"".")));
                }

                partialCount = Number64.ToLong(cosmosPartialCount.Value);
            }
            else
            {
                partialCount = 0;
            }

            return(TryCatch <IAggregator> .FromResult(
                       new CountAggregator(initialCount : partialCount)));
        }
        public override SqlObject VisitTop_spec([NotNull] sqlParser.Top_specContext context)
        {
            Contract.Requires(context != null);

            SqlTopSpec sqlTopSpec;

            if (context.NUMERIC_LITERAL() != null)
            {
                Number64 topCount = CstToAstVisitor.GetNumber64ValueFromNode(context.NUMERIC_LITERAL());
                sqlTopSpec = SqlTopSpec.Create(SqlNumberLiteral.Create(topCount));
            }
            else if (context.PARAMETER() != null)
            {
                sqlTopSpec = SqlTopSpec.Create(SqlParameter.Create(context.PARAMETER().GetText()));
            }
            else
            {
                throw new InvalidOperationException();
            }

            return(sqlTopSpec);
        }
Beispiel #26
0
        public static TryCatch <IAggregator> TryCreate(CosmosElement requestContinuationToken)
        {
            double partialSum;

            if (requestContinuationToken != null)
            {
                if (requestContinuationToken is CosmosNumber cosmosNumber)
                {
                    partialSum = Number64.ToDouble(cosmosNumber.Value);
                }
                else if (requestContinuationToken is CosmosString cosmosString)
                {
                    if (!double.TryParse(
                            cosmosString.Value,
                            NumberStyles.Float | NumberStyles.AllowThousands,
                            CultureInfo.InvariantCulture,
                            out partialSum))
                    {
                        return(TryCatch <IAggregator> .FromException(
                                   new MalformedContinuationTokenException(
                                       $"Malformed {nameof(SumAggregator)} continuation token: {requestContinuationToken}")));
                    }
                }
                else
                {
                    return(TryCatch <IAggregator> .FromException(
                               new MalformedContinuationTokenException(
                                   $"Malformed {nameof(SumAggregator)} continuation token: {requestContinuationToken}")));
                }
            }
            else
            {
                partialSum = 0.0;
            }

            return(TryCatch <IAggregator> .FromResult(
                       new SumAggregator(partialSum)));
        }
        public override void Visit(SqlNumberLiteral sqlNumberLiteral)
        {
            // We have to use InvariantCulture due to number formatting.
            // "1234.1234" is correct while "1234,1234" is incorrect.
            if (sqlNumberLiteral.Value.IsDouble)
            {
                string literalString = sqlNumberLiteral.Value.ToString(CultureInfo.InvariantCulture);
                double literalValue  = 0.0;
                if (!sqlNumberLiteral.Value.IsNaN &&
                    !sqlNumberLiteral.Value.IsInfinity &&
                    (!double.TryParse(literalString, NumberStyles.Number, CultureInfo.InvariantCulture, out literalValue) ||
                     !Number64.ToDouble(sqlNumberLiteral.Value).Equals(literalValue)))
                {
                    literalString = sqlNumberLiteral.Value.ToString("G17", CultureInfo.InvariantCulture);
                }

                this.writer.Write(literalString);
            }
            else
            {
                this.writer.Write(sqlNumberLiteral.Value.ToString(CultureInfo.InvariantCulture));
            }
        }
Beispiel #28
0
        private static IEnumerable <CosmosElement> ExecuteSelectClause(
            IEnumerable <IGrouping <GroupByKey, CosmosElement> > groupings,
            SqlSelectClause sqlSelectClause)
        {
            IEnumerable <CosmosElement> dataSource = ProjectOnGroupings(
                groupings,
                sqlSelectClause);

            if (sqlSelectClause.HasDistinct)
            {
                dataSource = dataSource.Distinct();
            }

            if (sqlSelectClause.TopSpec != null)
            {
                CosmosNumber cosmosTopValue = (CosmosNumber)sqlSelectClause.TopSpec.TopExpresion.Accept(
                    ScalarExpressionEvaluator.Singleton,
                    input: null);
                long topCount = Number64.ToLong(cosmosTopValue.Value);
                dataSource = dataSource.Take((int)topCount);
            }

            return(dataSource);
        }
        public async Task Aggregates()
        {
            const int           DocumentCount = 250;
            List <CosmosObject> documents     = new List <CosmosObject>();

            for (int i = 0; i < DocumentCount; i++)
            {
                documents.Add(CosmosObject.Parse($"{{\"pk\" : {i} }}"));
            }

            List <CosmosElement> documentsQueried = await ExecuteQueryAsync(
                query : "SELECT VALUE COUNT(1) FROM c",
                documents : documents);

            Assert.AreEqual(expected: 1, actual: documentsQueried.Count);
            if (documentsQueried[0] is CosmosNumber number)
            {
                Assert.AreEqual(expected: DocumentCount, actual: Number64.ToLong(number.Value));
            }
            else
            {
                Assert.Fail();
            }
        }
Beispiel #30
0
        public async Task TestAggregateFunctionsAsync()
        {
            AggregateTestArgs args = new AggregateTestArgs()
            {
                NumberOfDocsWithSamePartitionKey       = 37,
                NumberOfDocumentsDifferentPartitionKey = 43,
                PartitionKey       = "key",
                UniquePartitionKey = "uniquePartitionKey",
                Field  = "field",
                Values = new object[] { false, true, "abc", "cdfg", "opqrs", "ttttttt", "xyz" },
            };

            List <string> documents = new List <string>(args.NumberOfDocumentsDifferentPartitionKey + args.NumberOfDocsWithSamePartitionKey);

            foreach (object val in args.Values)
            {
                Document doc;
                doc = new Document();
                doc.SetPropertyValue(args.PartitionKey, val);
                doc.SetPropertyValue("id", Guid.NewGuid().ToString());

                documents.Add(doc.ToString());
            }

            for (int i = 0; i < args.NumberOfDocsWithSamePartitionKey; ++i)
            {
                Document doc = new Document();
                doc.SetPropertyValue(args.PartitionKey, args.UniquePartitionKey);
                documents.Add(doc.ToString());
            }

            Random random = new Random();

            for (int i = 0; i < args.NumberOfDocumentsDifferentPartitionKey; ++i)
            {
                Document doc = new Document();
                doc.SetPropertyValue(args.PartitionKey, random.NextDouble());
                documents.Add(doc.ToString());
            }

            await this.CreateIngestQueryDeleteAsync <AggregateTestArgs>(
                ConnectionModes.Direct | ConnectionModes.Gateway,
                CollectionTypes.SinglePartition | CollectionTypes.MultiPartition,
                documents,
                ImplementationAsync,
                args,
                "/" + args.PartitionKey);

            async Task ImplementationAsync(
                Container container,
                IReadOnlyList <CosmosObject> inputDocuments,
                AggregateTestArgs aggregateTestArgs)
            {
                IReadOnlyList <CosmosObject> documentsWherePkIsANumber = inputDocuments
                                                                         .Where(doc =>
                {
                    return(double.TryParse(
                               doc[aggregateTestArgs.PartitionKey].ToString(),
                               out double result));
                })
                                                                         .ToList();
                double numberSum = documentsWherePkIsANumber
                                   .Sum(doc =>
                {
                    if (!doc.TryGetValue(aggregateTestArgs.PartitionKey, out CosmosNumber number))
                    {
                        Assert.Fail("Failed to get partition key from document");
                    }

                    return(Number64.ToDouble(number.Value));
                });
                double count = documentsWherePkIsANumber.Count();

                AggregateQueryArguments[] aggregateQueryArgumentsList = new AggregateQueryArguments[]
                {
                    new AggregateQueryArguments()
                    {
                        AggregateOperator = "AVG",
                        ExpectedValue     = CosmosNumber64.Create(numberSum / count),
                        Predicate         = $"IS_NUMBER(r.{aggregateTestArgs.PartitionKey})",
                    },
                    new AggregateQueryArguments()
                    {
                        AggregateOperator = "AVG",
                        ExpectedValue     = null,
                        Predicate         = "true",
                    },
                    new AggregateQueryArguments()
                    {
                        AggregateOperator = "COUNT",
                        ExpectedValue     = CosmosNumber64.Create(documents.Count()),
                        Predicate         = "true",
                    },
                    new AggregateQueryArguments()
                    {
                        AggregateOperator = "MAX",
                        ExpectedValue     = CosmosString.Create("xyz"),
                        Predicate         = "true",
                    },
                    new AggregateQueryArguments()
                    {
                        AggregateOperator = "MIN",
                        ExpectedValue     = CosmosBoolean.Create(false),
                        Predicate         = "true",
                    },
                    new AggregateQueryArguments()
                    {
                        AggregateOperator = "SUM",
                        ExpectedValue     = CosmosNumber64.Create(numberSum),
                        Predicate         = $"IS_NUMBER(r.{aggregateTestArgs.PartitionKey})",
                    },
                    new AggregateQueryArguments()
                    {
                        AggregateOperator = "SUM",
                        ExpectedValue     = null,
                        Predicate         = $"true",
                    },
                };

                foreach (int maxDoP in new[] { 0, 10 })
                {
                    foreach (AggregateQueryArguments argument in aggregateQueryArgumentsList)
                    {
                        string[] queryFormats = new[]
                        {
                            "SELECT VALUE {0}(r.{1}) FROM r WHERE {2}",
                            "SELECT VALUE {0}(r.{1}) FROM r WHERE {2} ORDER BY r.{1}"
                        };

                        foreach (string queryFormat in queryFormats)
                        {
                            string query = string.Format(
                                CultureInfo.InvariantCulture,
                                queryFormat,
                                argument.AggregateOperator,
                                aggregateTestArgs.PartitionKey,
                                argument.Predicate);
                            string message = string.Format(
                                CultureInfo.InvariantCulture,
                                "query: {0}, data: {1}",
                                query,
                                JsonConvert.SerializeObject(argument));

                            List <CosmosElement> items = await QueryTestsBase.RunQueryAsync(
                                container,
                                query,
                                new QueryRequestOptions()
                            {
                                MaxConcurrency = maxDoP,
                            });

                            if (argument.ExpectedValue == null)
                            {
                                Assert.AreEqual(0, items.Count, message);
                            }
                            else
                            {
                                Assert.AreEqual(1, items.Count, message);
                                CosmosElement expected = argument.ExpectedValue;
                                CosmosElement actual   = items.Single();

                                if ((expected is CosmosNumber expectedNumber) && (actual is CosmosNumber actualNumber))
                                {
                                    Assert.AreEqual(Number64.ToDouble(expectedNumber.Value), Number64.ToDouble(actualNumber.Value), .01);
                                }