Skip to content

Commit

Permalink
MONDRIAN: Fix bug 1379068: Child member constaint SQL was incorrectly…
Browse files Browse the repository at this point in the history
… in terms of level key, should be in terms of level name.

[git-p4: depot-paths = "//open/mondrian/": change = 5370]
  • Loading branch information
julianhyde committed Feb 8, 2006
1 parent d5e38bb commit c833d38
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
6 changes: 4 additions & 2 deletions demo/FoodMart.xml
Expand Up @@ -324,8 +324,10 @@ fullname
levelType="TimeYears"/>
<Level name="Quarter" column="quarter" uniqueMembers="false"
levelType="TimeQuarters"/>
<Level name="Month" column="month_of_year" uniqueMembers="false"
type="Numeric" levelType="TimeMonths"/>
<!-- Use the_month as source for the name, so members look like
[Time].[1997].[Q1].[Jan] rather than [Time].[1997].[Q1].[1]. -->
<Level name="Month" column="month_of_year" nameColumn="the_month"
uniqueMembers="false" type="Numeric" levelType="TimeMonths"/>
</Hierarchy>
</Dimension>

Expand Down
45 changes: 32 additions & 13 deletions src/main/mondrian/rolap/ChildByNameConstraint.java
@@ -1,43 +1,60 @@
/*
//This software is subject to the terms of the Common Public License
//Agreement, available at the following URL:
//http://www.opensource.org/licenses/cpl.html.
//Copyright (C) 2004-2005 TONBELLER AG
//All Rights Reserved.
//You must accept the terms of that agreement to use this software.
// This software is subject to the terms of the Common Public License
// Agreement, available at the following URL:
// http://www.opensource.org/licenses/cpl.html.
// Copyright (C) 2004-2005 TONBELLER AG
// Copyright (C) 2006-2006 Julian Hyde
// All Rights Reserved.
// You must accept the terms of that agreement to use this software.
*/
package mondrian.rolap;

import java.util.Arrays;

import mondrian.rolap.sql.SqlQuery;
import mondrian.olap.MondrianDef;

/**
* optimize the search for a child by name. This is used whenever the
* string representation of a member is parsed, e.g.
* Constraint which optimizes the search for a child by name. This is used
* whenever the string representation of a member is parsed, e.g.
* [Customers].[All Customers].[USA].[CA]. Restricts the result to
* the member we are searching for.
*
* @author avix
* @version $Id$
*/
class ChildByNameConstraint extends DefaultMemberChildrenConstraint {
String childName;
Object cacheKey;

public ChildByNameConstraint(String childName) {
this.childName = childName;
this.cacheKey = Arrays.asList(new Object[] { super.getCacheKey(),
ChildByNameConstraint.class, childName});
this.cacheKey = Arrays.asList(
new Object[] {
super.getCacheKey(),
ChildByNameConstraint.class, childName});
}

public void addLevelConstraint(SqlQuery query, RolapLevel level) {
super.addLevelConstraint(query, level);
String column = level.getKeyExp().getExpression(query);
MondrianDef.Expression exp = level.getNameExp();
boolean numeric;
if (exp == null) {
exp = level.getKeyExp();
numeric = level.isNumeric();
} else {
// The schema doesn't specify whether the name column is numeric
// but we presume that it is not.
numeric = false;
}
String column = exp.getExpression(query);
String value = childName;
if (!level.isNumeric()) {
if (!numeric) {
// some dbs (like DB2) compare case sensitive
column = query.getDialect().toUpper(column);
value = value.toUpperCase();
}
value = query.quote(level.isNumeric(), value);
value = query.quote(numeric, value);
query.addWhere(column, RolapUtil.sqlNullLiteral.equals(value) ? " is " : " = ", value);
}

Expand All @@ -50,3 +67,5 @@ public Object getCacheKey() {
}

}

// End ChildByNameConstraint.java
12 changes: 12 additions & 0 deletions testsrc/main/mondrian/rolap/NonEmptyTest.java
Expand Up @@ -606,6 +606,18 @@ public void testMemberChildrenNoWhere() {
c.run();
}

public void testMemberChildrenNameCol() {
// Bug 1379068 causes no children of [Time].[1997].[Q2] to be
// found, because it incorrectly constrains on the level's key column
// rather than name column.
TestCase c = new TestCase(3, 1,
"select " +
" {[Measures].[Count]} ON columns," +
" {[Time].[1997].[Q2].[April]} on rows " +
"from [HR]");
c.run();
}

/**
* When a member is expanded in JPivot with mulitple hierarchies visible it
* generates a
Expand Down

0 comments on commit c833d38

Please sign in to comment.