示例#1
0
        private List <IndexData> ParseIndexesAndGetReadyToMerge()
        {
            var indexes = new List <IndexData>();

            foreach (var kvp in _indexDefinitions)
            {
                var index     = kvp.Value;
                var indexData = new IndexData(index)
                {
                    IndexName    = index.Name,
                    OriginalMaps = index.Maps
                };

                indexes.Add(indexData);

                if (index.Type == IndexType.MapReduce || index.Maps.Count > 1)
                {
                    indexData.IsMapReduceOrMultiMap = true;
                    continue;
                }

                var visitor = new IndexVisitor(indexData);
                var map     = SyntaxFactory.ParseExpression(indexData.OriginalMaps.FirstOrDefault()).NormalizeWhitespace();
                map.Accept(visitor);
            }

            return(indexes);
        }
示例#2
0
        private bool CanMergeIndexes(IndexData other, IndexData current)
        {
            if (current.IndexName == other.IndexName)
            {
                return(false);
            }

            if (current.NumberOfFromClauses > 1)
            {
                return(false);
            }

            if (current.NumberOfSelectClauses > 1)
            {
                return(false);
            }

            if (current.HasWhere)
            {
                return(false);
            }

            if (current.HasGroup)
            {
                return(false);
            }
            if (current.HasOrder)
            {
                return(false);
            }
            if (current.HasLet)
            {
                return(false);
            }

            var currentFromExpression = current.FromExpression as MemberAccessExpressionSyntax;
            var otherFromExpression   = other.FromExpression as MemberAccessExpressionSyntax;

            if (currentFromExpression != null || otherFromExpression != null)
            {
                if (currentFromExpression == null || otherFromExpression == null)
                {
                    return(false);
                }

                if (currentFromExpression.Name.Identifier.ValueText != otherFromExpression.Name.Identifier.ValueText)
                {
                    return(false);
                }
            }

            return(CompareIndexFieldOptions(other, current));
        }
示例#3
0
 private static bool AreSelectClausesCompatible(IndexData x, IndexData y)
 {
     foreach (var pair in x.SelectExpressions)
     {
         if (y.SelectExpressions.TryGetValue(pair.Key, out ExpressionSyntax expressionValue) == false)
         {
             continue;
         }
         // for the same key, they have to be the same
         var ySelectExpr = ExtractValueFromExpression(expressionValue);
         var xSelectExpr = ExtractValueFromExpression(pair.Value);
         if (xSelectExpr != ySelectExpr)
         {
             return(false);
         }
     }
     return(true);
 }
示例#4
0
        private static List <string> CheckForUnsuitableIndexForMerging(IndexData indexData)
        {
            var failComments = new List <string>();

            if (indexData.Index.Type == IndexType.MapReduce)
            {
                failComments.Add("Cannot merge map/reduce indexes");
            }
            if (indexData.Index.Maps.Count > 1)
            {
                failComments.Add("Cannot merge multi map indexes");
            }

            if (indexData.NumberOfFromClauses > 1)
            {
                failComments.Add("Cannot merge indexes that have more than a single from clause");
            }
            if (indexData.NumberOfSelectClauses > 1)
            {
                failComments.Add("Cannot merge indexes that have more than a single select clause");
            }
            if (indexData.HasWhere)
            {
                failComments.Add("Cannot merge indexes that have a where clause");
            }
            if (indexData.HasGroup)
            {
                failComments.Add("Cannot merge indexes that have a group by clause");
            }
            if (indexData.HasLet)
            {
                failComments.Add("Cannot merge indexes that are using a let clause");
            }
            if (indexData.HasOrder)
            {
                failComments.Add("Cannot merge indexes that have an order by clause");
            }
            return(failComments);
        }
示例#5
0
        private static bool AreSelectClausesTheSame(IndexData index, Dictionary <string, ExpressionSyntax> selectExpressionDict)
        {
            if (index.SelectExpressions.Count != selectExpressionDict.Count)
            {
                return(false);
            }

            foreach (var pair in index.SelectExpressions)
            {
                if (selectExpressionDict.TryGetValue(pair.Key, out ExpressionSyntax expressionValue) == false)
                {
                    return(false);
                }

                // for the same key, they have to be the same
                var ySelectExpr = ExtractValueFromExpression(expressionValue);
                var xSelectExpr = ExtractValueFromExpression(pair.Value);
                if (xSelectExpr != ySelectExpr)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#6
0
 public IndexVisitor(IndexData indexData)
 {
     _indexData = indexData;
     indexData.NumberOfFromClauses = 0;
     indexData.SelectExpressions   = new Dictionary <string, ExpressionSyntax>();
 }
示例#7
0
        private bool CompareIndexFieldOptions(IndexData index1Data, IndexData index2Data)
        {
            var intersectNames = index2Data.SelectExpressions.Keys.Intersect(index1Data.SelectExpressions.Keys).ToArray();

            return(DataDictionaryCompare(index1Data.Index.Fields, index2Data.Index.Fields, intersectNames));
        }