Skip to content

Commit

Permalink
Mondrian: fix a bug in generating predicates for compound members
Browse files Browse the repository at this point in the history
[git-p4: depot-paths = "//open/mondrian/": change = 9996]
  • Loading branch information
Rushan Chen committed Oct 11, 2007
1 parent 11a9921 commit 51078d0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/mondrian/rolap/agg/CellRequest.java
Expand Up @@ -318,11 +318,20 @@ public void addConstraint(StarPredicate predicate, int[] groupOrdinals) {
// new predicate
StarPredicate lastPredicate0 =
predicateList.get(size0 - 1);
int size1 = lastPredicate0 instanceof OrPredicate ?
((OrPredicate) lastPredicate0).getChildren().size() :
1;
boolean isOr = lastPredicate0 instanceof OrPredicate;
boolean isList = lastPredicate0 instanceof ListColumnPredicate;

// number of input predicates
int size1 = 1;

if (isOr) {
size1 = ((OrPredicate) lastPredicate0).getChildren().size();
} else if (isList) {
size1 = ((ListColumnPredicate) lastPredicate0).getPredicates().size();
}

if (groupOrdinals[1] == size1) {
// new predicate
// new predicate to be OR'ed together
StarPredicate newPredicate = lastPredicate0.or(predicate);
predicateList.set(size0 - 1, newPredicate);
} else if (groupOrdinals[1] == size1 - 1) {
Expand Down
46 changes: 46 additions & 0 deletions testsrc/main/mondrian/rolap/FastBatchingCellReaderTest.java
Expand Up @@ -1086,6 +1086,52 @@ public void testAggregateDistinctCount4() {
new SqlPattern(SqlPattern.Dialect.ACCESS, accessSql, accessSql)
});
}

public void testAggregateDistinctCount5() {
String query =
"With " +
"Set [Products] as '{[Product].[All Products].[Drink], [Product].[All Products].[Food], [Product].[All Products].[Non-Consumable]}' " +
"Member [Product].[Selected Products] as 'Aggregate([Products])', SOLVE_ORDER=2 " +
"Select {[Store].[Store State].Members} on rows, {[Measures].[Customer Count]} on columns " +
"From [Sales] " +
"Where ([Product].[Selected Products])";

String derbySql =
"select " +
"count(distinct \"sales_fact_1997\".\"customer_id\") as \"c\" " +
"from " +
"\"sales_fact_1997\" as \"sales_fact_1997\", \"store\" as \"store\", " +
"\"time_by_day\" as \"time_by_day\", \"product_class\" as \"product_class\", " +
"\"product\" as \"product\" " +
"where " +
"\"sales_fact_1997\".\"store_id\" = \"store\".\"store_id\" and " +
"\"store\".\"store_state\" = 'CA' and " +
"\"sales_fact_1997\".\"time_id\" = \"time_by_day\".\"time_id\" and " +
"\"time_by_day\".\"the_year\" = 1997 and " +
"\"sales_fact_1997\".\"product_id\" = \"product\".\"product_id\" and " +
"\"product\".\"product_class_id\" = \"product_class\".\"product_class_id\" and " +
"\"product_class\".\"product_family\" in ('Drink', 'Food', 'Non-Consumable')";

String mysqlSql =
"select count(distinct `sales_fact_1997`.`customer_id`) as `c` " +
"from `sales_fact_1997` as `sales_fact_1997`, `store` as `store`, " +
"`time_by_day` as `time_by_day`, `product_class` as `product_class`, " +
"`product` as `product` " +
"where " +
"`sales_fact_1997`.`store_id` = `store`.`store_id` and " +
"`store`.`store_state` = 'CA' and " +
"`sales_fact_1997`.`time_id` = `time_by_day`.`time_id` and " +
"`time_by_day`.`the_year` = 1997 and " +
"`sales_fact_1997`.`product_id` = `product`.`product_id` and " +
"`product`.`product_class_id` = `product_class`.`product_class_id` and " +
"`product_class`.`product_family` in ('Drink', 'Food', 'Non-Consumable')";

SqlPattern[] patterns = {
new SqlPattern(SqlPattern.Dialect.DERBY, derbySql, derbySql),
new SqlPattern(SqlPattern.Dialect.MYSQL, mysqlSql, mysqlSql)};

assertQuerySql(query, patterns);
}
}

// End FastBatchingCellReaderTest.java

0 comments on commit 51078d0

Please sign in to comment.