Search in sources :

Example 1 with OlapElement

use of mondrian.olap.OlapElement in project mondrian by pentaho.

the class DrillThroughFieldListTest method testTwoJoins.

public void testTwoJoins() {
    String mdx = "SELECT\n" + "{[Measures].[Unit Sales], [Measures].[Store Cost]} ON COLUMNS,\n" + "NONEMPTYCROSSJOIN({[Time].[Quarter].[Q1]}," + " {[Product].[Product Name].[Good Imported Beer]}) ON ROWS\n" + "FROM [Sales]";
    Result result = executeQuery(mdx);
    RolapCell rCell = (RolapCell) result.getCell(new int[] { 0, 0 });
    assertTrue(rCell.canDrillThrough());
    OlapElement unitSalesAttribute = result.getAxes()[0].getPositions().get(0).get(0);
    OlapElement storeCostAttribute = result.getAxes()[0].getPositions().get(1).get(0);
    OlapElement quarterAttribute = result.getAxes()[1].getPositions().get(0).get(0).getLevel();
    List<OlapElement> attributes = Arrays.asList(unitSalesAttribute, storeCostAttribute, quarterAttribute);
    String expectedSql;
    switch(getTestContext().getDialect().getDatabaseProduct()) {
        case MARIADB:
        case MYSQL:
            expectedSql = "select\n" + "    time_by_day.quarter as Quarter,\n" + "    sales_fact_1997.unit_sales as Unit Sales,\n" + "    sales_fact_1997.store_cost as Store Cost\n" + "from\n" + "    time_by_day as time_by_day,\n" + "    sales_fact_1997 as sales_fact_1997,\n" + "    product as product\n" + "where\n" + "    sales_fact_1997.time_id = time_by_day.time_id\n" + "and\n" + "    time_by_day.the_year = 1997\n" + "and\n" + "    time_by_day.quarter = 'Q1'\n" + "and\n" + "    sales_fact_1997.product_id = product.product_id\n" + "and\n" + "    product.product_name = 'Good Imported Beer'\n" + "order by\n" + (TestContext.instance().getDialect().requiresOrderByAlias() ? "    Quarter ASC" : "    time_by_day.quarter ASC");
            break;
        case ORACLE:
            expectedSql = "select\n" + "    time_by_day.quarter as Quarter,\n" + "    sales_fact_1997.unit_sales as Unit Sales,\n" + "    sales_fact_1997.store_cost as Store Cost\n" + "from\n" + "    time_by_day time_by_day,\n" + "    sales_fact_1997 sales_fact_1997,\n" + "    product product\n" + "where\n" + "    sales_fact_1997.time_id = time_by_day.time_id\n" + "and\n" + "    time_by_day.the_year = 1997\n" + "and\n" + "    time_by_day.quarter = 'Q1'\n" + "and\n" + "    sales_fact_1997.product_id = product.product_id\n" + "and\n" + "    product.product_name = 'Good Imported Beer'\n" + "order by\n" + "    time_by_day.quarter ASC";
            break;
        default:
            return;
    }
    String actual = rCell.getDrillThroughSQL(attributes, true);
    int expectedRowsNumber = 7;
    context.assertSqlEquals(expectedSql, actual, expectedRowsNumber);
}
Also used : OlapElement(mondrian.olap.OlapElement) Result(mondrian.olap.Result) RolapCell(mondrian.rolap.RolapCell)

Example 2 with OlapElement

use of mondrian.olap.OlapElement in project mondrian by pentaho.

the class DrillThroughFieldListTest method testVirtualCube.

