public void TableLoadTest() { // // Prepare table schema // SetTop top = new SetTop("Top"); Set setInteger = top.GetPrimitive("Integer"); Set setDouble = top.GetPrimitive("Double"); Set setString = top.GetPrimitive("String"); // Insert table Set t1 = new Set("t1"); top.Root.AddSubset(t1); Dim orders = new DimPrimitive <int>("orders", t1, setInteger); orders.Add(); Dim revenue = new DimPrimitive <double>("revenue", t1, setDouble); revenue.Add(); Dim name = new DimPrimitive <string>("name", t1, setString); name.Add(); // // Insert new data // t1.Append(); Assert.AreEqual(1, t1.Length); t1.SetValue("orders", 0, 10); t1.SetValue("revenue", 0, 12345.67); t1.SetValue("name", 0, "Smith"); Assert.AreEqual(10, t1.GetValue("orders", 0)); Assert.AreEqual(12345.67, t1.GetValue("revenue", 0)); Assert.AreEqual("Smith", t1.GetValue("name", 0)); }
public void ArithmeticTest() { // 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"); Set doubleSet = wsTop.GetPrimitive("Double"); // // Create derived dimensions // // "List Price", "Standard Cost", "Target Level" // Column names are function names and they have to be assign to expression node names (DOT) // But where is 'this' variable and 'this' set? This set is Input.OutputSet. And the function will be applied to whatever is stored in Input.Output (interpreted as offset). // So Input.Output has to be assigned explicitly offset in a loop. Or we need to store a variable 'this' which, when evaluated, writes its current value to Input.Output. // 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> { d1 }, Operation.DOT); Expression d2_Expr = Expression.CreateProjectExpression(new List <Dim> { d2 }, Operation.DOT); Expression d3_Expr = Expression.CreateProjectExpression(new List <Dim> { d3 }, Operation.DOT); // Add derived dimension Dim derived1 = wsTop.CreateColumn("Derived Column", products, doubleSet, true); derived1.Add(); Expression arithmExpr = new Expression("MINUS", Operation.SUB); arithmExpr.Input = d1_Expr; Expression plusExpr = new Expression("PLUS", Operation.ADD); plusExpr.Input = d2_Expr; plusExpr.AddOperand(d3_Expr); arithmExpr.AddOperand(plusExpr); var funcExpr1 = ExpressionScope.CreateFunctionDeclaration("Derived Column", "Products", "Double"); funcExpr1.Statements[0].Input = arithmExpr; // Return statement funcExpr1.ResolveFunction(wsTop); funcExpr1.Resolve(); derived1.SelectExpression = funcExpr1; // Update derived1.Evaluate(); Assert.AreEqual(-32.5, products.GetValue("Derived Column", 2)); // // Another (simpler) test // // Add derived dimension Dim derived2 = wsTop.CreateColumn("Derived Column 2", products, doubleSet, true); derived2.Add(); plusExpr = new Expression("PLUS", Operation.ADD); plusExpr.Input = d1_Expr; plusExpr.AddOperand(d1_Expr); var funcExpr2 = ExpressionScope.CreateFunctionDeclaration("Derived Column 2", "Products", "Double"); funcExpr2.Statements[0].Input = plusExpr; // Return statement funcExpr2.ResolveFunction(wsTop); funcExpr2.Resolve(); derived2.SelectExpression = funcExpr2; // plusExpr; // Update derived2.Evaluate(); Assert.AreEqual(60.0, products.GetValue("Derived Column 2", 2)); }
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); }
public void RecommendAggregationTest() { // Create Oldedb top set SetTopOledb dbTop = new SetTopOledb("Root"); 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 cust = wsTop.FindSubset("Customers"); Set prod = wsTop.FindSubset("Products"); Set doubleSet = wsTop.GetPrimitive("Double"); // // Test aggregation recommendations. From Customers to Product // Grouping (deproject) expression: (Customers) <- (Orders) <- (Order Details) // Measure (project) tupleExpr+ession: (Order Details) -> (Product) -> List Price // RecommendedAggregations recoms = new RecommendedAggregations(); recoms.SourceSet = cust; recoms.TargetSet = prod; recoms.FactSet = null; // Any recoms.Recommend(); recoms.GroupingPaths.SelectedFragment = recoms.GroupingPaths.Alternatives[0]; recoms.FactSets.SelectedFragment = recoms.FactSets.Alternatives[0]; recoms.MeasurePaths.SelectedFragment = recoms.MeasurePaths.Alternatives[0]; recoms.MeasureDimensions.SelectedFragment = recoms.MeasureDimensions.Alternatives.First(f => ((Dim)f.Fragment).Name == "List Price"); recoms.AggregationFunctions.SelectedFragment = recoms.AggregationFunctions.Alternatives.First(f => f.Fragment == "SUM"); Dim derived1 = wsTop.CreateColumn("Average List Price", cust, doubleSet, true); derived1.Add(); Expression aggreExpr = recoms.GetExpression(); var funcExpr = ExpressionScope.CreateFunctionDeclaration("Average List Price", cust.Name, doubleSet.Name); funcExpr.Statements[0].Input = aggreExpr; // Return statement funcExpr.ResolveFunction(wsTop); funcExpr.Resolve(); derived1.SelectExpression = funcExpr; // Update derived1.Evaluate(); Assert.AreEqual(64.0, cust.GetValue("Average List Price", 2)); }
public void SymbolResolutionTest() { ExpressionScope ast; // // Test schema. "Set A" -> b/c -> "Set B" -> d/i -> "Double"/"Integer" // SetTop top = new SetTop("Top"); Set setInteger = top.GetPrimitive("Integer"); Set setDouble = top.GetPrimitive("Double"); Set setA = new Set("Set A"); top.Root.AddSubset(setA); Set setB = new Set("Set B"); top.Root.AddSubset(setB); Dim dimB = top.CreateColumn("b", setA, setB, true); dimB.Add(); Dim dimC = top.CreateColumn("Function c", setA, setB, true); dimC.Add(); Dim dimD = top.CreateColumn("d", setB, setDouble, true); dimD.Add(); Dim dimI = top.CreateColumn("i", setB, setInteger, true); dimI.Add(); // // Test symbol resolution, type resolution and validation // string functionStr = "[Set B] [Function c]([Set A] this, [Integer] [param 2], [Set B] [param 3]) { return b().d() * this.b().d() + [param 2] / [param 3] <- b(); } "; ast = (ExpressionScope)BuildFunction(functionStr); // Bind ast to the real schema ast.ResolveFunction(top); Assert.AreEqual(ast.Input.OutputSet, setA); Assert.AreEqual(ast.Operands[0].OutputSet, setInteger); Assert.AreEqual(ast.Operands[1].OutputSet, setB); Assert.AreEqual(ast.OutputSet, setB); Assert.AreEqual(ast.Dimension, dimC); // Resolve all symboles used in the function definition ast.Resolve(); Assert.AreEqual(ast.Statements[0].Input.Operands[0].Operands[0].OutputSet, setDouble); Assert.AreEqual(ast.Statements[0].Input.Operands[0].Operands[0].Input.OutputSet, setB); Assert.AreEqual(ast.Statements[0].Input.Operands[0].Operands[0].Input.Input.OutputSet, setA); Assert.AreEqual(ast.Statements[0].Input.Operands[0].Operands[1].Input.Input.OutputSet, setA); Assert.AreEqual(ast.Statements[0].Input.Operands[1].Operands[0].OutputSet, setInteger); Assert.AreEqual(ast.Statements[0].Input.Operands[1].Operands[1].OutputSet, setA); Assert.AreEqual(ast.Statements[0].Input.Operands[1].Operands[1].Input.OutputSet, setB); }