private void ReplaceExistingColumn(DerivedColumn column)
        {
            if (column.ReplaceExisting)
            {
                IDTSVirtualInput100 vi = _component.InputCollection[0].GetVirtualInput();

                IDTSInputColumn100 col;
                SetInputUsageType(vi, vi.VirtualInputColumnCollection[column.Name], DTSUsageType.UT_READWRITE);
                col = _component.InputCollection[0].InputColumnCollection[column.Name];

                col.CustomPropertyCollection["Expression"].Value = this.ExpressionCleanerAndInputMapBuilder(column.Expression, vi, DTSUsageType.UT_READONLY);
                col.CustomPropertyCollection["FriendlyExpression"].Value = column.Expression;
            }
        }
        private void AddOutputColumn(DerivedColumn column)
        {
            IDTSOutputColumn100 col;
            col = _component.OutputCollection[0].OutputColumnCollection.New();
            col.Name = column.Name;
            col.Description = column.Name;
            col.ErrorRowDisposition = DTSRowDisposition.RD_IgnoreFailure;
            col.TruncationRowDisposition = DTSRowDisposition.RD_FailComponent;
            col.SetDataTypeProperties(GetDataTypeFromString(column.Type), column.Length, column.Precision, column.Scale, column.Codepage);
            col.ExternalMetadataColumnID = 0;

            IDTSCustomProperty100 propExpression = col.CustomPropertyCollection.New();
            propExpression.Name = "Expression";
            propExpression.Value = column.Expression;

            IDTSCustomProperty100 propFriendlyExpression = col.CustomPropertyCollection.New();
            propFriendlyExpression.Name = "FriendlyExpression";
            propFriendlyExpression.Value = column.Expression;

            IDTSVirtualInput100 vi = _component.InputCollection[0].GetVirtualInput();

            propExpression.Value = this.ExpressionCleanerAndInputMapBuilder(column.Expression, vi, DTSUsageType.UT_READONLY);
        }
        public static PhysicalDataFlow.DerivedColumns Lower(this AstTransformation.AstIsNullPatcherNode astNode)
        {
            if (astNode.AsClassOnly)
            {
                return null;
            }

            Ssis2008Emitter.IR.DataFlow.DerivedColumns physicalNode = new Ssis2008Emitter.IR.DataFlow.DerivedColumns();
            physicalNode.Name = astNode.Name;

            foreach (AstTransformation.AstIsNullPatcherColumnNode column in astNode.Columns)
            {
                Ssis2008Emitter.IR.DataFlow.DerivedColumn physicalColumn = new Ssis2008Emitter.IR.DataFlow.DerivedColumn();
                physicalColumn.Name = column.Name;
                // TODO: Use template here?
                physicalColumn.Expression = String.Format(System.Globalization.CultureInfo.InvariantCulture, "ISNULL({0}) ? {1} : {0}", column.Name, column.DefaultValue);
                physicalColumn.ReplaceExisting = true;
                physicalColumn.Parent = physicalNode;
                physicalNode.Columns.Add(physicalColumn);
            }
            return physicalNode;
        }
        public static PhysicalDataFlow.DerivedColumns Lower(this AstTransformation.AstDerivedColumnListNode astNode)
        {
            if (astNode.AsClassOnly)
            {
                return null;
            }

            Ssis2008Emitter.IR.DataFlow.DerivedColumns physicalNode = new Ssis2008Emitter.IR.DataFlow.DerivedColumns();
            physicalNode.Name = astNode.Name;

            foreach (AstTransformation.AstDerivedColumnNode column in astNode.Columns)
            {
                Ssis2008Emitter.IR.DataFlow.DerivedColumn physicalColumn = new Ssis2008Emitter.IR.DataFlow.DerivedColumn();
                physicalColumn.Name = column.Name;
                physicalColumn.Type = column.Type.ToString();
                physicalColumn.Length = column.Length;
                physicalColumn.Precision = column.Precision;
                physicalColumn.Scale = column.Scale;
                physicalColumn.Expression = column.Expression;

                physicalColumn.ReplaceExisting = column.ReplaceExisting;
                physicalColumn.Parent = physicalNode;
                physicalNode.Columns.Add(physicalColumn);
            }
            return physicalNode;
        }
        public static PhysicalDataFlow.DerivedColumns Lower(this AstTransformation.AstAutoNullPatcherNode astNode)
        {
            if (astNode.AsClassOnly)
            {
                return null;
            }

            Ssis2008Emitter.IR.DataFlow.DerivedColumns physicalNode = new Ssis2008Emitter.IR.DataFlow.DerivedColumns();
            physicalNode.Name = String.Format(System.Globalization.CultureInfo.InvariantCulture, "AutoPatcher for Fact Table: {0}", astNode.FactTable.ReferenceableName);

            foreach (AstTable.AstTableColumnBaseNode column in astNode.FactTable.Columns)
            {
                if (!column.IsNullable)
                {
                    Ssis2008Emitter.IR.DataFlow.DerivedColumn physicalColumn = new Ssis2008Emitter.IR.DataFlow.DerivedColumn();
                    physicalColumn.Name = column.Name;
                    AstTable.AstTableColumnNode tableColumn = column as AstTable.AstTableColumnNode;
                    // TODO: Use template here?
                    // TODO: Can we assume that dim default is 0?
                    physicalColumn.Expression = String.Format(System.Globalization.CultureInfo.InvariantCulture, "ISNULL({0}) ? {1} : {0}", column.Name, tableColumn == null ? 0.ToString(System.Globalization.CultureInfo.InvariantCulture) : tableColumn.Default);
                    physicalColumn.ReplaceExisting = true;
                    physicalColumn.Parent = physicalNode;
                    physicalNode.Columns.Add(physicalColumn);
                }
            }
            return physicalNode;
        }