public void SubsettingTest() { // 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(); // // Create logical expression // Set products = wsTop.FindSubset("Products"); // Add subset Set subProducts = new Set("SubProducts"); wsTop.AddTable(subProducts, products); // Create simple (one-segment) function expressions Dim d1 = products.GetGreaterDim("List Price"); Dim d2 = products.GetGreaterDim("Standard Cost"); Dim d3 = products.GetGreaterDim("Target Level"); Expression d1_Expr = Expression.CreateProjectExpression(new List <Dim> { subProducts.SuperDim, d1 }, Operation.DOT); Expression d2_Expr = Expression.CreateProjectExpression(new List <Dim> { subProducts.SuperDim, d2 }, Operation.DOT); Expression d3_Expr = Expression.CreateProjectExpression(new List <Dim> { subProducts.SuperDim, d3 }, Operation.DOT); // Here values will be stored d1_Expr.GetInputLeaf().Input = new Expression("this", Operation.DOT, subProducts); d2_Expr.GetInputLeaf().Input = new Expression("this", Operation.DOT, subProducts); d3_Expr.GetInputLeaf().Input = new Expression("this", Operation.DOT, subProducts); Expression logicalExpr = new Expression("GREATER", Operation.GRE); logicalExpr.Input = d1_Expr; logicalExpr.AddOperand(d3_Expr); // Update subProducts.TableDefinition.WhereExpression = logicalExpr; subProducts.TableDefinition.Populate(); Assert.AreEqual(2, subProducts.Length); }
public void SetDataOperationsTest() { // 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 odet = wsTop.FindSubset("Order Details"); Set orders = wsTop.FindSubset("Orders"); Set cust = wsTop.FindSubset("Customers"); Set doubleSet = wsTop.GetPrimitive("Double"); Set intSet = wsTop.GetPrimitive("Integer"); Set strSet = wsTop.GetPrimitive("String"); Expression childExpr; // // Find operation // Expression orderExpr = new Expression("", Operation.TUPLE, orders); childExpr = new Expression("Order ID", Operation.PRIMITIVE, intSet); childExpr.Output = 35; orderExpr.AddOperand(childExpr); childExpr = new Expression("Tax Rate", Operation.PRIMITIVE, doubleSet); childExpr.Output = 55.5; // Will be ignored - only identities are used orderExpr.AddOperand(childExpr); orders.Find(orderExpr); object offset = orderExpr.Output; Assert.AreEqual(5, offset); // // Append operation // orderExpr.SetOutput(Operation.ALL, null); orderExpr.GetOperands(Operation.ALL, "Order ID")[0].Output = 1000; orderExpr.GetOperands(Operation.ALL, "Tax Rate")[0].Output = 99.99; Expression custExpr = new Expression("Customer ID", Operation.TUPLE, cust); childExpr = new Expression("ID", Operation.PRIMITIVE, intSet); childExpr.Output = 2000; custExpr.AddOperand(childExpr); childExpr = new Expression("Last Name", Operation.PRIMITIVE, strSet); childExpr.Output = "Lennon"; custExpr.AddOperand(childExpr); orderExpr.AddOperand(custExpr); offset = orders.Append(orderExpr); Assert.AreEqual(40, offset); Assert.AreEqual(1000, orders.GetValue("Order ID", (int)offset)); Assert.AreEqual(99.99, orders.GetValue("Tax Rate", (int)offset)); Assert.AreEqual(2000, cust.GetValue("ID", 15)); Assert.AreEqual("Lennon", cust.GetValue("Last Name", 15)); orders.Find(orderExpr); offset = orderExpr.Output; Assert.AreEqual(orders.Length - 1, offset); // // Product operation and population of a product // Set ods = wsTop.FindSubset("Order Details Status"); // 4 elements loaded Set os = wsTop.FindSubset("Orders Status"); // 3 elements loaded Set newSet = new Set("New Set"); Dim d1 = wsTop.CreateColumn("Order Details Status", newSet, ods, true); d1.Add(); Dim d2 = wsTop.CreateColumn("Orders Status", newSet, os, true); d2.Add(); wsTop.Root.AddSubset(newSet); // Define filter Expression whereExpr = new Expression("EQUAL", Operation.EQ); Expression d1_Expr = Expression.CreateProjectExpression(new List <Dim> { d1, ods.GetGreaterDim("Status ID") }, Operation.DOT); Expression d2_Expr = Expression.CreateProjectExpression(new List <Dim> { d2, os.GetGreaterDim("Status ID") }, Operation.DOT); d1_Expr.GetInputLeaf().Input = new Expression("this", Operation.DOT, newSet); d2_Expr.GetInputLeaf().Input = new Expression("this", Operation.DOT, newSet); whereExpr.Input = d1_Expr; whereExpr.AddOperand(d2_Expr); newSet.TableDefinition.WhereExpression = whereExpr; // Populate and test newSet.TableDefinition.Populate(); Assert.AreEqual(2, newSet.Length); Assert.AreEqual(0, newSet.GetValue("Order Details Status", 0)); Assert.AreEqual(2, newSet.GetValue("Orders Status", 0)); Assert.AreEqual(3, newSet.GetValue("Order Details Status", 1)); Assert.AreEqual(1, newSet.GetValue("Orders Status", 1)); // // Subsetting operation (product with super-dimension) // Set subset_ods = new Set("Subset of ODS"); wsTop.AddTable(subset_ods); // TODO: Check that super-projDim is identity d2 = wsTop.CreateColumn("Orders Status", subset_ods, os, true); d2.Add(); // Define filter // Populate and test subset_ods.TableDefinition.Populate(); Assert.AreEqual(12, subset_ods.Length); // Define filter whereExpr = new Expression("EQUAL", Operation.EQ); d1_Expr = Expression.CreateProjectExpression(new List <Dim> { subset_ods.SuperDim, ods.GetGreaterDim("Status ID") }, Operation.DOT); d2_Expr = Expression.CreateProjectExpression(new List <Dim> { d2, os.GetGreaterDim("Status ID") }, Operation.DOT); d1_Expr.GetInputLeaf().Input = new Expression("this", Operation.DOT, subset_ods); d2_Expr.GetInputLeaf().Input = new Expression("this", Operation.DOT, subset_ods); whereExpr.Input = d1_Expr; whereExpr.AddOperand(d2_Expr); subset_ods.TableDefinition.WhereExpression = whereExpr; subset_ods.TableDefinition.Unpopulate(); subset_ods.TableDefinition.Populate(); Assert.AreEqual(2, subset_ods.Length); }