use of mondrian.test.TestContext in project mondrian by pentaho.
the class FunctionTest method testOrdinal.
public void testOrdinal() {
final TestContext testContext = getTestContext().withCube("Sales Ragged");
Cell cell = testContext.executeExprRaw("[Store].[All Stores].[Vatican].ordinal");
assertEquals("Vatican is at level 1.", 1, ((Number) cell.getValue()).intValue());
cell = testContext.executeExprRaw("[Store].[All Stores].[USA].[Washington].ordinal");
assertEquals("Washington is at level 3.", 3, ((Number) cell.getValue()).intValue());
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class FunctionTest method testComplexSlicer_Unsupported.
public void testComplexSlicer_Unsupported() {
TestContext context = getTestContext().createSubstitutingCube("Sales", null, "<CalculatedMember " + "name='H1 1997' " + "formula='([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]}";
final String errorMessagePattern = "Calculated member 'H1 1997' is not supported within a compound predicate";
context.assertQueryThrows(query, errorMessagePattern);
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class FunctionTest method testComplexSlicer_Calc_Calc.
public void testComplexSlicer_Calc_Calc() {
TestContext context = getTestContext().createSubstitutingCube("Sales", null, "<CalculatedMember " + "name='H1 1997' " + "formula='Aggregate([Time].[1997].[Q1]:[Time].[1997].[Q2])' " + "dimension='Time' />" + "<CalculatedMember " + "name='Partial' " + "formula='Aggregate([Education Level].[Partial College]:[Education Level].[Partial High School])' " + "dimension='Education Level' />");
String query = "SELECT " + "{[Measures].[Customer Count]} ON 0 " + "FROM [Sales] " + "WHERE ([Time].[H1 1997],[Education Level].[Partial])";
String expectedResult = "Axis #0:\n" + "{[Time].[H1 1997], [Education Level].[Partial]}\n" + "Axis #1:\n" + "{[Measures].[Customer Count]}\n" + "Row #0: 1,671\n";
context.assertQueryReturns(query, expectedResult);
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class CellKeyTest method testCellLookup.
public void testCellLookup() {
if (!isDefaultNullMemberRepresentation()) {
return;
}
String cubeDef = "<Cube name = \"SalesTest\" defaultMeasure=\"Unit Sales\">\n" + " <Table name=\"sales_fact_1997\"/>\n" + " <Dimension name=\"City\" foreignKey=\"customer_id\">\n" + " <Hierarchy hasAll=\"true\" primaryKey=\"customer_id\">\n" + " <Table name=\"customer\"/>\n" + " <Level name=\"city\" column=\"city\" uniqueMembers=\"true\"/>\n" + " </Hierarchy>\n" + " </Dimension>\n" + " <Dimension name=\"Gender\" foreignKey=\"customer_id\">\n" + " <Hierarchy hasAll=\"true\" primaryKey=\"customer_id\">\n" + " <Table name=\"customer\"/>\n" + " <Level name=\"gender\" column=\"gender\" uniqueMembers=\"true\"/>\n" + " </Hierarchy>\n" + " </Dimension>\n" + " <Dimension name=\"Address2\" foreignKey=\"customer_id\">\n" + " <Hierarchy hasAll=\"true\" primaryKey=\"customer_id\">\n" + " <Table name=\"customer\"/>\n" + " <Level name=\"addr\" column=\"address2\" uniqueMembers=\"true\"/>\n" + " </Hierarchy>\n" + " </Dimension>\n" + " <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\" formatString=\"Standard\"/>\n" + "</Cube>";
String query = "With Set [*NATIVE_CJ_SET] as NonEmptyCrossJoin([Gender].Children, [Address2].Children) " + "Select Generate([*NATIVE_CJ_SET], {([Gender].CurrentMember, [Address2].CurrentMember)}) on columns " + "From [SalesTest] where ([City].[Redwood City])";
String result = "Axis #0:\n" + "{[City].[Redwood City]}\n" + "Axis #1:\n" + "{[Gender].[F], [Address2].[#null]}\n" + "{[Gender].[F], [Address2].[#2]}\n" + "{[Gender].[F], [Address2].[Unit H103]}\n" + "{[Gender].[M], [Address2].[#null]}\n" + "{[Gender].[M], [Address2].[#208]}\n" + "Row #0: 71\n" + "Row #0: 10\n" + "Row #0: 3\n" + "Row #0: 52\n" + "Row #0: 8\n";
/*
* Make sure ExpandNonNative is not set. Otherwise, the query is
* evaluated natively. For the given data set(which contains NULL
* members), native evaluation produces results in a different order
* from the non-native evaluation.
*/
propSaver.set(MondrianProperties.instance().ExpandNonNative, false);
TestContext testContext = TestContext.instance().create(null, cubeDef, null, null, null, null);
testContext.assertQueryReturns(query, result);
}
use of mondrian.test.TestContext in project mondrian by pentaho.
the class FastBatchingCellReaderTest method testCountDistinctAggWithOtherCountDistinctInContext.
public void testCountDistinctAggWithOtherCountDistinctInContext() {
// tests that Aggregate( <set>, <count-distinct measure>) aggregates
// the correct measure when a *different* count-distinct measure is
// in context (MONDRIAN-2128)
TestContext testContext = TestContext.instance().create(null, "<Cube name=\"2CountDistincts\" defaultMeasure=\"Store Count\">\n" + " <Table name=\"sales_fact_1997\"/>\n" + " <DimensionUsage name=\"Time\" source=\"Time\" " + "foreignKey=\"time_id\"/>" + " <DimensionUsage name=\"Store\" source=\"Store\" " + "foreignKey=\"store_id\"/>\n" + " <DimensionUsage name=\"Product\" source=\"Product\" " + " foreignKey=\"product_id\"/>" + " <Measure name=\"Store Count\" column=\"store_id\" " + "aggregator=\"distinct-count\"/>\n" + " <Measure name=\"Customer Count\" column=\"customer_id\" " + "aggregator=\"distinct-count\"/>\n" + " <Measure name=\"Unit Sales\" column=\"unit_sales\" " + "aggregator=\"sum\"/>\n" + "</Cube>", null, null, null, null);
// We should get the same answer whether the default [Store Count]
// measure is in context or [Unit Sales]. The measure specified in the
// second param of Aggregate() should be used.
final String queryStoreCountInContext = "with member Store.agg as " + "'aggregate({[Store].[USA].[CA],[Store].[USA].[OR]}, " + " measures.[Customer Count])'" + " select Store.agg on 0 from [2CountDistincts] ";
final String queryUnitSalesInContext = "with member Store.agg as " + "'aggregate({[Store].[USA].[CA],[Store].[USA].[OR]}, " + " measures.[Customer Count])'" + " select Store.agg on 0 from [2CountDistincts] where " + "measures.[Unit Sales] ";
assertQueriesReturnSimilarResults(queryStoreCountInContext, queryUnitSalesInContext, testContext);
final String queryCAORRollup = "with member measures.agg as " + "'aggregate({[Store].[USA].[CA],[Store].[USA].[OR]}, " + " measures.[Customer Count])'" + " select {measures.agg, measures.[Customer Count]} on 0, " + " [Product].[All Products].children on 1 " + "from [2CountDistincts] ";
testContext.assertQueryReturns(queryCAORRollup, "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[agg]}\n" + "{[Measures].[Customer Count]}\n" + "Axis #2:\n" + "{[Product].[Drink]}\n" + "{[Product].[Food]}\n" + "{[Product].[Non-Consumable]}\n" + "Row #0: 2,243\n" + "Row #0: 3,485\n" + "Row #1: 3,711\n" + "Row #1: 5,525\n" + "Row #2: 2,957\n" + "Row #2: 4,468\n");
// [Customer Count] should override context
testContext.assertQueryReturns("with member Store.agg as " + "'aggregate({[Store].[USA].[CA],[Store].[USA].[OR]}, " + " measures.[Customer Count])'" + " select {measures.[Store Count], measures.[Customer Count]} on 0, " + " [Store].agg on 1 " + "from [2CountDistincts] ", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[Store Count]}\n" + "{[Measures].[Customer Count]}\n" + "Axis #2:\n" + "{[Store].[agg]}\n" + "Row #0: 3,753\n" + "Row #0: 3,753\n");
// aggregate should pick up measure in context
testContext.assertQueryReturns("with member Store.agg as " + "'aggregate({[Store].[USA].[CA],[Store].[USA].[OR]})'" + " select {measures.[Store Count], measures.[Customer Count]} on 0, " + " [Store].agg on 1 " + "from [2CountDistincts] ", "Axis #0:\n" + "{}\n" + "Axis #1:\n" + "{[Measures].[Store Count]}\n" + "{[Measures].[Customer Count]}\n" + "Axis #2:\n" + "{[Store].[agg]}\n" + "Row #0: 6\n" + "Row #0: 3,753\n");
}
Aggregations