Search in sources :

Example 81 with TestContext

use of mondrian.test.TestContext in project mondrian by pentaho.

the class FunctionTest method testComplexSlicer_CalcBase.

public void testComplexSlicer_CalcBase() {
    TestContext context = getTestContext().createSubstitutingCube("Sales", null, "<CalculatedMember " + "name='H1 1997' " + "formula='Aggregate([Time].[1997].[Q1]:[Time].[1997].[Q2])' " + "dimension='Time' />");
    String query = "SELECT " + "{[Measures].[Customer Count]} ON 0, " + "{[Education Level].Members} ON 1 " + "FROM [Sales] " + "WHERE {[Time].[H1 1997],[Time].[1998].[Q1]}";
    String expectedResult = "Axis #0:\n" + "{[Time].[H1 1997]}\n" + "{[Time].[1998].[Q1]}\n" + "Axis #1:\n" + "{[Measures].[Customer Count]}\n" + "Axis #2:\n" + "{[Education Level].[All Education Levels]}\n" + "{[Education Level].[Bachelors Degree]}\n" + "{[Education Level].[Graduate Degree]}\n" + "{[Education Level].[High School Degree]}\n" + "{[Education Level].[Partial College]}\n" + "{[Education Level].[Partial High School]}\n" + "Row #0: 4,257\n" + "Row #1: 1,109\n" + "Row #2: 240\n" + "Row #3: 1,237\n" + "Row #4: 394\n" + "Row #5: 1,277\n";
    context.assertQueryReturns(query, expectedResult);
}
Also used : TestContext(mondrian.test.TestContext)

Example 82 with TestContext

use of mondrian.test.TestContext in project mondrian by pentaho.

the class FunctionTest method testComplexSlicerWith_CalcBase.

public void testComplexSlicerWith_CalcBase() {
    TestContext context = getTestContext();
    String query = "with " + "member [Time].[H1 1997] as 'Aggregate([Time].[1997].[Q1] : [Time].[1997].[Q2])', $member_scope = \"CUBE\", MEMBER_ORDINAL = 6 " + "SELECT " + "{[Measures].[Customer Count]} ON 0, " + "{[Education Level].Members} ON 1 " + "FROM [Sales] " + "WHERE {[Time].[H1 1997],[Time].[1998].[Q1]}";
    String expectedResult = "Axis #0:\n" + "{[Time].[H1 1997]}\n" + "{[Time].[1998].[Q1]}\n" + "Axis #1:\n" + "{[Measures].[Customer Count]}\n" + "Axis #2:\n" + "{[Education Level].[All Education Levels]}\n" + "{[Education Level].[Bachelors Degree]}\n" + "{[Education Level].[Graduate Degree]}\n" + "{[Education Level].[High School Degree]}\n" + "{[Education Level].[Partial College]}\n" + "{[Education Level].[Partial High School]}\n" + "Row #0: 4,257\n" + "Row #1: 1,109\n" + "Row #2: 240\n" + "Row #3: 1,237\n" + "Row #4: 394\n" + "Row #5: 1,277\n";
    context.assertQueryReturns(query, expectedResult);
}
Also used : TestContext(mondrian.test.TestContext)

Example 83 with TestContext

use of mondrian.test.TestContext in project mondrian by pentaho.

the class FunctionTest method testDefaultMember.

public void testDefaultMember() {
    // [Time] has no default member and no all, so the default member is
    // the first member of the first level.
    Result result = executeQuery("select {[Time].[Time].DefaultMember} on columns\n" + "from Sales");
    Assert.assertEquals("1997", result.getAxes()[0].getPositions().get(0).get(0).getName());
    // [Time].[Weekly] has an all member and no explicit default.
    result = executeQuery("select {[Time.Weekly].DefaultMember} on columns\n" + "from Sales");
    Assert.assertEquals(MondrianProperties.instance().SsasCompatibleNaming.get() ? "All Weeklys" : "All Time.Weeklys", result.getAxes()[0].getPositions().get(0).get(0).getName());
    final String memberUname = MondrianProperties.instance().SsasCompatibleNaming.get() ? "[Time2].[Weekly].[1997].[23]" : "[Time2.Weekly].[1997].[23]";
    TestContext testContext = TestContext.instance().createSubstitutingCube("Sales", "  <Dimension name=\"Time2\" type=\"TimeDimension\" foreignKey=\"time_id\">\n" + "    <Hierarchy hasAll=\"false\" primaryKey=\"time_id\">\n" + "      <Table name=\"time_by_day\"/>\n" + "      <Level name=\"Year\" column=\"the_year\" type=\"Numeric\" uniqueMembers=\"true\"\n" + "          levelType=\"TimeYears\"/>\n" + "      <Level name=\"Quarter\" column=\"quarter\" uniqueMembers=\"false\"\n" + "          levelType=\"TimeQuarters\"/>\n" + "      <Level name=\"Month\" column=\"month_of_year\" uniqueMembers=\"false\" type=\"Numeric\"\n" + "          levelType=\"TimeMonths\"/>\n" + "    </Hierarchy>\n" + "    <Hierarchy hasAll=\"true\" name=\"Weekly\" primaryKey=\"time_id\"\n" + "          defaultMember=\"" + memberUname + "\">\n" + "      <Table name=\"time_by_day\"/>\n" + "      <Level name=\"Year\" column=\"the_year\" type=\"Numeric\" uniqueMembers=\"true\"\n" + "          levelType=\"TimeYears\"/>\n" + "      <Level name=\"Week\" column=\"week_of_year\" type=\"Numeric\" uniqueMembers=\"false\"\n" + "          levelType=\"TimeWeeks\"/>\n" + "      <Level name=\"Day\" column=\"day_of_month\" uniqueMembers=\"false\" type=\"Numeric\"\n" + "          levelType=\"TimeDays\"/>\n" + "    </Hierarchy>\n" + "  </Dimension>");
    // In this variant of the schema, Time2.Weekly has an explicit default
    // member.
    result = testContext.executeQuery("select {[Time2.Weekly].DefaultMember} on columns\n" + "from Sales");
    Assert.assertEquals("23", result.getAxes()[0].getPositions().get(0).get(0).getName());
}
Also used : TestContext(mondrian.test.TestContext)

