Example #1
0
        public void SetExtractionTest()
        {
            // Create Oldedb top set
            SetTopOledb dbTop = new SetTopOledb("Northwind");

            dbTop.ConnectionString = Northwind;
            dbTop.Open();
            dbTop.ImportSchema();

            SetTop wsTop = new SetTop("My Mashup");

            //
            // Load test data
            //
            Set targetSet = Mapper.ImportSet(dbTop.FindSubset("Order Details"), wsTop);

            targetSet.TableDefinition.Populate();

            Set products = wsTop.FindSubset("Products");
            Dim projDim  = products.GetGreaterDim("Category"); // This is a parameter for the whole operation

            //
            // Create a set to be extracted
            //
            Set extractedSet = new Set("Categories");

            wsTop.Root.AddSubset(extractedSet);

            Set idSet = projDim.GreaterSet;
            Dim idDim = wsTop.CreateColumn(projDim.Name, extractedSet, idSet, true);

            idDim.Add();

            //
            // Configure the new extracted set population procedure (mapped dimension)
            //
            Mapping mapping = new Mapping(products, extractedSet);

            mapping.AddMatch(new PathMatch(new DimPath(projDim), new DimPath(idDim)));

            Dim extractedDim = wsTop.CreateColumn(extractedSet.Name, products, extractedSet, true);

            extractedDim.Mapping = mapping;
            extractedDim.Add();
            extractedDim.GreaterSet.ProjectDimensions.Add(extractedDim);

            //
            // Populate the extracted set
            //
            extractedSet.TableDefinition.Populate();

            Assert.AreEqual("Dried Fruit & Nuts", extractedSet.GetValue("Category", 1));
            Assert.AreEqual("Pasta", extractedSet.GetValue("Category", 9));

            //
            // Populate the new dimension. It is equivalent to evaluating a normal (mapped) dimension because its greater set has been extracted.
            //
            extractedDim.Evaluate();

            Assert.AreEqual(1, extractedDim.GetValue(1));
            Assert.AreEqual(1, extractedDim.GetValue(19));
        }
Example #2
0
        public void ChangeTypeTest()
        {
            // Create Oldedb top set
            SetTopOledb dbTop = new SetTopOledb("Northwind");

            dbTop.ConnectionString = Northwind;
            dbTop.Open();
            dbTop.ImportSchema();

            SetTop wsTop = new SetTop("My Mashup");

            //
            // Load test data.
            //
            Set orderStatus = Mapper.ImportSet(dbTop.FindSubset("Orders Status"), wsTop); // We load it separately to get more (target) data

            orderStatus.TableDefinition.Populate();

            Set mainSet = Mapper.ImportSet(dbTop.FindSubset("Order Details"), wsTop);

            mainSet.TableDefinition.Populate();

            Dim sourceDim     = mainSet.GetGreaterDim("Status ID");
            Set sourceDimType = wsTop.FindSubset("Order Details Status");

            //
            // Define a new derived (mapped) dimension: (Order Details) -> newDim -> (Orders Status)
            // This new projDim is supposed to clone existing projDim: (Order Details) -> existingDim -> (Order Details Status)
            // Thus we essentially implement "Change Type" pattern
            //
            Set mappedDimType = wsTop.FindSubset("Orders Status");
            Dim mappedDim     = wsTop.CreateColumn(sourceDim.Name + " (1)", mainSet, mappedDimType, true); // TODO: set also other properties so that new projDim is identical to the old one

            mappedDim.Add();

            // Manually define a mapping: Source: (Orders Details) -> Status ID -> Status ID. Target: (Orders Status) -> Status ID.
            Mapping mapping = new Mapping(mainSet, mappedDimType);

            mapping.AddMatch(new PathMatch( // Add one match between two paths
                                 new DimPath(new List <Dim> {
                sourceDim, sourceDimType.GetGreaterDim("Status ID")
            }),
                                 new DimPath(mappedDimType.GetGreaterDim("Status ID")))
                             );

            mappedDim.Mapping = mapping;

            // Populate new dimension
            mappedDim.Evaluate(); // Evaluate tuple expression on the same set (not remove set), that is, move data from one dimension to the new dimension

            Assert.AreEqual(2, mappedDim.GetValue(14));
            Assert.AreEqual(1, mappedDim.GetValue(15));

            //
            // Define a new derived (mapped) dimension: (Orders) -> newDim -> (Suppliers)
            // This new projDim is supposed to clone existing projDim: (Orders) -> existingDim -> (Employees)
            // Thus we essentially implement "Change Type" pattern
            //
            mainSet = wsTop.FindSubset("Orders");

            sourceDimType = wsTop.FindSubset("Employees");
            sourceDim     = mainSet.GetGreaterDim("Employee ID");

            //
            // Define a new derived (mapped) dimensions
            //
            mappedDimType = Mapper.ImportSet(dbTop.FindSubset("Suppliers"), wsTop);
            mappedDimType.TableDefinition.Populate();

            mappedDim = wsTop.CreateColumn(sourceDim.Name + " (1)", mainSet, mappedDimType, true); // TODO: set also other properties so that new projDim is identical to the old one
            mappedDim.Add();

            // Manually define a mapping
            mapping = new Mapping(mainSet, mappedDimType);
            mapping.AddMatch(new PathMatch( // Add one match between two paths
                                 new DimPath(new List <Dim> {
                sourceDim, sourceDimType.GetGreaterDim("ID")
            }),
                                 new DimPath(mappedDimType.GetGreaterDim("ID")))
                             );

            mappedDim.Mapping = mapping;

            // Populate new dimension
            mappedDim.Evaluate(); // Evaluate tuple expression on the same set (not remove set), that is, move data from one dimension to the new dimension

            Assert.AreEqual(8, mappedDim.GetValue(0));
            Assert.AreEqual(2, mappedDim.GetValue(1));
            Assert.AreEqual(3, mappedDim.GetValue(2));
            Assert.AreEqual(5, mappedDim.GetValue(3));
        }