public void testVirtualCube() {
    String mdx = " SELECT\n" + " [Measures].[Unit Sales] ON COLUMNS\n" + " FROM [Warehouse and Sales]\n" + " WHERE [Gender].[F]";
    Result result = executeQuery(mdx);
    RolapCell rCell = (RolapCell) result.getCell(new int[] { 0 });
    assertTrue(rCell.canDrillThrough());
    OlapElement StoreSqftAttribute = result.getAxes()[0].getPositions().get(0).get(0);
    List<OlapElement> attributes = Arrays.asList(StoreSqftAttribute);
    String expectedSql;
    switch(getTestContext().getDialect().getDatabaseProduct()) {
        case MARIADB:
        case MYSQL:
            expectedSql = "select\n" + "    sales_fact_1997.unit_sales as Unit Sales\n" + "from\n" + "    time_by_day as time_by_day,\n" + "    sales_fact_1997 as sales_fact_1997,\n" + "    customer as customer\n" + "where\n" + "    sales_fact_1997.time_id = time_by_day.time_id\n" + "and\n" + "    time_by_day.the_year = 1997\n" + "and\n" + "    sales_fact_1997.customer_id = customer.customer_id\n" + "and\n" + "    customer.gender = 'F'";
            break;
        case ORACLE:
            expectedSql = "select\n" + "    sales_fact_1997.unit_sales as Unit Sales\n" + "from\n" + "    time_by_day time_by_day,\n" + "    sales_fact_1997 sales_fact_1997,\n" + "    customer customer\n" + "where\n" + "    sales_fact_1997.time_id = time_by_day.time_id\n" + "and\n" + "    time_by_day.the_year = 1997\n" + "and\n" + "    sales_fact_1997.customer_id = customer.customer_id\n" + "and\n" + "    customer.gender = 'F'";
            break;
        default:
            return;
    }
    String actual = rCell.getDrillThroughSQL(attributes, true);
    int expectedRowsNumber = 42831;
    context.assertSqlEquals(expectedSql, actual, expectedRowsNumber);
}
Also used : OlapElement(mondrian.olap.OlapElement) Result(mondrian.olap.Result) RolapCell(mondrian.rolap.RolapCell)

Example 3 with OlapElement

use of mondrian.olap.OlapElement in project mondrian by pentaho.

the class DrillThroughFieldListTest method testOneJoinTwoMeasures.

public void testOneJoinTwoMeasures() {
    String mdx = "SELECT\n" + "{[Measures].[Unit Sales], [Measures].[Store Cost]} ON COLUMNS,\n" + "[Time].[Quarter].[Q1] ON ROWS\n" + "FROM [Sales]";
    Result result = executeQuery(mdx);
    RolapCell rCell = (RolapCell) result.getCell(new int[] { 0, 0 });
    assertTrue(rCell.canDrillThrough());
    OlapElement unitSalesAttribute = result.getAxes()[0].getPositions().get(0).get(0);
    OlapElement storeCostAttribute = result.getAxes()[0].getPositions().get(1).get(0);
    OlapElement quarterAttribute = result.getAxes()[1].getPositions().get(0).get(0).getLevel();
    List<OlapElement> attributes = Arrays.asList(unitSalesAttribute, storeCostAttribute, quarterAttribute);
    String expectedSql;
    switch(getTestContext().getDialect().getDatabaseProduct()) {
        case MARIADB:
        case MYSQL:
            expectedSql = "select\n" + "    time_by_day.quarter as Quarter,\n" + "    sales_fact_1997.unit_sales as Unit Sales,\n" + "    sales_fact_1997.store_cost as Store Cost\n" + "from\n" + "    time_by_day as time_by_day,\n" + "    sales_fact_1997 as sales_fact_1997\n" + "where\n" + "    sales_fact_1997.time_id = time_by_day.time_id\n" + "and\n" + "    time_by_day.the_year = 1997\n" + "and\n" + "    time_by_day.quarter = 'Q1'\n" + "order by\n" + (TestContext.instance().getDialect().requiresOrderByAlias() ? "    Quarter ASC" : "    time_by_day.quarter ASC");
            break;
        case ORACLE:
            expectedSql = "select\n" + "    time_by_day.quarter as Quarter,\n" + "    sales_fact_1997.unit_sales as Unit Sales,\n" + "    sales_fact_1997.store_cost as Store Cost\n" + "from\n" + "    time_by_day time_by_day,\n" + "    sales_fact_1997 sales_fact_1997\n" + "where\n" + "    sales_fact_1997.time_id = time_by_day.time_id\n" + "and\n" + "    time_by_day.the_year = 1997\n" + "and\n" + "    time_by_day.quarter = 'Q1'\n" + "order by\n" + "    time_by_day.quarter ASC";
            break;
        default:
            return;
    }
    String actual = rCell.getDrillThroughSQL(attributes, true);
    int expectedRowsNumber = 21588;
    context.assertSqlEquals(expectedSql, actual, expectedRowsNumber);
}
Also used : OlapElement(mondrian.olap.OlapElement) Result(mondrian.olap.Result) RolapCell(mondrian.rolap.RolapCell)

Example 4 with OlapElement

use of mondrian.olap.OlapElement in project mondrian by pentaho.

the class DrillThroughFieldListTest method testOneJoin.

