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] ",