Exemple #1
0
        private DistinctQuery BuildDistinctFromContext(IRequestContext ctx, NameValueCollection p)
        {
            DistinctQueryTop query = new DistinctQueryTop();

            query.Column = p["col"];
            if (String.IsNullOrEmpty(query.Column))
            {
                throw new ArgumentException("Distinct Column [col] must be passed.");
            }

            string queryString = p["q"];

            using (ctx.Monitor(MonitorEventLevel.Verbose, "Arriba.ParseQuery", String.IsNullOrEmpty(queryString) ? "<none>" : queryString))
            {
                query.Where = String.IsNullOrEmpty(queryString) ? new AllExpression() : SelectQuery.ParseWhere(queryString);
            }

            string take = p["t"];

            if (!String.IsNullOrEmpty(take))
            {
                query.Count = UInt16.Parse(take);
            }

            return(query);
        }
        private async static Task <DistinctQuery> BuildDistinctFromContext(IRequestContext ctx)
        {
            if (ctx.Request.Method == RequestVerb.Post && ctx.Request.HasBody)
            {
                return(await ctx.Request.ReadBodyAsync <DistinctQuery>());
            }

            DistinctQueryTop query = new DistinctQueryTop();

            query.Column = ctx.Request.ResourceParameters["col"];
            if (String.IsNullOrEmpty(query.Column))
            {
                throw new ArgumentException("Distinct Column [col] must be passed.");
            }

            string queryString = ctx.Request.ResourceParameters["q"];

            using (ctx.Monitor(MonitorEventLevel.Verbose, "Arriba.ParseQuery", String.IsNullOrEmpty(queryString) ? "<none>" : queryString))
            {
                query.Where = String.IsNullOrEmpty(queryString) ? new AllExpression() : SelectQuery.ParseWhere(queryString);
            }

            string take = ctx.Request.ResourceParameters["t"];

            if (!String.IsNullOrEmpty(take))
            {
                query.Count = UInt16.Parse(take);
            }

            return(query);
        }
Exemple #3
0
        public void ITable_DistinctTop(Func <ITable> factoryMethod)
        {
            // Define columns and add sample data
            ITable table = factoryMethod();

            AddSampleData(table);

            // Get Distinct Priority for all bugs, verify three (3, 0, 1)
            DistinctQueryTop query  = new DistinctQueryTop("Priority", "", 5);
            DistinctResult   result = table.Query(query);

            // Verify "3" is first, it's in 3 items, all values are returned, three distinct were returned
            Assert.AreEqual("3", result.Values[0, 0].ToString());
            Assert.AreEqual("3", result.Values[0, 1].ToString());
            Assert.AreEqual(3, result.Values.RowCount);
            Assert.AreEqual(5, result.Total);
            Assert.IsTrue(result.AllValuesReturned);

            // Verify distinct priority where priority is not 1 has only two values
            query.Where = QueryParser.Parse("Priority != 1");
            result      = table.Query(query);

            Assert.AreEqual("3, 0", result.Values.GetColumn(0).Join(", "));
            Assert.AreEqual(2, result.Values.RowCount);
            Assert.AreEqual(4, result.Total);
            Assert.IsTrue(result.AllValuesReturned);

            // Verify the result converts to a dimension properly
            AggregationDimension dimension = result.ToAggregationDimension();

            Assert.AreEqual("Query [[Priority] = 3,[Priority] = 0]", dimension.ToString());

            // Verify if we only ask for one value, query reports more values left
            query.Count = 1;
            result      = table.Query(query);
            Assert.AreEqual("3", result.Values[0, 0].ToString());
            Assert.AreEqual(1, result.Values.RowCount);
            Assert.IsFalse(result.AllValuesReturned);
        }