示例#1
0
        public virtual DcSchema CreateSchema(string name, DcSchemaKind schemaType)
        {
            DcSchema schema;

            if (schemaType == DcSchemaKind.Dc)
            {
                schema = new Schema(name, this);
            }
            else if (schemaType == DcSchemaKind.Csv)
            {
                schema = new SchemaCsv(name, this);
            }
            else if (schemaType == DcSchemaKind.Oledb)
            {
                schema = new SchemaOledb(name, this);
            }
            else if (schemaType == DcSchemaKind.Rel)
            {
                throw new NotImplementedException("This schema type is not implemented.");
            }
            else
            {
                throw new NotImplementedException("This schema type is not implemented.");
            }

            _schemas.Add(schema);

            NotifyAdd(schema);

            return(schema);
        }
示例#2
0
        public void CsvReadTest() // Load Csv schema and data as a result of evaluation
        {
            DcSpace space = new Space();

            // Create schema for a remote db
            SchemaCsv top = (SchemaCsv)space.CreateSchema("My Files", DcSchemaKind.Csv);

            // Create a remote file description
            TableCsv table = (TableCsv)space.CreateTable(DcSchemaKind.Csv, "Products", top.Root);

            table.FilePath = CsvRead;
            var columns = top.LoadSchema(table);

            Assert.AreEqual(1, top.Root.SubTables.Count);
            Assert.AreEqual(15, top.GetSubTable("Products").Columns.Count);

            Assert.AreEqual("String", top.GetSubTable("Products").GetColumn("Product Name").Output.Name);
            Assert.AreEqual("3", ((ColumnCsv)top.GetSubTable("Products").GetColumn("ID")).SampleValues[1]);

            //
            // Configure import
            //
            DcSchema schema = space.CreateSchema("My Schema", DcSchemaKind.Dc);

            DcTable productsTable = space.CreateTable(DcSchemaKind.Dc, "Products", schema.Root);

            // Manually create column to be imported (we need an automatic mechanism for appending missing columns specified in the formula)
            DcColumn p1 = space.CreateColumn("ID", productsTable, schema.GetPrimitiveType("Integer"), true);
            DcColumn p2 = space.CreateColumn("Product Code", productsTable, schema.GetPrimitiveType("String"), false);
            DcColumn p3 = space.CreateColumn("Custom Product Name", productsTable, schema.GetPrimitiveType("String"), false);
            DcColumn p4 = space.CreateColumn("List Price", productsTable, schema.GetPrimitiveType("Double"), false);
            DcColumn p5 = space.CreateColumn("Constant Column", productsTable, schema.GetPrimitiveType("Double"), false);

            // Define import column
            DcColumn col = space.CreateColumn("Import", top.GetSubTable("Products"), productsTable, false);

            col.GetData().IsAppendData   = true;
            col.GetData().Formula        = "(( [Integer] [ID] = this.[ID], [String] [Product Code] = [Product Code], [String] [Custom Product Name] = [Product Name], [Double] [List Price] = [List Price], [Double] [Constant Column] = 20.02 ))"; // Tuple structure corresponds to output table
            col.GetData().IsAppendData   = true;
            col.GetData().IsAppendSchema = true;

            productsTable.GetData().Populate();

            Assert.AreEqual(45, productsTable.GetData().Length);
            Assert.AreEqual("Northwind Traders Dried Pears", p3.GetData().GetValue(5));
            Assert.AreEqual(20.02, p5.GetData().GetValue(5));
        }
示例#3
0
        public void CsvWriteTest() // Store schema and data to a CSV file as a result of evaluation
        {
            DcSpace  space  = new Space();
            DcSchema schema = space.CreateSchema("My Schema", DcSchemaKind.Dc);

            CoreTest.CreateSampleSchema(schema);

            CoreTest.CreateSampleData(schema);

            DcTable t2 = schema.GetSubTable("Table 2");

            DcColumn c21 = t2.GetColumn("Column 21");
            DcColumn c22 = t2.GetColumn("Column 22");
            DcColumn c23 = t2.GetColumn("Column 23");

            //
            // Create schema for a remote db
            //
            SchemaCsv top = (SchemaCsv)space.CreateSchema("My Files", DcSchemaKind.Csv);

            // Create a remote file description
            TableCsv table = (TableCsv)space.CreateTable(DcSchemaKind.Csv, "Table_1", top.Root);

            table.FilePath = CsvWrite;

            // Manually create column to be imported (we need an automatic mechanism for appending missing columns specified in the formula)
            DcColumn p1 = space.CreateColumn("Column 11", table, top.GetPrimitiveType("String"), true);
            DcColumn p2 = space.CreateColumn("Column 12", table, top.GetPrimitiveType("String"), true);
            DcColumn p3 = space.CreateColumn("Custom Column 13", table, top.GetPrimitiveType("String"), true);
            DcColumn p4 = space.CreateColumn("Constant Column", table, top.GetPrimitiveType("String"), true);

            // Define export column
            DcColumn col = space.CreateColumn("Export", schema.GetSubTable("Table 1"), table, false);

            col.GetData().IsAppendData   = true;
            col.GetData().Formula        = "(( [String] [Column 11] = this.[Column 11], [String] [Column 12] = [Column 12], [String] [Custom Column 13] = [Column 13], [String] [Constant Column] = 20.02 ))"; // Tuple structure corresponds to output table
            col.GetData().IsAppendData   = true;
            col.GetData().IsAppendSchema = true;

            table.Populate();
        }