Example 84 with TestContext

use of mondrian.test.TestContext in project mondrian by pentaho.

the class FunctionTest method testAncestorNumeric.

public void testAncestorNumeric() {
    Member member = executeSingletonAxis("Ancestor([Store].[USA].[CA].[Los Angeles],1)");
    Assert.assertEquals("CA", member.getName());
    member = executeSingletonAxis("Ancestor([Store].[USA].[CA].[Los Angeles], 0)");
    Assert.assertEquals("Los Angeles", member.getName());
    final TestContext testContextRagged = getTestContext().withCube("[Sales Ragged]");
    member = testContextRagged.executeSingletonAxis("Ancestor([Store].[All Stores].[Vatican], 1)");
    Assert.assertEquals("All Stores", member.getName());
    member = testContextRagged.executeSingletonAxis("Ancestor([Store].[USA].[Washington], 1)");
    Assert.assertEquals("USA", member.getName());
    // complicated way to say "1".
    member = testContextRagged.executeSingletonAxis("Ancestor([Store].[USA].[Washington], 7 * 6 - 41)");
    Assert.assertEquals("USA", member.getName());
    member = testContextRagged.executeSingletonAxis("Ancestor([Store].[All Stores].[Vatican], 2)");
    Assert.assertNull("Ancestor at 2 must be null", member);
    member = testContextRagged.executeSingletonAxis("Ancestor([Store].[All Stores].[Vatican], -5)");
    Assert.assertNull("Ancestor at -5 must be null", member);
}
Also used : TestContext(mondrian.test.TestContext)

Example 85 with TestContext

use of mondrian.test.TestContext in project mondrian by pentaho.

the class FunctionTest method testComplexSlicerWith_Calc.

public void testComplexSlicerWith_Calc() {
    TestContext context = getTestContext();
    String query = "with " + "member [Time].[H1 1997] as 'Aggregate([Time].[1997].[Q1] : [Time].[1997].[Q2])', $member_scope = \"CUBE\", MEMBER_ORDINAL = 6 " + "SELECT " + "{[Measures].[Customer Count]} ON 0, " + "{[Education Level].Members} ON 1 " + "FROM [Sales] " + "WHERE {[Time].[H1 1997]}";
    String expectedResult = "Axis #0:\n" + "{[Time].[H1 1997]}\n" + "Axis #1:\n" + "{[Measures].[Customer Count]}\n" + "Axis #2:\n" + "{[Education Level].[All Education Levels]}\n" + "{[Education Level].[Bachelors Degree]}\n" + "{[Education Level].[Graduate Degree]}\n" + "{[Education Level].[High School Degree]}\n" + "{[Education Level].[Partial College]}\n" + "{[Education Level].[Partial High School]}\n" + "Row #0: 4,257\n" + "Row #1: 1,109\n" + "Row #2: 240\n" + "Row #3: 1,237\n" + "Row #4: 394\n" + "Row #5: 1,277\n";
    context.assertQueryReturns(query, expectedResult);
}
Also used : TestContext(mondrian.test.TestContext)

Aggregations

TestContext (mondrian.test.TestContext)167 SqlPattern (mondrian.test.SqlPattern)37 Result (mondrian.olap.Result)4 Member (mondrian.olap.Member)3 AggStar (mondrian.rolap.aggmatcher.AggStar)3 MemberExpr (mondrian.mdx.MemberExpr)2 Connection (mondrian.olap.Connection)2 Query (mondrian.olap.Query)2 QueryAxis (mondrian.olap.QueryAxis)2 TestMember (mondrian.olap.fun.TestMember)2 Execution (mondrian.server.Execution)2 Dialect (mondrian.spi.Dialect)2 SoftReference (java.lang.ref.SoftReference)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 mondrian.olap (mondrian.olap)1 Axis (mondrian.olap.Axis)1 MondrianException (mondrian.olap.MondrianException)1 Position (mondrian.olap.Position)1