Example #1
0
        public static void ProcessIsNullPatcherTransformations(SymbolTable symbolTable)
        {
            var snapshotSymbolTable = new List<IReferenceableItem>(symbolTable);
            foreach (var astNamedNode in snapshotSymbolTable)
            {
                var nullPatcherNode = astNamedNode as AstIsNullPatcherNode;
                if (nullPatcherNode != null && astNamedNode.FirstThisOrParent<ITemplate>() == null)
                {
                    var astDerivedColumnListNode = new AstDerivedColumnListNode(nullPatcherNode.ParentItem)
                                                       {
                                                           Name = nullPatcherNode.Name,
                                                           ValidateExternalMetadata = nullPatcherNode.ValidateExternalMetadata
                                                       };

                    foreach (AstIsNullPatcherColumnNode patchColumn in nullPatcherNode.Columns)
                    {
                        var column = new AstDerivedColumnNode(astDerivedColumnListNode)
                                         {
                                             Name = patchColumn.Name,
                                             ReplaceExisting = true,
                                             Expression = String.Format(CultureInfo.InvariantCulture, "ISNULL({0}) ? {1} : {0}", patchColumn.Name, patchColumn.DefaultValue),
                                             DerivedColumnType = VulcanEngine.IR.Ast.ColumnType.Object
                                         };
                        astDerivedColumnListNode.Columns.Add(column);
                    }

                    Utility.Replace(nullPatcherNode, new List<AstTransformationNode> { astDerivedColumnListNode });
                }
            }
        }
Example #2
0
 public DerivedColumns(LoweringContext context, AstNode astNode)
     : base(context, astNode as AstTransformationNode)
 {
     _astDerivedColumnListNode = astNode as AstDerivedColumnListNode;
     RegisterInputBinding(_astDerivedColumnListNode);
 }
        private static void BuildInsertPath(AstTableNode targetTable, IFrameworkItem parentItem, List<AstTransformationNode> workflowFragment, AstDataflowOutputPathNode scdInsertPath)
        {
            var insertTransform = new AstDerivedColumnListNode(parentItem) { Name = Utility.NameCleanerAndUniqifier(targetTable.Name + "_InsertDerivedColumns") };
            insertTransform.InputPath = new AstDataflowMappedInputPathNode(insertTransform) { OutputPath = scdInsertPath };
            insertTransform.Columns.Add(new AstDerivedColumnNode(insertTransform)
            {
                Name = "_scdFrom",
                Expression = "(DT_DBTIMESTAMP2,7)(@[System::StartTime])",
                Scale = 7,
                DerivedColumnType = ColumnType.DateTime2,
                ReplaceExisting = false
            });
            insertTransform.Columns.Add(new AstDerivedColumnNode(insertTransform)
            {
                Name = "_scdTo",
                Expression = "NULL(DT_DBTIMESTAMP2,7)",
                Scale = 7,
                DerivedColumnType = ColumnType.DateTime2,
                ReplaceExisting = false
            });
            workflowFragment.Add(insertTransform);

            var insertDestination = new AstDestinationNode(parentItem);
            insertDestination.Table = targetTable;
            insertDestination.DisableScd = true;
            insertDestination.ValidateExternalMetadata = false;
            insertDestination.Name = Utility.NameCleanerAndUniqifier(targetTable.Name + "_InsertDestination");
            workflowFragment.Add(insertDestination);
        }
        private static AstDataflowOutputPathNode BuildHistoricalSubpath(AstTableNode targetTable, IFrameworkItem parentItem, List<AstTransformationNode> workflowFragment, AstDataflowOutputPathNode scdHistoricalPath)
        {
            var historicalTransform = new AstDerivedColumnListNode(parentItem);
            historicalTransform.InputPath = new AstDataflowMappedInputPathNode(historicalTransform) { OutputPath = scdHistoricalPath };
            historicalTransform.Name = Utility.NameCleanerAndUniqifier(targetTable.Name + "_HistoricalDerivedColumns");
            historicalTransform.Columns.Add(new AstDerivedColumnNode(historicalTransform)
            {
                Name = "_scdTo",
                Expression = "(DT_DBTIMESTAMP2,7)(@[System::StartTime])",
                Scale = 7,
                DerivedColumnType = ColumnType.DateTime2,
                ReplaceExisting = false
            });
            workflowFragment.Add(historicalTransform);

            var historicalCommand = new AstOleDBCommandNode(parentItem)
                                        {
                                            Name = Utility.NameCleanerAndUniqifier(targetTable.Name + "_HistoricalCommand"), 
                                            Connection = targetTable.Connection
                                        };
            historicalCommand.Query = new AstTransformationMappedQueryNode(historicalCommand);

            var historicalSetColumnValueMappings = new List<TableColumnValueMapping>();
            var historicalWhereColumnValueMappings = new List<TableColumnValueMapping>();
            historicalCommand.Query.Mappings.Add(new AstDataflowColumnMappingNode(historicalCommand) { SourceName = "_scdTo", TargetName = "Param_0" });
            historicalSetColumnValueMappings.Add(new TableColumnValueMapping("_scdTo", "?", MappingOperator.Assign));

            historicalWhereColumnValueMappings.Add(new TableColumnValueMapping("_scdTo", "NULL", MappingOperator.CompareIs));
            int historicalIndex = 1;
            foreach (var keyColumn in targetTable.PreferredKey.Columns)
            {
                historicalCommand.Query.Mappings.Add(new AstDataflowColumnMappingNode(historicalCommand) { SourceName = keyColumn.Column.Name, TargetName = String.Format(CultureInfo.InvariantCulture, "Param_{0}", historicalIndex++) });
                historicalWhereColumnValueMappings.Add(new TableColumnValueMapping(keyColumn.Column.Name, "?", MappingOperator.CompareEqual));
            }

            historicalCommand.Query.Body = TableLowerer.EmitUpdateStatement(targetTable, historicalSetColumnValueMappings, historicalWhereColumnValueMappings);
            historicalCommand.ValidateExternalMetadata = false;
            workflowFragment.Add(historicalCommand);

            return historicalCommand.OutputPath;
        }