/* // $Id: //guest/julian_hyde/mondrian/src/main/mondrian/test/Main.java#3 $ // This software is subject to the terms of the Common Public License // Agreement, available at the following URL: // http://www.opensource.org/licenses/cpl.html. // (C) Copyright 1998-2002 Kana Software, Inc. and others. // All Rights Reserved. // You must accept the terms of that agreement to use this software. // // jhyde, 21 January, 1999 */ package mondrian.test; import mondrian.olap.*; import mondrian.rolap.RolapConnection; import mondrian.xom.XOMUtil; import java_cup.runtime.Symbol; import java.io.*; import java.net.URL; import java.util.StringTokenizer; import junit.framework.*; /** * Test-harness for parser. **/ class Main { mondrian.olap.Connection mdxConnection; static public void main(String[] args) { new Main().run(args); } Main() { mondrian.olap.Util.setThreadRes(MondrianResource.instance()); } void run(String[] args) { TestContext.init(); final PrintWriter pw = TestContext.instance().getWriter(); if (args.length == 0) { TestSuite suite = suite(); TestResult result = new TestResult(); result.addListener(new TestListener() { private void report(Test test, String s, Throwable throwable) { pw.print(s + " in test '" + test + "': "); String[] msgs = Util.convertStackToString(throwable); for (int i = 0; i < msgs.length; i++) { String msg = msgs[i]; pw.println(msg); } } public void addError(Test test, Throwable throwable) { report(test, "Error", throwable); } public void addFailure(Test test, AssertionFailedError error) { report(test, "Failure", error); } public void endTest(Test test) { } public void startTest(Test test) { } }); suite.run(result); return; } try { mdxConnection = TestContext.instance().getFoodMartConnection(); Query q = null; for (int i = 0; i < queries.length; i++) { String s = queries[i]; if (s.indexOf("Warehouse") >= 0) { // continue; } if (i >= 8) { // continue; } if (i != 23) { continue; } q = doQuery(pw, s, "Query #" + i); } if (true) { return; } for (int j = 0; j < 100; j++) { int i = j % queries.length; String s = queries[i]; if (s.indexOf("Warehouse") >= 0) { continue; } if (i >= 8) { continue; } q = doQuery(pw, s, "Query #" + i); } Level level = q.getCube().lookupLevel( "[Product].[Product Department]"); Query q2 = (Query) q.clone(); q2.addLevelToAxis(0, level); pw.println(q2.toPlatoMdx()); } catch (Throwable e) { String[] errors = Util.convertStackToString(e); for (int i = 0; i < errors.length; i++) { pw.println(errors[i]); } } finally { if (mdxConnection != null) { mdxConnection.close(); } pw.flush(); } } private Query doQuery(PrintWriter pw, String s, String desc) { pw.println(); pw.println(desc); Query q = mdxConnection.parseQuery(s); pw.println(q.toPlatoMdx()); Result result = mdxConnection.execute(q); result.print(pw); // execute it again, to see if the caching works result = mdxConnection.execute(q); // result.print(pw); return q; } static String[] queries = new String[] { // #0 "select {[Measures].[Unit Sales]} on columns\r\n" + " from Sales", // mdx sample #1 "select\r\n" + " {[Measures].[Unit Sales]} on columns,\r\n" + " order(except([Promotion Media].[Media Type].members,{[Promotion Media].[Media Type].[No Media]}),[Measures].[Unit Sales],DESC) on rows\r\n" + "from Sales ", // mdx sample #2 "select\r\n" + " { [Measures].[Units Shipped], [Measures].[Units Ordered] } on columns,\r\n" + " NON EMPTY [Store].[Store Name].members on rows\r\n" + "from Warehouse", // mdx sample #3 "with member [Measures].[Store Sales Last Period] as '([Measures].[Store Sales], Time.PrevMember)'\r\n" + "select\r\n" + " {[Measures].[Store Sales Last Period]} on columns,\r\n" + " {TopCount([Product].[Product Department].members,5, [Measures].[Store Sales Last Period])} on rows\r\n" + "from Sales\r\n" + "where ([Time].[1998])", // mdx sample #4 "with member [Measures].[Total Store Sales] as 'Sum(YTD(),[Measures].[Store Sales])'\r\n" + "select\r\n" + " {[Measures].[Total Store Sales]} on columns,\r\n" + " {TopCount([Product].[Product Department].members,5, [Measures].[Total Store Sales])} on rows\r\n" + "from Sales\r\n" + "where ([Time].[1997].[Q2].[4])", // mdx sample #5 "with member [Measures].[Store Profit Rate] as '([Measures].[Store Sales]-[Measures].[Store Cost])/[Measures].[Store Cost]', format = '#.00%'\r\n" + "select\r\n" + " {[Measures].[Store Cost],[Measures].[Store Sales],[Measures].[Store Profit Rate]} on columns,\r\n" + " Order([Product].[Product Department].members, [Measures].[Store Profit Rate], BDESC) on rows\r\n" + "from Sales\r\n" + "where ([Time].[1997])", // mdx sample #6 "with\r\n" + " member [Product].[All Products].[Drink].[Percent of Alcoholic Drinks] as '[Product].[All Products].[Drink].[Alcoholic Beverages]/[Product].[All Products].[Drink]', format = '#.00%'\r\n" + "select\r\n" + " { [Product].[All Products].[Drink].[Percent of Alcoholic Drinks] } on columns,\r\n" + " order([Customers].[All Customers].[USA].[WA].Children, [Product].[All Products].[Drink].[Percent of Alcoholic Drinks],BDESC ) on rows\r\n" + "from Sales\r\n" + "where ( [Measures].[Unit Sales] )", // mdx sample #7 "with member [Measures].[Accumulated Sales] as 'Sum(YTD(),[Measures].[Store Sales])'\r\n" + "select\r\n" + " {[Measures].[Store Sales],[Measures].[Accumulated Sales]} on columns,\r\n" + " {Descendants([Time].[1997],[Time].[Month])} on rows\r\n" + "from Sales", // #8 "select\r\n" + " {[Measures].[Unit Sales], [Measures].[Ever]} on columns,\r\n" + " [Gender].members on rows\r\n" + "from Sales", // #9 "with\r\n" + " member [Product].[Non dairy] as '[Product].[All Products] - [Product].[Food].[Dairy]'\r\n" + " member [Measures].[Dairy ever] as 'sum([Time].members, ([Measures].[Unit Sales],[Product].[Food].[Dairy]))'\r\n" + " set [Customers who never bought dairy] as 'filter([Customers].members, [Measures].[Dairy ever] = 0)'\r\n" + "select\r\n" + " {[Measures].[Unit Sales], [Measures].[Dairy ever]} on columns,\r\n" + " [Customers who never bought dairy] on rows\r\n" + "from Sales\r\n", // #10 "select {[Has bought dairy].members} on columns,\r\n" + " {[Customers].[USA]} on rows\r\n" + "from Sales\r\n" + "where ([Measures].[Unit Sales])", // #11 "WITH\r\n" + " MEMBER [Measures].[StoreType] AS \r\n" + " '[Store].CurrentMember.Properties(\"Store Type\")',\r\n" + " SOLVE_ORDER = 2\r\n" + " MEMBER [Measures].[ProfitPct] AS \r\n" + " 'Val((Measures.[Store Sales] - Measures.[Store Cost]) / Measures.[Store Sales])',\r\n" + " SOLVE_ORDER = 1, FORMAT_STRING = 'Percent'\r\n" + "SELECT\r\n" + " { [Store].[Store Name].Members} ON COLUMNS,\r\n" + " { [Measures].[Store Sales], [Measures].[Store Cost], [Measures].[StoreType],\r\n" + " [Measures].[ProfitPct] } ON ROWS\r\n" + "FROM Sales", // #12 "WITH\r\n" + " MEMBER [Product].[Beer and Wine].[BigSeller] AS\r\n" + " 'IIf([Product].[Beer and Wine] > 100, \"Yes\",\"No\")'\r\n" + "SELECT\r\n" + " {[Product].[BigSeller]} ON COLUMNS,\r\n" + " {Store.[Store Name].Members} ON ROWS\r\n" + "FROM Sales", // #13 "WITH\r\n" + " MEMBER [Measures].[ProfitPct] AS \r\n" + " 'Val((Measures.[Store Sales] - Measures.[Store Cost]) / Measures.[Store Sales])',\r\n" + " SOLVE_ORDER = 1, FORMAT_STRING = 'Percent'\r\n" + " MEMBER [Measures].[ProfitValue] AS \r\n" + " '[Measures].[Store Sales] * [Measures].[ProfitPct]',\r\n" + " SOLVE_ORDER = 2, FORMAT_STRING = 'Currency'\r\n" + "SELECT\r\n" + " { [Store].[Store Name].Members} ON COLUMNS,\r\n" + " { [Measures].[Store Sales], [Measures].[Store Cost], [Measures].[ProfitValue],\r\n" + " [Measures].[ProfitPct] } ON ROWS\r\n" + "FROM Sales", // #14: cyclical calculated members "WITH\r\n" + " MEMBER [Product].[X] AS '[Product].[Y]'\r\n" + " MEMBER [Product].[Y] '[Product].[X]'\r\n" + "SELECT\r\n" + " {[Product].[X]} ON COLUMNS,\r\n" + " {Store.[Store Name].Members} ON ROWS\r\n" + "FROM Sales", // #15 "WITH MEMBER MEASURES.ProfitPercent AS\r\n" + " '([Measures].[Store Sales]-[Measures].[Store Cost])/([Measures].[Store Cost])',\r\n" + " FORMAT_STRING = '#.00%', SOLVE_ORDER = 1\r\n" + " MEMBER [Time].[First Half 97] AS '[Time].[1997].[Q1] + [Time].[1997].[Q2]'\r\n" + " MEMBER [Time].[Second Half 97] AS '[Time].[1997].[Q3] + [Time].[1997].[Q4]'\r\n" + " SELECT {[Time].[First Half 97],\r\n" + " [Time].[Second Half 97],\r\n" + " [Time].[1997].CHILDREN} ON COLUMNS,\r\n" + " {[Store].[Store Country].[USA].CHILDREN} ON ROWS\r\n" + " FROM [Sales]\r\n" + " WHERE (MEASURES.ProfitPercent)", // #16 (= mdx sample #7, but uses virtual cube) "with member [Measures].[Accumulated Sales] as 'Sum(YTD(),[Measures].[Store Sales])'\r\n" + "select\r\n" + " {[Measures].[Store Sales],[Measures].[Accumulated Sales]} on columns,\r\n" + " {Descendants([Time].[1997],[Time].[Month])} on rows\r\n" + "from [Warehouse and Sales]", // #17 Virtual cube. Note that Unit Sales is independent of Warehouse. "select CrossJoin(\r\n"+ " {[Warehouse].DefaultMember, [Warehouse].[USA].children},\r\n" + " {[Measures].[Unit Sales], [Measures].[Units Shipped]}) on columns,\r\n" + " [Time].children on rows\r\n" + "from [Warehouse and Sales]", // #18 bug: should allow dimension to be used as shorthand for member "select {[Measures].[Unit Sales]} on columns,\r\n" + " {[Store], [Store].children} on rows\r\n" + "from [Sales]", // #19 bug: should allow 'members(n)' (and do it efficiently) "select {[Measures].[Unit Sales]} on columns,\r\n" + " {[Customers].members(0)} on rows\r\n" + "from [Sales]", // #20: taglib.jsp query1 "select\r\n" + " {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns,\r\n" + " CrossJoin(\r\n" + " { [Promotion Media].[All Promotion Media].[Radio],\r\n" + " [Promotion Media].[All Promotion Media].[TV],\r\n" + " [Promotion Media].[All Promotion Media].[Sunday Paper],\r\n" + " [Promotion Media].[All Promotion Media].[Street Handout] },\r\n" + " [Product].[All Products].[Drink].children) on rows\r\n" + "from Sales\r\n" + "where ([Time].[1997])", // #21: taglib.jsp query2 "select\r\n" + " [Product].[All Products].[Drink].children on rows,\r\n" + " CrossJoin(\r\n" + " {[Measures].[Unit Sales], [Measures].[Store Sales]},\r\n" + " { [Promotion Media].[All Promotion Media].[Radio],\r\n" + " [Promotion Media].[All Promotion Media].[TV],\r\n" + " [Promotion Media].[All Promotion Media].[Sunday Paper],\r\n" + " [Promotion Media].[All Promotion Media].[Street Handout] }\r\n" + " ) on columns\r\n" + "from Sales\r\n" + "where ([Time].[1997])", // #22: taglib.jsp query3 "select\r\n" + " {[Measures].[Unit Sales], [Measures].[Store Sales]} on columns,\r\n" + " Order([Product].[Product Department].members, [Measures].[Store Sales], DESC) on rows\r\n" + "from Sales", // #23: taglib.jsp query4 "select\r\n" + " [Product].[All Products].[Drink].children on columns\r\n" + "from Sales\r\n" + "where ([Measures].[Unit Sales], [Promotion Media].[All Promotion Media].[Street Handout], [Time].[1997])", // #24: taglib.jsp query5 "select\r\n" + " NON EMPTY CrossJoin([Product].[All Products].[Drink].children, [Customers].[All Customers].[USA].[WA].Children) on rows,\r\n" + " CrossJoin(\r\n" + " {[Measures].[Unit Sales], [Measures].[Store Sales]},\r\n" + " { [Promotion Media].[All Promotion Media].[Radio],\r\n" + " [Promotion Media].[All Promotion Media].[TV],\r\n" + " [Promotion Media].[All Promotion Media].[Sunday Paper],\r\n" + " [Promotion Media].[All Promotion Media].[Street Handout] }\r\n" + " ) on columns\r\n" + "from Sales\r\n" + "where ([Time].[1997])", // #25: taglib.jsp query6 "select from Sales\r\n" + "where ([Measures].[Store Sales], [Time].[1997], [Promotion Media].[All Promotion Media].[TV])", }; /** * Creates a TestSuite to test the whole of mondrian. */ public static TestSuite suite() { TestSuite suite = new TestSuite(); suite.addTest(new FoodMartTestCase("non empty 1") { protected void runTest() throws Throwable { assertSize( "select\r\n" + " NON EMPTY CrossJoin({[Product].[All Products].[Drink].Children},\r\n" + " {[Customers].[All Customers].[USA].[WA].[Bellingham]}) on rows,\r\n" + " CrossJoin(\r\n" + " {[Measures].[Unit Sales], [Measures].[Store Sales]},\r\n" + " { [Promotion Media].[All Promotion Media].[Radio],\r\n" + " [Promotion Media].[All Promotion Media].[TV],\r\n" + " [Promotion Media].[All Promotion Media].[Sunday Paper],\r\n" + " [Promotion Media].[All Promotion Media].[Street Handout] }\r\n" + " ) on columns\r\n" + "from Sales\r\n" + "where ([Time].[1997])", 8, 2); }}); suite.addTest(new FoodMartTestCase("non empty 2") { protected void runTest() throws Throwable { assertSize( "select\r\n" + " NON EMPTY CrossJoin(\r\n" + " {[Product].[All Products].Children},\r\n" + " {[Customers].[All Customers].[USA].[WA].[Bellingham]}) on rows,\r\n" + " NON EMPTY CrossJoin(\r\n" + " {[Measures].[Unit Sales]},\r\n" + " { [Promotion Media].[All Promotion Media].[Cash Register Handout],\r\n" + " [Promotion Media].[All Promotion Media].[Sunday Paper],\r\n" + " [Promotion Media].[All Promotion Media].[Street Handout] }\r\n" + " ) on columns\r\n" + "from Sales\r\n" + "where ([Time].[1997])", 2, 2); }}); suite.addTest(new FoodMartTestCase("1 dimensional query with compound slicer") { protected void runTest() throws Throwable { Result result = runQuery( "select\r\n" + " [Product].[All Products].[Drink].children on columns\r\n" + "from Sales\r\n" + "where ([Measures].[Unit Sales], [Promotion Media].[All Promotion Media].[Street Handout], [Time].[1997])"); assertTrue(result.getAxes().length == 1); assertTrue(result.getAxes()[0].positions.length == 3); assertTrue(result.getSlicerAxis().positions.length == 1); assertTrue(result.getSlicerAxis().positions[0].members.length == 3); }}); return suite; } // testcase: make sure that slicer is in force when expression is applied // on axis, E.g. select filter([Customers].members, [Unit Sales] > 100) // from sales where ([Time].[1998]) } // End Main.java
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 1801 | Julian Hyde |
saffron: add ObjectSchema; rules can now be matched more than once; started to implement correlations in queries in from list. |
||
#7 | 1788 | Julian Hyde | mondrian: More of the same. | ||
#6 | 1787 | Julian Hyde |
mondrian: Organize tests into more JUnit-friendly structure. Get properties from TestContext.getProperties. Read properties from mondrian.properties, if it exists. Add Paul's code for <Member>.Hierarchy, disabled. |
||
#5 | 1611 | Julian Hyde |
mondrian: Add XOMGen ant task; Improve JavaCUP ant task; Upgrade to JavaCUP 0.10k beta 2; Fix test oopses. |
||
#4 | 1609 | Julian Hyde |
mondrian: Forgot a couple of files last change. Unit tests for builtin functions. Don't return null members (e.g. [Gender].[F].PrevMember). |
||
#3 | 1603 | Julian Hyde |
mondrian: Add Andreas' taglib; Rename 'mondrian.rolap.Util.assert' to 'assertTrue', because 'assert' is a keyword in jdk 1.4; Fix 'NON EMPTY'; JUnit framework for tests; Add Oracle dataset. |
||
#2 | 1576 | Julian Hyde |
mondrian: fix dataset (add column customer.ordinal); create dataset for oracle; get queries working on oracle; get format strings working; refactor out new packages mondrian.rolap.agg and mondrian.rolap.sql. |
||
#1 | 1453 | Julian Hyde | mondrian: first source check-in |