public void testOneJoin() {
    String mdx = "SELECT\n" + "[Measures].[Unit Sales] ON COLUMNS,\n" + "[Time].[Quarter].[Q1] ON ROWS\n" + "FROM [Sales]";
    Result result = executeQuery(mdx);
    RolapCell rCell = (RolapCell) result.getCell(new int[] { 0, 0 });
    assertTrue(rCell.canDrillThrough());
    OlapElement returnMeasureAttribute = result.getAxes()[0].getPositions().get(0).get(0);
    OlapElement returnLevelAttribute = result.getAxes()[1].getPositions().get(0).get(0).getLevel();
    List<OlapElement> attributes = Arrays.asList(returnMeasureAttribute, returnLevelAttribute);
    String expectedSql;
    switch(getTestContext().getDialect().getDatabaseProduct()) {
        case MARIADB:
        case MYSQL:
            expectedSql = "select\n" + "    time_by_day.quarter as Quarter,\n" + "    sales_fact_1997.unit_sales as Unit Sales\n" + "from\n" + "    time_by_day as time_by_day,\n" + "    sales_fact_1997 as sales_fact_1997\n" + "where\n" + "    sales_fact_1997.time_id = time_by_day.time_id\n" + "and\n" + "    time_by_day.the_year = 1997\n" + "and\n" + "    time_by_day.quarter = 'Q1'\n" + "order by\n" + (TestContext.instance().getDialect().requiresOrderByAlias() ? "    Quarter ASC" : "    time_by_day.quarter ASC");
            break;
        case ORACLE:
            expectedSql = "select\n" + "    time_by_day.quarter as Quarter,\n" + "    sales_fact_1997.unit_sales as Unit Sales\n" + "from\n" + "    time_by_day time_by_day,\n" + "    sales_fact_1997 sales_fact_1997\n" + "where\n" + "    sales_fact_1997.time_id = time_by_day.time_id\n" + "and\n" + "    time_by_day.the_year = 1997\n" + "and\n" + "    time_by_day.quarter = 'Q1'\n" + "order by\n" + "    time_by_day.quarter ASC";
            break;
        default:
            return;
    }
    String actual = rCell.getDrillThroughSQL(attributes, true);
    int expectedRowsNumber = 21588;
    context.assertSqlEquals(expectedSql, actual, expectedRowsNumber);
}
Also used : OlapElement(mondrian.olap.OlapElement) Result(mondrian.olap.Result) RolapCell(mondrian.rolap.RolapCell)

Example 5 with OlapElement

use of mondrian.olap.OlapElement in project mondrian by pentaho.

the class DrillThroughFieldListTest method testNoJoin.

public void testNoJoin() {
    String mdx = "SELECT\n" + "Measures.[Store Sqft] on COLUMNS\n" + "FROM [Store]";
    Result result = executeQuery(mdx);
    RolapCell rCell = (RolapCell) result.getCell(new int[] { 0 });
    assertTrue(rCell.canDrillThrough());
    OlapElement StoreSqftAttribute = result.getAxes()[0].getPositions().get(0).get(0);
    List<OlapElement> attributes = Arrays.asList(StoreSqftAttribute);
    String expectedSql;
    switch(getTestContext().getDialect().getDatabaseProduct()) {
        case MARIADB:
        case MYSQL:
            expectedSql = "select\n" + "    store.store_sqft as Store Sqft\n" + "from\n" + "    store as store";
            break;
        case ORACLE:
            expectedSql = "select\n" + "    store.store_sqft as Store Sqft\n" + "from\n" + "    store store";
            break;
        default:
            return;
    }
    String actual = rCell.getDrillThroughSQL(attributes, true);
    int expectedRowsNumber = 25;
    context.assertSqlEquals(expectedSql, actual, expectedRowsNumber);
}
Also used : OlapElement(mondrian.olap.OlapElement) Result(mondrian.olap.Result) RolapCell(mondrian.rolap.RolapCell)

Aggregations

OlapElement (mondrian.olap.OlapElement)6 Result (mondrian.olap.Result)5 RolapCell (mondrian.rolap.RolapCell)5 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 BooleanCalc (mondrian.calc.BooleanCalc)1 Calc (mondrian.calc.Calc)1 DimensionCalc (mondrian.calc.DimensionCalc)1 DoubleCalc (mondrian.calc.DoubleCalc)1 ExpCompiler (mondrian.calc.ExpCompiler)1 HierarchyCalc (mondrian.calc.HierarchyCalc)1 IntegerCalc (mondrian.calc.IntegerCalc)1 LevelCalc (mondrian.calc.LevelCalc)1 ListCalc (mondrian.calc.ListCalc)1 MemberCalc (mondrian.calc.MemberCalc)1 StringCalc (mondrian.calc.StringCalc)1 TupleList (mondrian.calc.TupleList)1 AbstractBooleanCalc (mondrian.calc.impl.AbstractBooleanCalc)1