public void testAggStarWithIgnoredColumnsAndCountDistinct() {
propSaver.set(propSaver.properties.ReadAggregates, true);
propSaver.set(propSaver.properties.UseAggregates, true);
propSaver.set(propSaver.properties.GenerateFormattedSql, true);
final TestContext context =
TestContext.instance().withSchema(
"<Schema name=\"FoodMart\">"
+ " <Dimension name=\"Time\" type=\"TimeDimension\">\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"
+ " </Hierarchy>\n"
+ " </Dimension>\n"
+ "<Cube name=\"Sales\" defaultMeasure=\"Unit Sales\">\n"
+ " <Table name=\"sales_fact_1997\">\n"
+ " <AggExclude name=\"agg_c_special_sales_fact_1997\" />\n"
+ " <AggExclude name=\"agg_lc_100_sales_fact_1997\" />\n"
+ " <AggExclude name=\"agg_lc_10_sales_fact_1997\" />\n"
+ " <AggExclude name=\"agg_pc_10_sales_fact_1997\" />\n"
+ " <AggName name=\"agg_g_ms_pcat_sales_fact_1997\">\n"
+ " <AggFactCount column=\"FACT_COUNT\"/>\n"
+ " <AggIgnoreColumn column=\"Quarter\"/>\n"
+ " <AggIgnoreColumn column=\"MONTH_OF_YEAR\"/>\n"
+ " <AggMeasure name=\"[Measures].[Customer Count]\" column=\"customer_count\" />\n"
+ " <AggLevel name=\"[Time].[Year]\" column=\"the_year\" />\n"
+ " </AggName>\n"
+ " </Table>\n"
+ " <DimensionUsage name=\"Time\" source=\"Time\" foreignKey=\"time_id\"/>\n"
+ " <Measure name=\"Unit Sales\" column=\"unit_sales\" aggregator=\"sum\"\n"
+ " formatString=\"Standard\"/>\n"
+ " <Measure name=\"Customer Count\" column=\"customer_id\" aggregator=\"distinct-count\"\n"
+ " formatString=\"Standard\"/>\n"
+ "</Cube>\n"
+ "</Schema>");
RolapStar star = context.getConnection().getSchemaReader()
.getSchema().getStar("sales_fact_1997");
AggStar aggStarSpy = spy(
getAggStar(star, "agg_g_ms_pcat_sales_fact_1997"));
// make sure the test AggStar will be prioritized first
when(aggStarSpy.getSize()).thenReturn(0);
context.getConnection().getSchemaReader()
.getSchema().getStar("sales_fact_1997").addAggStar(aggStarSpy);
boolean[] rollup = { false };
AggStar returnedStar = AggregationManager
.findAgg(
star, aggStarSpy.getLevelBitKey(),