Exemplo n.º 1
0
        public override string ToString()
        {
            var result = "";
            var query  = _query;

            foreach (var queryUsed in _queriesUsed)
            {
                if (!queryUsed.Value)
                {
                    continue;
                }

                var extrQuery  = _queries[queryUsed.Key];
                var whereParts = extrQuery
                                 .Where(part => part.StartsWith("where") && (part.Contains("==") || part.Contains("!=") || part.Contains("contains")))
                                 .ToList();

                var inString   = "in";
                var invertPart = whereParts.All(part => part.Contains("!=") || part.Contains("!contains")) && whereParts.Count > 0;

                // We invert the query to avoid hiding un-correlated items like non failed requests.
                if (invertPart)
                {
                    inString  = "!in";
                    extrQuery = new StructuredQuery(extrQuery);
                    var tmpWhere = new List <string>();

                    for (var i = 0; i < extrQuery.Count; i++)
                    {
                        var part = extrQuery[i];

                        if (part.StartsWith("where") && (part.Contains("==") || part.Contains("!=") || part.Contains("!contains")))
                        {
                            tmpWhere.Add(
                                part
                                .Replace("where", "")
                                .Replace("!=", "==")
                                .Replace("!contains", "contains")
                                .Trim());

                            extrQuery.RemoveAt(i);
                            i--;
                        }
                    }

                    extrQuery = QueryBuilder.AddWherePart(extrQuery, $"where {string.Join(" or ", tmpWhere)}");
                }

                var tmpQuery = QueryBuilder.Append(extrQuery, QueryBuilder.Parse("| distinct operation_Id"));
                result += $"let {queryUsed.Key}OperationIds = {QueryBuilder.ToQueryString(tmpQuery)};\r\n";
                query   = QueryBuilder.AddWherePart(query, $"where (operation_Id {inString} ({queryUsed.Key}OperationIds))");
            }

            result += QueryBuilder.ToQueryString(query);
            result  = Regex.Replace(result, "[ ]+", " ");
            return(result);
        }
Exemplo n.º 2
0
        public QueryGroup(StructuredQuery query)
        {
            _query       = query;
            _queries     = new Dictionary <string, StructuredQuery>();
            _queriesUsed = new Dictionary <string, bool>();

            foreach (var type in new[] { "requests", "exceptions", "availabilityResults" })
            {
                _queries.Add(type, QueryBuilder.Parse($" {type} | {_query.First(q => q.Contains("timestamp >"))}"));
                _queriesUsed.Add(type, false);
            }
        }
Exemplo n.º 3
0
        public static StructuredQuery AddWherePart(StructuredQuery structuredQuery, string part)
        {
            var firstWhereIndex = 0;

            for (var i = 0; i < structuredQuery.Count; i++)
            {
                if (structuredQuery[i].StartsWith("where ", StringComparison.OrdinalIgnoreCase))
                {
                    firstWhereIndex = i;
                    break;
                }
            }

            var result = new StructuredQuery(structuredQuery);

            result.Insert(firstWhereIndex, part);
            return(result);
        }
Exemplo n.º 4
0
 public static StructuredQuery Append(StructuredQuery structuredQuery, StructuredQuery parts)
 {
     return(new StructuredQuery(structuredQuery.Concat(parts)));
 }
Exemplo n.º 5
0
 public static string ToQueryString(StructuredQuery structuredQuery)
 {
     return(string.Join("\r\n| ", structuredQuery));
 }
Exemplo n.º 6
0
 public static StructuredQuery RemoveProject(StructuredQuery structuredQuery)
 {
     return(new StructuredQuery(structuredQuery.Where(part => !part.StartsWith("project ", StringComparison.OrdinalIgnoreCase))));
 }
Exemplo n.º 7
0
 public void RemoveProjectAndSummarize()
 {
     _query = QueryBuilder.RemoveProject(_query);
     _query = QueryBuilder.RemoveSummarize(_query);
 }
Exemplo n.º 8
0
 public void Append(StructuredQuery query)
 {
     _query = QueryBuilder.Append(_query, query);
 }
Exemplo n.º 9
0
 public void AddWhere(string part)
 {
     _query = QueryBuilder.AddWherePart(_query, part);
 }
Exemplo n.º 10
0
 public void Replace(string type, StructuredQuery query)
 {
     _queries[type]     = query;
     _queriesUsed[type] = true;
 }