Search in sources :

Example 91 with Result

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

the class BasicQueryTest method testMemberWithNullKey.

/**
 * There are cross database order issues in this test.
 * <p>
 * MySQL and Access show the rows as:
 * <p>
 * [Store Size in SQFT].[All Store Size in SQFTs] [Store Size in SQFT].[null] [Store Size in SQFT].[<each distinct
 * store size>]
 * <p>
 * Postgres shows:
 * <p>
 * [Store Size in SQFT].[All Store Size in SQFTs] [Store Size in SQFT].[<each distinct store size>] [Store Size in
 * SQFT].[null]
 * <p>
 * The test failure is due to some inherent differences in the way Postgres orders NULLs in a result set, compared
 * with MySQL and Access.
 * <p>
 * From the MySQL 4.X manual:
 * <p>
 * When doing an ORDER BY, NULL values are presented first if you do ORDER BY ... ASC and last if you do ORDER BY ...
 * DESC.
 * <p>
 * From the Postgres 8.0 manual:
 * <p>
 * The null value sorts higher than any other value. In other words, with ascending sort order, null values sort at
 * the end, and with descending sort order, null values sort at the beginning.
 * <p>
 * Oracle also sorts nulls high by default.
 * <p>
 * So, this test has expected results that vary depending on whether the database is being used sorts nulls high or
 * low.
 */
public void testMemberWithNullKey() {
    if (!isDefaultNullMemberRepresentation()) {
        return;
    }
    Result result = executeQuery("select {[Measures].[Unit Sales]} on columns,\n" + "{[Store Size in SQFT].members} on rows\n" + "from Sales");
    String resultString = TestContext.toString(result);
    resultString = Pattern.compile("\\.0\\]").matcher(resultString).replaceAll("]");
    // The members function hierarchizes its results, so nulls should
    // sort high, regardless of DBMS. Note that Oracle's driver says that
    // NULLs sort low, but it's lying.
    final boolean nullsSortHigh = false;
    int row = 0;
    final String expected = "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[Unit Sales]}\n" + "Axis #2:\n" + "{[Store Size in SQFT].[All Store Size in SQFTs]}\n" + // null is at the start in order under DBMSs that sort null low
    (!nullsSortHigh ? "{[Store Size in SQFT].[#null]}\n" : "") + "{[Store Size in SQFT].[20319]}\n" + "{[Store Size in SQFT].[21215]}\n" + "{[Store Size in SQFT].[22478]}\n" + "{[Store Size in SQFT].[23112]}\n" + "{[Store Size in SQFT].[23593]}\n" + "{[Store Size in SQFT].[23598]}\n" + "{[Store Size in SQFT].[23688]}\n" + "{[Store Size in SQFT].[23759]}\n" + "{[Store Size in SQFT].[24597]}\n" + "{[Store Size in SQFT].[27694]}\n" + "{[Store Size in SQFT].[28206]}\n" + "{[Store Size in SQFT].[30268]}\n" + "{[Store Size in SQFT].[30584]}\n" + "{[Store Size in SQFT].[30797]}\n" + "{[Store Size in SQFT].[33858]}\n" + "{[Store Size in SQFT].[34452]}\n" + "{[Store Size in SQFT].[34791]}\n" + "{[Store Size in SQFT].[36509]}\n" + "{[Store Size in SQFT].[38382]}\n" + "{[Store Size in SQFT].[39696]}\n" + // null is at the end in order for DBMSs that sort nulls high
    (nullsSortHigh ? "{[Store Size in SQFT].[#null]}\n" : "") + "Row #" + row++ + ": 266,773\n" + (!nullsSortHigh ? "Row #" + row++ + ": 39,329\n" : "") + "Row #" + row++ + ": 26,079\n" + "Row #" + row++ + ": 25,011\n" + "Row #" + row++ + ": 2,117\n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": 25,663\n" + "Row #" + row++ + ": 21,333\n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": 41,580\n" + "Row #" + row++ + ": 2,237\n" + "Row #" + row++ + ": 23,591\n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": 35,257\n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": \n" + "Row #" + row++ + ": 24,576\n" + (nullsSortHigh ? "Row #" + row++ + ": 39,329\n" : "");
    TestContext.assertEqualsVerbose(expected, resultString);
}
Also used : Result(mondrian.olap.Result)

Example 92 with Result

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

the class BasicQueryTest method testNonEmptyNonEmptyCrossJoin2.

public void testNonEmptyNonEmptyCrossJoin2() {
    TestContext.instance().flushSchemaCache();
    Result result = executeQuery("select {[Education Level].[All Education Levels].[Graduate Degree]} on columns,\n" + "   NonEmptyCrossJoin(\n" + "      {[Store Type].[Store Type].members},\n" + "      {[Promotions].[Promotion Name].members})\n" + "   on rows\n" + "from Sales\n" + "where ([Customers].[All Customers].[USA].[WA].[Anacortes])\n");
    Axis a = result.getAxes()[1];
    assertEquals(10, a.getPositions().size());
}
Also used : Axis(mondrian.olap.Axis) Result(mondrian.olap.Result)

