Skip to content

Commit

Permalink
MONDRIAN: fix a LucidDB dialect test problem; also add an additional …
Browse files Browse the repository at this point in the history
…check to try to load only agg(distinct subquery) individually.

[git-p4: depot-paths = "//open/mondrian/": change = 9698]
  • Loading branch information
Rushan Chen committed Aug 3, 2007
1 parent c0a682d commit b472a98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
14 changes: 12 additions & 2 deletions src/main/mondrian/rolap/FastBatchingCellReader.java
Expand Up @@ -591,7 +591,7 @@ int getDistinctMeasureCount(List<RolapStar.Measure> measuresList) {
* This method was initially intended for only those measures that are
* defined using subqueries(for DBs that support them). However, since
* Mondrian does not parse the SQL string, the method will count both
* queries as well as non query SQL expressions, e.g. "col1" + "col2".
* queries as well as some non query SQL expressions.
*/
List<RolapStar.Measure> getDistinctSqlMeasures(
List<RolapStar.Measure> measuresList) {
Expand All @@ -601,7 +601,17 @@ List<RolapStar.Measure> getDistinctSqlMeasures(
if (measure.getAggregator().isDistinct() &&
measure.getExpression() instanceof
MondrianDef.MeasureExpression) {
distinctSqlMeasureList.add(measure);
MondrianDef.MeasureExpression measureExpr =
(MondrianDef.MeasureExpression) measure.getExpression();
MondrianDef.SQL measureSql = measureExpr.expressions[0];
// Checks if the SQL contains "SELECT" to detect the case a
// subquery is used to define the measure. This is not a
// perfect check, because a SQL expression on column names
// containing "SELECT" will also be detected. e,g,
// count("select beef" + "regular beef").
if (measureSql.cdata.toUpperCase().contains("SELECT ")) {
distinctSqlMeasureList.add(measure);
}
}
}
return distinctSqlMeasureList;
Expand Down
23 changes: 9 additions & 14 deletions testsrc/main/mondrian/rolap/FastBatchingCellReaderTest.java
Expand Up @@ -757,9 +757,9 @@ public void testLoadDistinctSqlMeasure() {
"select " +
"\"store\".\"store_type\" as \"c0\", " +
"count(distinct " +
"select \"warehouse_class\".\"warehouse_class_id\" AS \"warehouse_class_id\" " +
"(select \"warehouse_class\".\"warehouse_class_id\" AS \"warehouse_class_id\" " +
"from \"warehouse_class\" AS \"warehouse_class\" " +
"where \"warehouse_class\".\"warehouse_class_id\" = \"warehouse\".\"warehouse_class_id\" and \"warehouse_class\".\"description\" = 'Large Owned') as \"m0\" " +
"where \"warehouse_class\".\"warehouse_class_id\" = \"warehouse\".\"warehouse_class_id\" and \"warehouse_class\".\"description\" = 'Large Owned')) as \"m0\" " +
"from \"store\" as \"store\", \"warehouse\" as \"warehouse\" " +
"where \"warehouse\".\"stores_id\" = \"store\".\"store_id\" " +
"group by \"store\".\"store_type\"";
Expand All @@ -768,27 +768,23 @@ public void testLoadDistinctSqlMeasure() {
"select " +
"\"store\".\"store_type\" as \"c0\", " +
"count(distinct " +
"select \"warehouse_class\".\"warehouse_class_id\" AS \"warehouse_class_id\" " +
"(select \"warehouse_class\".\"warehouse_class_id\" AS \"warehouse_class_id\" " +
"from \"warehouse_class\" AS \"warehouse_class\" " +
"where \"warehouse_class\".\"warehouse_class_id\" = \"warehouse\".\"warehouse_class_id\" and \"warehouse_class\".\"description\" = 'Large Independent') as \"m0\" " +
"where \"warehouse_class\".\"warehouse_class_id\" = \"warehouse\".\"warehouse_class_id\" and \"warehouse_class\".\"description\" = 'Large Independent')) as \"m0\" " +
"from \"store\" as \"store\", \"warehouse\" as \"warehouse\" " +
"where \"warehouse\".\"stores_id\" = \"store\".\"store_id\" " +
"group by \"store\".\"store_type\"";

String loadCountDistinct_luciddb3 =
"select \"store\".\"store_type\" as \"c0\", count(distinct \"store_id\"+\"warehouse_id\") as \"m0\" " +
"from \"store\" as \"store\", \"warehouse\" as \"warehouse\" " +
"where \"warehouse\".\"stores_id\" = \"store\".\"store_id\" group by \"store\".\"store_type\"";

String loadOtherAggs_luciddb =
"select " +
"\"store\".\"store_type\" as \"c0\", " +
"count(" +
"select \"warehouse_class\".\"warehouse_class_id\" AS \"warehouse_class_id\" " +
"(select \"warehouse_class\".\"warehouse_class_id\" AS \"warehouse_class_id\" " +
"from \"warehouse_class\" AS \"warehouse_class\" " +
"where \"warehouse_class\".\"warehouse_class_id\" = \"warehouse\".\"warehouse_class_id\" and \"warehouse_class\".\"description\" = 'Large Independent') as \"m0\", " +
"count(\"store_id\"+\"warehouse_id\") as \"m1\", " +
"count(\"warehouse\".\"stores_id\") as \"m2\" " +
"where \"warehouse_class\".\"warehouse_class_id\" = \"warehouse\".\"warehouse_class_id\" and \"warehouse_class\".\"description\" = 'Large Independent')) as \"m0\", " +
"count(distinct \"store_id\"+\"warehouse_id\") as \"m1\", " +
"count(\"store_id\"+\"warehouse_id\") as \"m2\", " +
"count(\"warehouse\".\"stores_id\") as \"m3\" " +
"from \"store\" as \"store\", \"warehouse\" as \"warehouse\" " +
"where \"warehouse\".\"stores_id\" = \"store\".\"store_id\" " +
"group by \"store\".\"store_type\"";
Expand Down Expand Up @@ -816,7 +812,6 @@ public void testLoadDistinctSqlMeasure() {
SqlPattern[] patterns = {
new SqlPattern(SqlPattern.Dialect.LUCIDDB, loadCountDistinct_luciddb1, loadCountDistinct_luciddb1),
new SqlPattern(SqlPattern.Dialect.LUCIDDB, loadCountDistinct_luciddb2, loadCountDistinct_luciddb2),
new SqlPattern(SqlPattern.Dialect.LUCIDDB, loadCountDistinct_luciddb3, loadCountDistinct_luciddb3),
new SqlPattern(SqlPattern.Dialect.LUCIDDB, loadOtherAggs_luciddb, loadOtherAggs_luciddb),

new SqlPattern(SqlPattern.Dialect.DERBY, loadCountDistinct_derby1, loadCountDistinct_derby1),
Expand Down

0 comments on commit b472a98

Please sign in to comment.