Skip to content

Commit

Permalink
MONDRIAN: RoalpNativeSet must return copies from cache because the re…
Browse files Browse the repository at this point in the history
…turned sets are modified in later steps

[git-p4: depot-paths = "//open/mondrian/": change = 4456]
  • Loading branch information
Andreas Voss committed Nov 22, 2005
1 parent c3df895 commit 93460ed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/main/mondrian/rolap/RolapNativeSet.java
Expand Up @@ -10,7 +10,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import mondrian.olap.Exp;
Expand Down Expand Up @@ -129,7 +128,7 @@ public Object execute() {
TupleEvent e = new TupleEvent(this, tr);
listener.foundInCache(e);
}
return result;
return copy(result);
}

// execute sql and store the result
Expand All @@ -138,12 +137,20 @@ public Object execute() {
listener.excutingSql(e);
}
result = tr.readTuples(schemaReader.getDataSource());
result = Collections.unmodifiableList(result);
cache.put(key, result);
return result;
return copy(result);
}


/**
* returns a copy of the result because its modified
*/
private List copy(List list) {
List copy = new ArrayList();
copy.addAll(list);
return copy;
}

private void addLevel(TupleReader tr, CrossJoinArg arg) {
RolapLevel level = arg.getLevel();
Hierarchy hierarchy = level.getHierarchy();
Expand Down
16 changes: 15 additions & 1 deletion testsrc/main/mondrian/rolap/NonEmptyTest.java
Expand Up @@ -46,14 +46,28 @@ public class NonEmptyTest extends FoodMartTestCase {
private static Logger logger = Logger.getLogger(NonEmptyTest.class);
SqlConstraintFactory scf = SqlConstraintFactory.instance();

/**
* checks that crossjoin returns a modifiable copy from cache
* because its modified during sort
*/
public void testResultIsModifyableCopy() {
checkNative(3, 3, "select {[Measures].[Store Sales]} on columns,"
+ " NON EMPTY Order("
+ " CrossJoin([Customers].[All Customers].[USA].children, [Promotions].[Promotion Name].Members), "
+ " [Measures].[Store Sales]) ON ROWS"
+ " from [Sales] where ("
+ " [Store].[All Stores].[USA].[CA].[San Francisco].[Store 14],"
+ " [Time].[1997].[Q1].[1])");
}

/** check that top count is executed native unless disabled */
public void testNativeTopCount() {
if (!MondrianProperties.instance().EnableNativeTopCount.get())
return;
checkNative(3, 3, "select {[Measures].[Store Sales]} on columns,"
+ " NON EMPTY TopCount("
+ " CrossJoin([Customers].[All Customers].[USA].children, [Promotions].[Promotion Name].Members), "
+ " 10, [Measures].[Store Sales]) ON ROWS"
+ " 3, [Measures].[Store Sales]) ON ROWS"
+ " from [Sales] where ("
+ " [Store].[All Stores].[USA].[CA].[San Francisco].[Store 14],"
+ " [Time].[1997].[Q1].[1])");
Expand Down

0 comments on commit 93460ed

Please sign in to comment.