Example 93 with Result

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

the class BasicQueryTest method testAllMemberCaption.

public void testAllMemberCaption() {
    TestContext testContext = TestContext.instance().createSubstitutingCube("Sales", "<Dimension name=\"Gender3\" foreignKey=\"customer_id\">\n" + "  <Hierarchy hasAll=\"true\" allMemberName=\"All Gender\"\n" + " allMemberCaption=\"Frauen und Maenner\" primaryKey=\"customer_id\">\n" + "  <Table name=\"customer\"/>\n" + "    <Level name=\"Gender\" column=\"gender\" uniqueMembers=\"true\"/>\n" + "  </Hierarchy>\n" + "</Dimension>");
    String mdx = "select {[Gender3].[All Gender]} on columns from Sales";
    Result result = testContext.executeQuery(mdx);
    Axis axis0 = result.getAxes()[0];
    Position pos0 = axis0.getPositions().get(0);
    Member allGender = pos0.get(0);
    String caption = allGender.getCaption();
    Assert.assertEquals(caption, "Frauen und Maenner");
}
Also used : Position(mondrian.olap.Position) Member(mondrian.olap.Member) Axis(mondrian.olap.Axis) Result(mondrian.olap.Result)

Example 94 with Result

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

the class BasicQueryTest method testGetContext.

/**
 * Unit test for the {@link Cell#getContextMember(mondrian.olap.Hierarchy)} method.
 */
public void testGetContext() {
    if (!MondrianProperties.instance().SsasCompatibleNaming.get()) {
        return;
    }
    Result result = getTestContext().executeQuery("select [Gender].Members on 0,\n" + "[Time].[Weekly].[1997].[6].Children on 1\n" + "from [Sales]\n" + "where [Marital Status].[S]");
    final Cell cell = result.getCell(new int[] { 0, 0 });
    final Map<String, Hierarchy> hierarchyMap = new HashMap<String, Hierarchy>();
    for (Dimension dimension : result.getQuery().getCube().getDimensions()) {
        for (Hierarchy hierarchy : dimension.getHierarchies()) {
            hierarchyMap.put(hierarchy.getUniqueName(), hierarchy);
        }
    }
    assertEquals("[Measures].[Unit Sales]", cell.getContextMember(hierarchyMap.get("[Measures]")).getUniqueName());
    assertEquals("[Time].[1997]", cell.getContextMember(hierarchyMap.get("[Time]")).getUniqueName());
    assertEquals("[Time].[Weekly].[1997].[6].[1]", cell.getContextMember(hierarchyMap.get("[Time].[Weekly]")).getUniqueName());
    assertEquals("[Gender].[All Gender]", cell.getContextMember(hierarchyMap.get("[Gender]")).getUniqueName());
    assertEquals("[Marital Status].[S]", cell.getContextMember(hierarchyMap.get("[Marital Status]")).getUniqueName());
}
Also used : Hierarchy(mondrian.olap.Hierarchy) HashMap(java.util.HashMap) Dimension(mondrian.olap.Dimension) Cell(mondrian.olap.Cell) Result(mondrian.olap.Result)

Example 95 with Result

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

the class BasicQueryTest method testNonEmptyNonEmptyCrossJoin1.

/**
 * NonEmptyCrossJoin() is not the same as NON EMPTY CrossJoin() because it's evaluated independently of the other
 * axes. (see http://blogs.msdn.com/bi_systems/articles/162841.aspx)
 */
public void testNonEmptyNonEmptyCrossJoin1() {
    TestContext.instance().flushSchemaCache();
    Result result = executeQuery("select {[Education Level].[All Education Levels].[Graduate Degree]} on columns,\n" + "   CrossJoin(\n" + "      {[Store Type].[Store Type].members},\n" + "      {[Promotions].[Promotion Name].members})\n" + "   on rows\n" + "from Sales\n" + "where ([Customers].[All Customers].[USA].[WA].[Anacortes])\n");
    Axis a = result.getAxes()[1];
    assertEquals(306, a.getPositions().size());
}
Also used : Axis(mondrian.olap.Axis) Result(mondrian.olap.Result)

Aggregations

Result (mondrian.olap.Result)113 Axis (mondrian.olap.Axis)24 Member (mondrian.olap.Member)10 Test (org.junit.Test)10 Cell (mondrian.olap.Cell)9 Connection (mondrian.olap.Connection)9 Query (mondrian.olap.Query)9 Position (mondrian.olap.Position)8 TestContext (mondrian.test.TestContext)7 ArrayList (java.util.ArrayList)5 MondrianProperties (mondrian.olap.MondrianProperties)5 OlapElement (mondrian.olap.OlapElement)5 RolapCell (mondrian.rolap.RolapCell)5 NonEmptyResult (mondrian.rolap.RolapConnection.NonEmptyResult)5 Execution (mondrian.server.Execution)5 Dialect (mondrian.spi.Dialect)5 OlapConnection (org.olap4j.OlapConnection)5 List (java.util.List)4 ResultBase (mondrian.olap.ResultBase)4 Evaluator (mondrian.olap.Evaluator)3