public void RepeatedNodeAllocationWithSplit() { var subject = new MetadataIndex(); var path = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), new NodePathLevel("Level3", null) }); var result1 = subject.AllocateNode(path); var path2 = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null) }); var result = subject.AllocateNode(path2); result.PathLevels.Count.Should().Be(2); result.PathLevels[0].Should().Be(path.Levels[0]); result.PathLevels[1].Should().Be(path.Levels[1]); result.Parent.Should().BeNull(); result.Children.Count.Should().Be(1); result.Children[path.Levels[2]].PathLevels.Count.Should().Be(1); result.Children[path.Levels[2]].PathLevels[0].Should().Be(path.Levels[2]); result.Children[path.Levels[2]].Children.Count.Should().Be(0); }
public void RepeatedNodeAllocationWithBranch() { var subject = new MetadataIndex(); var path = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), }); var result1 = subject.AllocateNode(path); var path2 = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level3", null), }); var result = subject.AllocateNode(path2); result.PathLevels.Count.Should().Be(1); result.PathLevels[0].Should().Be(path2.Levels[1]); result.Parent.Should().NotBeNull(); var l1 = result.Parent; l1.Children.Count.Should().Be(2); l1.PathLevels.Count.Should().Be(1); l1.PathLevels[0].Should().Be(path.Levels[0]); l1.Children.ContainsKey(path.Levels[1]).Should().BeTrue(); l1.Children[path.Levels[1]].PathLevels.Count.Should().Be(1); l1.Children[path.Levels[1]].PathLevels[0].Should().Be(path.Levels[1]); }
public void GetExactNodeSecondNode() { var subject = new MetadataIndex(); var path = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), }); var result1 = subject.AllocateNode(path); var path2 = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), new NodePathLevel("Level3", null), new NodePathLevel("Level4", null), }); var result2 = subject.AllocateNode(path2); var result = subject.GetExactNode(path2, true); result.Should().Be(result2); }
public void AddMetadataIndex(string collection, MetadataIndex metadataIndex) { lock (_metadataIndices) { _metadataIndices.Add(collection, metadataIndex); } }
internal static bool IsCompatibleWithPlatform(MetadataReader mr, MetadataIndex index, Platform?platform, CustomAttributeHandleCollection customAttributesOnMember) { if (index.SupportedArchitectureAttributeCtor == default) { // This metadata never uses the SupportedArchitectureAttribute, so we assume this member is compatible. return(true); } foreach (CustomAttributeHandle attHandle in customAttributesOnMember) { CustomAttribute att = mr.GetCustomAttribute(attHandle); if (att.Constructor.Equals(index.SupportedArchitectureAttributeCtor)) { if (platform is null) { // Without a compilation, we cannot ascertain compatibility. return(false); } var requiredPlatform = (InteropArchitecture)(int)att.DecodeValue(CustomAttributeTypeProvider.Instance).FixedArguments[0].Value !; return(platform switch { Platform.AnyCpu or Platform.AnyCpu32BitPreferred => requiredPlatform == InteropArchitecture.All, Platform.Arm64 => (requiredPlatform & InteropArchitecture.Arm64) == InteropArchitecture.Arm64, Platform.X86 => (requiredPlatform & InteropArchitecture.X86) == InteropArchitecture.X86, Platform.X64 => (requiredPlatform & InteropArchitecture.X64) == InteropArchitecture.X64, _ => false, });
public BucketKeysFilterEnumerator(int bucketId, MetadataIndex metadataIndex, IDistribution distribution) { if (metadataIndex == null) { throw new Exception("Metadata Index can not be null"); } this.bucketId = bucketId; this.metadataIndex = metadataIndex; this.rowIDsEnumerator = metadataIndex.GetEnumerator(); this.distribution = distribution; if (LoggerManager.Instance.StateXferLogger.IsDebugEnabled) { LoggerManager.Instance.StateXferLogger.Debug("StateXfer", "BucketKeysFilterEnumerator created for BucketId: " + bucketId); } }
public void RepeatedNodeAllocationWithExtensionOverTwoNodes() { var subject = new MetadataIndex(); var path = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null) }); var result1 = subject.AllocateNode(path); var path2 = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), new NodePathLevel("Level3", null), new NodePathLevel("Level4", null) }); var result2 = subject.AllocateNode(path2); var path3 = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), new NodePathLevel("Level3", null), new NodePathLevel("Level4", null), new NodePathLevel("Level5", null), new NodePathLevel("Level6", null) }); var result = subject.AllocateNode(path3); result.PathLevels.Count.Should().Be(2); result.PathLevels[0].Should().Be(path3.Levels[4]); result.PathLevels[1].Should().Be(path3.Levels[5]); result.Parent.Should().NotBeNull(); result.Parent.PathLevels.Count.Should().Be(2); result.Parent.PathLevels[0].Should().Be(path3.Levels[2]); result.Parent.PathLevels[1].Should().Be(path3.Levels[3]); result.Parent.Parent.Should().NotBeNull(); result.Parent.Parent.PathLevels.Count.Should().Be(2); result.Parent.Parent.PathLevels[0].Should().Be(path3.Levels[0]); result.Parent.Parent.PathLevels[1].Should().Be(path3.Levels[1]); }
public void SimpleNodeAllocation() { var subject = new MetadataIndex(); var path = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), }); var result = subject.AllocateNode(path); result.Should().NotBeNull(); result.Parent.Should().BeNull(); result.Children.Count.Should().Be(0); result.RootIndex.Should().Be(subject); result.PathLevels.Count.Should().Be(2); result.PathLevels[0].Should().Be(path.Levels[0]); result.PathLevels[1].Should().Be(path.Levels[1]); }
public void GetExactNodeParent(bool orParent, bool resultShouldBeNull) { var subject = new MetadataIndex(); var path = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), }); var result1 = subject.AllocateNode(path); var path2 = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), new NodePathLevel("Level3", null), new NodePathLevel("Level4", null), }); var result2 = subject.AllocateNode(path2); var path3 = new NodePath("Lang1", new NodePathLevel[] { new NodePathLevel("Level1", null), new NodePathLevel("Level2", null), new NodePathLevel("Level3", null), }); var result = subject.GetExactNode(path3, orParent); if (!resultShouldBeNull) { result.Should().Be(result1); } else { result.Should().BeNull(); } }
public QueryPlan GetQueryPlan(IDmObject parsedQuery, IQuery query, IQueryStore queryStore, MetadataIndex rowsEnumerator) { //Todo: Plan's cache's key decision (query-string based plan cache/optimizable-section based cache). OrderedList <double, IProxyPredicate> sortedPlans = new OrderedList <double, IProxyPredicate>(); var optimizableQuery = parsedQuery as IFilterObject; var criteria = AddQueryCriteria(parsedQuery, query.Parameters, queryStore); var queryPlan = new QueryPlan { Criteria = criteria }; if (optimizableQuery != null && optimizableQuery.WherePredicate != null) { ITreePredicate whereExpression = optimizableQuery.WherePredicate; ITreePredicate contractedExpression = whereExpression.Contract(); if (contractedExpression == null) { contractedExpression = whereExpression; } List <ITreePredicate> distribCombinations = new List <ITreePredicate>(); distribCombinations.Add(contractedExpression); //Todo: Restrict this call if there doesn't exist a compound index. while (contractedExpression.Expand() != null) { distribCombinations.Add(contractedExpression.Expand()); contractedExpression = contractedExpression.Expand(); } foreach (var treePredicate in distribCombinations) { if (treePredicate is OrTreePredicate || treePredicate is AndTreePredicate) { break; } if (treePredicate is ComparisonPredicate) { DocumentKey documentKey = null; if (((ComparisonPredicate)treePredicate).TryGetProxyKeyPredicate(rowsEnumerator, out documentKey)) { IProxyPredicate optimizablePredicate = new ProxyPredicate(new KeyPredicate(documentKey, rowsEnumerator), treePredicate); sortedPlans.Add(optimizablePredicate.Statistics[Statistic.ExpectedIO], optimizablePredicate); queryPlan.Predicate = sortedPlans.FirstValues[0].GetExecutionPredicate(queryStore); return(queryPlan); } } } foreach (var expressionState in distribCombinations) { IProxyPredicate optimizablePredicate = expressionState.GetProxyExecutionPredicate(_indexManager, queryStore, rowsEnumerator); sortedPlans.Add(optimizablePredicate.Statistics[Statistic.ExpectedIO], optimizablePredicate); //Todo: Add optimizedPredicate to the SortedList by the cost. } queryPlan.Predicate = sortedPlans.FirstValues[0].GetExecutionPredicate(queryStore); } else { if (criteria.GroupFields != null && criteria.GroupFields.Count == 1 && criteria.GroupFields[0] is AllField && criteria.ContainsAggregations) { if (criteria.Aggregations.Count == 1 && criteria.Aggregations[0].Aggregation is COUNT && criteria.Aggregations[0].Evaluation is AllEvaluable) { queryPlan.Criteria.GroupByField = null; queryPlan.Predicate = new SpecialCountPredicate(rowsEnumerator.KeyCount); queryPlan.IsSpecialExecution = true; return(queryPlan); } } //Todo:1 Projection variable-based index assigning (Functions' arguments + attributes). queryPlan.Predicate = GetSelectAllPredicate(criteria, rowsEnumerator); } return(queryPlan); }
public MetadataType getMetadataType(MetadataIndex index) { return(metadataTypes[(int)index]); }
int getSize(MetadataIndex index) { return(getSize(16, new MetadataIndex[] { index })); }
int getSize(MetadataIndex index) { return getSize(16, new MetadataIndex[] { index }); }
int getSize(int bits, MetadataIndex[] indexes) { uint maxNum = 1U << bits; uint maxRows = getMaxRows(indexes); return maxRows <= maxNum ? 2 : 4; }
uint getMaxRows(MetadataIndex[] indexes) { uint maxRows = 0; for (int i = 0; i < indexes.Length; i++) maxRows = Math.Max(maxRows, numRows[(int)indexes[i]]); return maxRows; }
public MetadataType getMetadataType(MetadataIndex index) { return metadataTypes[(int)index]; }
public KeyPredicate(DocumentKey key, MetadataIndex metadataIndex) { _key = key; _index = metadataIndex; }
public QueryPlan GetQueryPlan(IDmObject parsedQuery, IQuery query, IQueryStore queryStore, MetadataIndex rowEnumerator) { throw new System.NotImplementedException(); }