/// <inheritdoc /> internal override ProjectionAttributeStateSet AppendProjectionAttributeState( ProjectionContext projCtx, ProjectionAttributeStateSet projOutputSet, CdmAttributeContext attrCtx) { // Create a new attribute context for the operation AttributeContextParameters attrCtxOpExcludeAttrsParam = new AttributeContextParameters { under = attrCtx, type = CdmAttributeContextType.OperationExcludeAttributes, Name = $"operation/index{Index}/operationExcludeAttributes" }; CdmAttributeContext attrCtxOpExcludeAttrs = CdmAttributeContext.CreateChildUnder(projCtx.ProjectionDirective.ResOpt, attrCtxOpExcludeAttrsParam); // Get the top-level attribute names of the attributes to exclude // We use the top-level names because the exclude list may contain a previous name our current resolved attributes had Dictionary <string, string> topLevelExcludeAttributeNames = ProjectionResolutionCommonUtil.GetTopList(projCtx, this.ExcludeAttributes); // Initialize a projection attribute context tree builder with the created attribute context for the operation ProjectionAttributeContextTreeBuilder attrCtxTreeBuilder = new ProjectionAttributeContextTreeBuilder(attrCtxOpExcludeAttrs); // Iterate through all the projection attribute states generated from the source's resolved attributes // Each projection attribute state contains a resolved attribute that it is corresponding to foreach (ProjectionAttributeState currentPAS in projCtx.CurrentAttributeStateSet.States) { // Check if the current projection attribute state's resolved attribute is in the list of attributes to exclude // If this attribute is not in the exclude list, then we are including it in the output if (!topLevelExcludeAttributeNames.ContainsKey(currentPAS.CurrentResolvedAttribute.ResolvedName)) { // Create the attribute context parameters and just store it in the builder for now // We will create the attribute contexts at the end attrCtxTreeBuilder.CreateAndStoreAttributeContextParameters(null, currentPAS, currentPAS.CurrentResolvedAttribute, CdmAttributeContextType.AttributeDefinition); // Create a projection attribute state for the included attribute by creating a copy of the current state // Copy() sets the current state as the previous state for the new one // We only create projection attribute states for attributes that are not in the exclude list ProjectionAttributeState newPAS = currentPAS.Copy(); projOutputSet.Add(newPAS); } else { // The current projection attribute state's resolved attribute is in the exclude list // Get the attribute name the way it appears in the exclude list string excludeAttributeName = null; topLevelExcludeAttributeNames.TryGetValue(currentPAS.CurrentResolvedAttribute.ResolvedName, out excludeAttributeName); // Create the attribute context parameters and just store it in the builder for now // We will create the attribute contexts at the end attrCtxTreeBuilder.CreateAndStoreAttributeContextParameters(excludeAttributeName, currentPAS, currentPAS.CurrentResolvedAttribute, CdmAttributeContextType.AttributeDefinition); } } // Create all the attribute contexts and construct the tree attrCtxTreeBuilder.ConstructAttributeContextTree(projCtx); return(projOutputSet); }
/// <inheritdoc /> internal override ProjectionAttributeStateSet AppendProjectionAttributeState( ProjectionContext projCtx, ProjectionAttributeStateSet projOutputSet, CdmAttributeContext attrCtx) { // Create a new attribute context for the operation AttributeContextParameters attrCtxOpIncludeAttrsParam = new AttributeContextParameters { under = attrCtx, type = CdmAttributeContextType.OperationIncludeAttributes, Name = $"operation/index{Index}/operationIncludeAttributes" }; CdmAttributeContext attrCtxOpIncludeAttrs = CdmAttributeContext.CreateChildUnder(projCtx.ProjectionDirective.ResOpt, attrCtxOpIncludeAttrsParam); // Get the top-level attribute names for each of the included attributes // Since the include operation allows providing either current state resolved attribute names // or the previous state resolved attribute names, we search for the name in the PAS tree // and fetch the top level resolved attribute names. Dictionary <string, string> topLevelIncludeAttributeNames = ProjectionResolutionCommonUtil.GetTopList(projCtx, this.IncludeAttributes); // Initialize a projection attribute context tree builder with the created attribute context for the operation ProjectionAttributeContextTreeBuilder attrCtxTreeBuilder = new ProjectionAttributeContextTreeBuilder(attrCtxOpIncludeAttrs); // Iterate through all the PAS in the PASSet generated from the projection source's resolved attributes foreach (ProjectionAttributeState currentPAS in projCtx.CurrentAttributeStateSet.States) { // Check if the current PAS's RA is in the list of attributes to include. if (topLevelIncludeAttributeNames.ContainsKey(currentPAS.CurrentResolvedAttribute.ResolvedName)) { // Get the attribute name the way it appears in the include list string includeAttributeName = null; topLevelIncludeAttributeNames.TryGetValue(currentPAS.CurrentResolvedAttribute.ResolvedName, out includeAttributeName); // Create the attribute context parameters and just store it in the builder for now // We will create the attribute contexts at the end attrCtxTreeBuilder.CreateAndStoreAttributeContextParameters(includeAttributeName, currentPAS, currentPAS.CurrentResolvedAttribute, CdmAttributeContextType.AttributeDefinition); // Create a projection attribute state for the included attribute by creating a copy of the current state // Copy() sets the current state as the previous state for the new one // We only create projection attribute states for attributes in the include list ProjectionAttributeState newPAS = currentPAS.Copy(); projOutputSet.Add(newPAS); } else { // Create the attribute context parameters and just store it in the builder for now // We will create the attribute contexts at the end attrCtxTreeBuilder.CreateAndStoreAttributeContextParameters(null, currentPAS, currentPAS.CurrentResolvedAttribute, CdmAttributeContextType.AttributeDefinition); } } // Create all the attribute contexts and construct the tree attrCtxTreeBuilder.ConstructAttributeContextTree(projCtx); return(projOutputSet); }
/// <inheritdoc /> internal override ProjectionAttributeStateSet AppendProjectionAttributeState( ProjectionContext projCtx, ProjectionAttributeStateSet projOutputSet, CdmAttributeContext attrCtx) { // Create a new attribute context for the operation AttributeContextParameters attrCtxOpCombineAttrsParam = new AttributeContextParameters { under = attrCtx, type = CdmAttributeContextType.OperationCombineAttributes, Name = $"operation/index{Index}/operationCombineAttributes" }; CdmAttributeContext attrCtxOpCombineAttrs = CdmAttributeContext.CreateChildUnder(projCtx.ProjectionDirective.ResOpt, attrCtxOpCombineAttrsParam); // Initialize a projection attribute context tree builder with the created attribute context for the operation ProjectionAttributeContextTreeBuilder attrCtxTreeBuilder = new ProjectionAttributeContextTreeBuilder(attrCtxOpCombineAttrs); // Get all the leaf level PAS nodes from the tree for each selected attribute and cache to a dictionary Dictionary <string, List <ProjectionAttributeState> > leafLevelCombineAttributeNames = new Dictionary <string, List <ProjectionAttributeState> >(); // Also, create a single list of leaf level PAS List <ProjectionAttributeState> leafLevelMergePASList = new List <ProjectionAttributeState>(); foreach (string select in this.Select) { List <ProjectionAttributeState> leafLevelListForCurrentSelect = ProjectionResolutionCommonUtil.GetLeafList(projCtx, select); if (leafLevelListForCurrentSelect != null && leafLevelListForCurrentSelect.Count > 0 && !leafLevelCombineAttributeNames.ContainsKey(select)) { leafLevelCombineAttributeNames.Add(select, leafLevelListForCurrentSelect); leafLevelMergePASList.AddRange(leafLevelListForCurrentSelect); } } // Create a List of top-level PAS objects that will be get merged based on the selected attributes List <ProjectionAttributeState> pasMergeList = new List <ProjectionAttributeState>(); // Run through the top-level PAS objects foreach (ProjectionAttributeState currentPAS in projCtx.CurrentAttributeStateSet.States) { if (leafLevelCombineAttributeNames.ContainsKey(currentPAS.CurrentResolvedAttribute.ResolvedName)) { // Attribute to Merge if (!pasMergeList.Contains(currentPAS)) { pasMergeList.Add(currentPAS); } } else { // Attribute to Pass Through // Create a projection attribute state for the non-selected / pass-through attribute by creating a copy of the current state // Copy() sets the current state as the previous state for the new one ProjectionAttributeState newPAS = currentPAS.Copy(); projOutputSet.Add(newPAS); } } if (pasMergeList.Count > 0) { CdmTypeAttributeDefinition mergeIntoAttribute = this.MergeInto as CdmTypeAttributeDefinition; // the merged attribute needs one new place to live, so here it is AttributeContextParameters mergedAttrCtxParam = new AttributeContextParameters { under = attrCtxOpCombineAttrs, type = CdmAttributeContextType.AttributeDefinition, Name = mergeIntoAttribute.GetName() }; CdmAttributeContext mergedAttrCtx = CdmAttributeContext.CreateChildUnder(projCtx.ProjectionDirective.ResOpt, mergedAttrCtxParam); // Create new resolved attribute, set the new attribute as target ResolvedAttribute raNewMergeInto = CreateNewResolvedAttribute(projCtx, mergedAttrCtx, mergeIntoAttribute, null); // Create new output projection attribute state set ProjectionAttributeState newMergeIntoPAS = new ProjectionAttributeState(projOutputSet.Ctx) { CurrentResolvedAttribute = raNewMergeInto, PreviousStateList = pasMergeList }; // Create the attribute context parameters and just store it in the builder for now // We will create the attribute contexts at the end foreach (string select in leafLevelCombineAttributeNames.Keys) { if (leafLevelCombineAttributeNames.ContainsKey(select) && leafLevelCombineAttributeNames[select] != null && leafLevelCombineAttributeNames[select].Count > 0) { foreach (ProjectionAttributeState leafLevelForSelect in leafLevelCombineAttributeNames[select]) { attrCtxTreeBuilder.CreateAndStoreAttributeContextParameters(select, leafLevelForSelect, newMergeIntoPAS.CurrentResolvedAttribute, CdmAttributeContextType.AttributeDefinition, leafLevelForSelect.CurrentResolvedAttribute.AttCtx, // lineage is the source att newMergeIntoPAS.CurrentResolvedAttribute.AttCtx); // merge into points back here } } } projOutputSet.Add(newMergeIntoPAS); } // Create all the attribute contexts and construct the tree attrCtxTreeBuilder.ConstructAttributeContextTree(projCtx); return(projOutputSet); }
/// <inheritdoc /> internal override ProjectionAttributeStateSet AppendProjectionAttributeState( ProjectionContext projCtx, ProjectionAttributeStateSet projOutputSet, CdmAttributeContext attrCtx) { // Create a new attribute context for the operation AttributeContextParameters attrCtxOpRenameAttrsParam = new AttributeContextParameters { under = attrCtx, type = CdmAttributeContextType.OperationRenameAttributes, Name = $"operation/index{Index}/operationRenameAttributes" }; CdmAttributeContext attrCtxOpRenameAttrs = CdmAttributeContext.CreateChildUnder(projCtx.ProjectionDirective.ResOpt, attrCtxOpRenameAttrsParam); // Get the list of attributes that will be renamed List <string> renameAttributes; if (this.ApplyTo != null) { renameAttributes = this.ApplyTo; } else { renameAttributes = new List <string>(); foreach (ProjectionAttributeState currentPAS in projCtx.CurrentAttributeStateSet.States) { renameAttributes.Add(currentPAS.CurrentResolvedAttribute.ResolvedName); } } // Get the top-level attribute names of the attributes to rename // We use the top-level names because the rename list may contain a previous name our current resolved attributes had Dictionary <string, string> topLevelRenameAttributeNames = ProjectionResolutionCommonUtil.GetTopList(projCtx, renameAttributes); string sourceAttributeName = projCtx.ProjectionDirective.OriginalSourceEntityAttributeName; // Initialize a projection attribute context tree builder with the created attribute context for the operation ProjectionAttributeContextTreeBuilder attrCtxTreeBuilder = new ProjectionAttributeContextTreeBuilder(attrCtxOpRenameAttrs); // Iterate through all the projection attribute states generated from the source's resolved attributes // Each projection attribute state contains a resolved attribute that it is corresponding to foreach (ProjectionAttributeState currentPAS in projCtx.CurrentAttributeStateSet.States) { // Check if the current projection attribute state's resolved attribute is in the list of attributes to rename // If this attribute is not in the rename list, then we are including it in the output without changes if (topLevelRenameAttributeNames.ContainsKey(currentPAS.CurrentResolvedAttribute.ResolvedName)) { if (currentPAS.CurrentResolvedAttribute.Target is CdmAttribute) { // The current attribute should be renamed string newAttributeName = GetNewAttributeName(currentPAS, sourceAttributeName); // Create new resolved attribute with the new name, set the new attribute as target ResolvedAttribute resAttrNew = CreateNewResolvedAttribute(projCtx, null, currentPAS.CurrentResolvedAttribute.Target, newAttributeName); // Get the attribute name the way it appears in the applyTo list string applyToName = topLevelRenameAttributeNames[currentPAS.CurrentResolvedAttribute.ResolvedName]; // Create the attribute context parameters and just store it in the builder for now // We will create the attribute contexts at the end attrCtxTreeBuilder.CreateAndStoreAttributeContextParameters(applyToName, currentPAS, resAttrNew, CdmAttributeContextType.AttributeDefinition, currentPAS.CurrentResolvedAttribute.AttCtx, // lineage is the original attribute null); // don't know who will point here yet // Create a projection attribute state for the renamed attribute by creating a copy of the current state // Copy() sets the current state as the previous state for the new one // We only create projection attribute states for attributes that are in the rename list ProjectionAttributeState newPAS = currentPAS.Copy(); // Update the resolved attribute to be the new renamed attribute we created newPAS.CurrentResolvedAttribute = resAttrNew; projOutputSet.Add(newPAS); } else { Logger.Warning(this.Ctx, Tag, nameof(AppendProjectionAttributeState), this.AtCorpusPath, CdmLogCode.WarnProjRenameAttrNotSupported); // Add the attribute without changes projOutputSet.Add(currentPAS); } } else { // Pass through projOutputSet.Add(currentPAS); } } // Create all the attribute contexts and construct the tree attrCtxTreeBuilder.ConstructAttributeContextTree(projCtx); return(projOutputSet); }
/// <inheritdoc /> internal override ProjectionAttributeStateSet AppendProjectionAttributeState( ProjectionContext projCtx, ProjectionAttributeStateSet projOutputSet, CdmAttributeContext attrCtx) { // Create a new attribute context for the operation AttributeContextParameters attrCtxOpIncludeAttrsParam = new AttributeContextParameters { under = attrCtx, type = CdmAttributeContextType.OperationIncludeAttributes, Name = $"operation/index{Index}/operationIncludeAttributes" }; CdmAttributeContext attrCtxOpIncludeAttrs = CdmAttributeContext.CreateChildUnder(projCtx.ProjectionDirective.ResOpt, attrCtxOpIncludeAttrsParam); // Get the top-level attribute names for each of the included attributes // Since the include operation allows providing either current state resolved attribute names // or the previous state resolved attribute names, we search for the name in the PAS tree // and fetch the top level resolved attribute names. Dictionary <string, string> topLevelIncludeAttributeNames = ProjectionResolutionCommonUtil.GetTopList(projCtx, this.IncludeAttributes); // Initialize a projection attribute context tree builder with the created attribute context for the operation ProjectionAttributeContextTreeBuilder attrCtxTreeBuilder = new ProjectionAttributeContextTreeBuilder(attrCtxOpIncludeAttrs); // Index that holds the current attribute name as the key and the attribute as value Dictionary <string, ProjectionAttributeState> topLevelIncludeAttribute = new Dictionary <string, ProjectionAttributeState>(); // List of attributes that were not included on the final attribute list List <ProjectionAttributeState> removedAttributes = new List <ProjectionAttributeState>(); // Iterate through all the PAS in the PASSet generated from the projection source's resolved attributes foreach (ProjectionAttributeState currentPAS in projCtx.CurrentAttributeStateSet.States) { // Check if the current PAS's RA is in the list of attributes to include. if (topLevelIncludeAttributeNames.ContainsKey(currentPAS.CurrentResolvedAttribute.ResolvedName)) { topLevelIncludeAttribute.Add(currentPAS.CurrentResolvedAttribute.ResolvedName, currentPAS); } else { removedAttributes.Add(currentPAS); } } // Loop through the list of attributes in the same order that was specified by the user foreach (KeyValuePair <string, string> entry in topLevelIncludeAttributeNames) { // Get the attribute state ProjectionAttributeState currentPAS = topLevelIncludeAttribute[entry.Key]; // Get the attribute name the way it appears in the include list string includeAttributeName = entry.Value; // Create the attribute context parameters and just store it in the builder for now // We will create the attribute contexts at the end attrCtxTreeBuilder.CreateAndStoreAttributeContextParameters(includeAttributeName, currentPAS, currentPAS.CurrentResolvedAttribute, CdmAttributeContextType.AttributeDefinition, currentPAS.CurrentResolvedAttribute.AttCtx, // lineage is the included attribute null); // don't know who will point here yet // Create a projection attribute state for the included attribute by creating a copy of the current state // Copy() sets the current state as the previous state for the new one // We only create projection attribute states for attributes in the include list ProjectionAttributeState newPAS = currentPAS.Copy(); projOutputSet.Add(newPAS); } // Generate attribute context nodes for the attributes that were not included foreach (ProjectionAttributeState currentPAS in removedAttributes) { // Create the attribute context parameters and just store it in the builder for now // We will create the attribute contexts at the end attrCtxTreeBuilder.CreateAndStoreAttributeContextParameters(null, currentPAS, currentPAS.CurrentResolvedAttribute, CdmAttributeContextType.AttributeExcluded, currentPAS.CurrentResolvedAttribute.AttCtx, // lineage is the included attribute null); // don't know who will point here yet } // Create all the attribute contexts and construct the tree attrCtxTreeBuilder.ConstructAttributeContextTree(projCtx); return(projOutputSet); }