Пример #1
0
        private static void ProcessTables(AstRootNode astRootNode)
        {
            var tables = new List <AstTableBaseNode>(astRootNode.Tables);

            foreach (var dimension in astRootNode.Dimensions)
            {
                tables.Add(dimension);
            }

            foreach (var fact in astRootNode.Facts)
            {
                tables.Add(fact);
            }

            foreach (AstTableNode table in tables)
            {
                if (table.LateArriving)
                {
                    LateArrivingLowerer.ProcessLateArrivingTable(table);
                }

                if (table.HasScdColumns)
                {
                    SlowlyChangingDimensionsLowerer.ProcessTableScdColumns(table);
                }

                foreach (var staticSourcePackage in StaticSourcesLowerer.ProcessTableStaticSource(table))
                {
                    astRootNode.Packages.Add(staticSourcePackage);
                }

                if (!(table is AstTableCloneNode) && table.EmitVersionNumber)
                {
                    var versionNumber = new AstTableColumnNode(table)
                    {
                        Name            = "VersionNumber",
                        ColumnType      = ColumnType.Binary,
                        Length          = 8,
                        CustomType      = "rowversion",
                        IsAssignable    = false,
                        IsNullable      = false,
                        IsAutoGenerated = true
                    };
                    table.Columns.Add(versionNumber);
                }

                if (table.Emit)
                {
                    astRootNode.Packages.Add(TableLowerer.ProcessTable(table));
                }
            }
        }
Пример #2
0
        public static void ProcessLateArrivingTable(AstTableNode astTableNode)
        {
            var lateArrivedColumn = new AstTableColumnNode(astTableNode)
            {
                Name = "_LateArrived", IsNullable = true, ColumnType = ColumnType.DateTime2, IsAutoGenerated = true
            };
            var markLateColumn = new AstTableColumnNode(astTableNode)
            {
                Name = "_IsLate", IsNullable = true, ColumnType = ColumnType.Boolean, IsAutoGenerated = true, Computed = "_LateArrived IS NOT NULL PERSISTED NOT NULL"
            };

            astTableNode.Columns.Add(lateArrivedColumn);
            astTableNode.Columns.Add(markLateColumn);
        }
Пример #3
0
        public AstTableNode GetFileSchema()
        {
            //default the schema to "File"
            AstSchemaNode astSchemaNode = new AstSchemaNode(null)
            {
                Name = "File",
                ForceDisableIncrementalChangeTracking = true
            };

            AstTableNode astTableNode = new AstTableNode(null)
            {
                Name   = this.Name,
                Schema = astSchemaNode,
                ForceDisableIncrementalChangeTracking = true
            };

            this.TableNode = astTableNode;

            Interrogator             i = new Interrogator();
            List <DestinationColumn> DestinationObject = i.ProcessFile(
                this.FilePath,
                this.ColumnDelimiter,
                this.FirstRowHeader,
                this.HeaderRowsToSkip,
                this.TextQualifier);

            foreach (DestinationColumn col in DestinationObject)
            {
                AstTableColumnNode currentColumn = new AstTableColumnNode(astTableNode)
                {
                    ForceDisableIncrementalChangeTracking = true
                };
                //set up the column
                currentColumn.Name = col.Name;
                if (col.MaxLength != null)
                {
                    currentColumn.Length = int.Parse(col.MaxLength.ToString());
                }
                if (col.Precision != null)
                {
                    currentColumn.Precision = int.Parse(col.Precision.ToString());
                }

                currentColumn.IsNullable = col.Nullable;
                //add the column to the table
                this.TableNode.Columns.Add(currentColumn);
            }

            return(this.TableNode);
        }
        public static void ProcessTableScdColumns(AstTableNode astTableNode)
        {
            AstLowererValidation.ValidateScdTable(astTableNode);

            bool emitScdColumns = astTableNode.Columns.Any(column => column.ScdType == ScdType.Historical);

            if (emitScdColumns)
            {
                var scdFromColumn = new AstTableColumnNode(astTableNode)
                {
                    Name = "_scdFrom", ColumnType = ColumnType.DateTime2, IsAutoGenerated = true
                };
                astTableNode.Columns.Add(scdFromColumn);

                var scdToColumn = new AstTableColumnNode(astTableNode)
                {
                    Name = "_scdTo", ColumnType = ColumnType.DateTime2, IsAutoGenerated = true
                };
                astTableNode.Columns.Add(scdToColumn);
            }
        }
Пример #5
0
    public static AstTableNode ToAstTableNode(this DataTable dataTable)
    {
        var schema = new AstSchemaNode(null);
        var table  = new AstTableNode(null);

        schema.Name  = dataTable.Rows.OfType <DataRow>().Select(r => r["TABLE_SCHEMA"].ToString()).First();
        table.Schema = schema;
        table.Name   = dataTable.Rows.OfType <DataRow>().Select(r => r["TABLE_NAME"].ToString()).First();
        foreach (DataRow row in dataTable.Rows)
        {
            var column = new AstTableColumnNode(table)
            {
                Name       = row["COLUMN_NAME"].ToString(),
                DataType   = row["DATA_TYPE"].ToString().GetDbType(),
                IsNullable = Convert.ToBoolean(row["IS_NULLABLE"].ToString().Replace("YES", "true").Replace("NO", "false"))
            };
            if (!row.IsNull("CHARACTER_MAXIMUM_LENGTH"))
            {
                column.Length = Convert.ToInt32(row["CHARACTER_MAXIMUM_LENGTH"]);
            }

            if (!row.IsNull("NUMERIC_PRECISION"))
            {
                column.Precision = Convert.ToInt32(row["NUMERIC_PRECISION"]);
            }

            if (!row.IsNull("NUMERIC_SCALE"))
            {
                column.Precision = Convert.ToInt32(row["NUMERIC_SCALE"]);
            }

            table.Columns.Add(column);
        }

        return(table);
    }