Skip to content

Commit

Permalink
MONDRIAN
Browse files Browse the repository at this point in the history
   In RolapResult executeStripe getting the cell's format
   string no longer requires the creation of a new Evalator
   (since the current Evalator has the correct Member context),
   altered RolapResult and RolapCell so that when only
   the Evalator's current Members are required by the RolapCell,
   only the Member array is generated (not a new Evaluator).

[git-p4: depot-paths = "//open/mondrian/": change = 8536]
  • Loading branch information
Richard Emberson committed Jan 17, 2007
1 parent c19807b commit 65b94c2
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 30 deletions.
22 changes: 22 additions & 0 deletions src/main/mondrian/olap/ResultBase.java
Expand Up @@ -64,6 +64,27 @@ public void print(PrintWriter pw) {
private void printRows(PrintWriter pw, int axis, int[] pos) {
Axis _axis = axis < 0 ? slicerAxis : axes[axis];
List<Position> positions = _axis.getPositions();
int i = 0;
for (Position position: positions) {
if (axis < 0) {
if (i > 0) {
pw.print(", ");
}
printCell(pw, pos);
} else {
pos[axis] = i;
if (axis == 0) {
int row = axis + 1 < pos.length ? pos[axis + 1] : 0;
pw.print("Row #" + row + ": ");
}
printRows(pw, axis - 1, pos);
if (axis == 0) {
pw.println();
}
}
i++;
}
/*
for (int i = 0, count = positions.size(); i < count; i++) {
if (axis < 0) {
if (i > 0) {
Expand All @@ -82,6 +103,7 @@ private void printRows(PrintWriter pw, int axis, int[] pos) {
}
}
}
*/
}
private void printAxis(PrintWriter pw, Axis axis) {
List<Position> positions = axis.getPositions();
Expand Down
23 changes: 11 additions & 12 deletions src/main/mondrian/rolap/RolapCell.java
Expand Up @@ -45,9 +45,9 @@ public String getCachedFormatString() {
}

public String getFormattedValue() {
final Evaluator evaluator = result.getEvaluator(pos);
RolapCube c = (RolapCube) evaluator.getCube();
RolapCube c = (RolapCube) result.getCube();
Dimension measuresDim = c.getMeasuresHierarchy().getDimension();
final Evaluator evaluator = result.getEvaluator(pos);
RolapMeasure m = (RolapMeasure) evaluator.getContext(measuresDim);

CellFormatter cf = m.getFormatter();
Expand Down Expand Up @@ -80,9 +80,7 @@ public boolean isError() {
*/
public String getDrillThroughSQL(boolean extendedContext) {
RolapAggregationManager aggMan = AggregationManager.instance();

final RolapEvaluator evaluator = getEvaluator();
final Member[] currentMembers = evaluator.getCurrentMembers();
final Member[] currentMembers = getMembers();
CellRequest cellRequest = RolapAggregationManager.makeRequest(
currentMembers, extendedContext, true);
return (cellRequest == null)
Expand All @@ -93,16 +91,14 @@ public String getDrillThroughSQL(boolean extendedContext) {

public int getDrillThroughCount() {
RolapAggregationManager aggMan = AggregationManager.instance();

final RolapEvaluator evaluator = getEvaluator();
final Member[] currentMembers = evaluator.getCurrentMembers();
final Member[] currentMembers = getMembers();
CellRequest cellRequest = RolapAggregationManager.makeRequest(
currentMembers, false, true);
if (cellRequest == null) {
return -1;
}
RolapConnection connection =
(RolapConnection) evaluator.getQuery().getConnection();
(RolapConnection) result.getQuery().getConnection();
java.sql.Connection jdbcConnection = null;
ResultSet rs = null;
final String sql = aggMan.getDrillThroughSql(cellRequest, true);
Expand Down Expand Up @@ -146,11 +142,11 @@ public int getDrillThroughCount() {
*/
public boolean canDrillThrough() {
// Cannot drill through query based on virtual cube.
if (((RolapCube) getEvaluator().getCube()).isVirtual()) {
if (((RolapCube) result.getCube()).isVirtual()) {
return false;
}
}
// get current members
final Member[] currentMembers = getEvaluator().getCurrentMembers();
final Member[] currentMembers = getMembers();
// First member is the measure, test if it is stored measure, return
// true if it is, false if not.
return (currentMembers[0] instanceof RolapStoredMeasure);
Expand All @@ -159,6 +155,9 @@ public boolean canDrillThrough() {
private RolapEvaluator getEvaluator() {
return result.getCellEvaluator(pos);
}
private Member[] getMembers() {
return result.getCellMembers(pos);
}

public Object getPropertyValue(String propertyName) {
Property property = Property.lookup(propertyName, true);
Expand Down
28 changes: 13 additions & 15 deletions src/main/mondrian/rolap/RolapEvaluator.java
Expand Up @@ -57,6 +57,10 @@ public class RolapEvaluator implements Evaluator {
private int iterationLength;
private boolean evalAxes;

private final Member[] calcMembers;
private int calcMemberCount;


/**
* Creates an evaluator.
*/
Expand Down Expand Up @@ -205,6 +209,11 @@ Member[] getCurrentMembers() {
return this.currentMembers;
}

public Member[] getMembers() {
return currentMembers;
}


void setCellReader(CellReader cellReader) {
this.cellReader = cellReader;
}
Expand Down Expand Up @@ -666,10 +675,6 @@ public Object evaluateNamedSet(String name, Exp exp) {
return root.evaluateNamedSet(name, exp);
}

public Member[] getMembers() {
return currentMembers;
}

public int getMissCount() {
return cellReader.getMissCount();
}
Expand All @@ -678,9 +683,6 @@ public Object getParameterValue(ParameterSlot slot) {
return root.getParameterValue(slot);
}

private final Member[] calcMembers;
private int calcMemberCount;

void addCalcMember(Member member) {
assert member != null;
assert member.isCalculated();
Expand Down Expand Up @@ -730,23 +732,19 @@ private void removeCalcMember(Member previous) {
}
}

public int getIterationLength()
{
public int getIterationLength() {
return iterationLength;
}

public void setIterationLength(int length)
{
public void setIterationLength(int length) {
iterationLength = length;
}

public boolean isEvalAxes()
{
public boolean isEvalAxes() {
return evalAxes;
}

public void setEvalAxes(boolean evalAxes)
{
public void setEvalAxes(boolean evalAxes) {
this.evalAxes = evalAxes;
}
}
Expand Down
78 changes: 75 additions & 3 deletions src/main/mondrian/rolap/RolapResult.java
Expand Up @@ -122,6 +122,13 @@ class RolapResult extends ResultBase {
// Sales] > 100) on columns from Sales where
// ([Time].[1998])" should show customers whose 1998 (not
// total) purchases exceeded 100.

// Getting the Position list's size and the Position
// at index == 0 will, in fact, cause an Iterable-base
// Axis Position List to become a List-base Axis
// Position List (and increae memory usage), but for
// the slicer axis, the number of Positions is very
// small, so who cares.
switch (this.slicerAxis.getPositions().size()) {
case 0:
throw MondrianResource.instance().EmptySlicer.ex();
Expand Down Expand Up @@ -178,6 +185,9 @@ class RolapResult extends ResultBase {

// Now that the axes are evaluated, make sure that the number of
// cells does not exceed the result limit.
// If we set the ResultLimit, then we force a conversion of
// Iterable-base Axis Position Lists into List-based version -
// thats just the way it is.
int limit = MondrianProperties.instance().ResultLimit.get();
if (limit > 0) {
// result limit exceeded, throw an exception
Expand All @@ -203,6 +213,9 @@ class RolapResult extends ResultBase {
protected Logger getLogger() {
return LOGGER;
}
public Cube getCube() {
return evaluator.getCube();
}

// implement Result
public Axis[] getAxes() {
Expand Down Expand Up @@ -451,10 +464,41 @@ private void executeStripe(int axisOrdinal, RolapEvaluator evaluator) {
// Get the cell without default format string, if it returns
// null getFormattedValue() will try to evaluate a new
// format string
Cell cell = getCellNoDefaultFormatString(key);
Util.discard(cell.getFormattedValue());
String cachedFormatString = cell.getCachedFormatString();

// The previous implementation created a RolapCell
// with its int array of position indexes and then
// used that array to set the context of the
// Evaluator (and as a result, forcing Iterable-base
// RolapAxis to become List-base). Thats not necessary
// since at this point the current evaluator already has
// the correct context, so we just use it here.
//
// This code is a combination of the code found in
// the getCellNoDefaultFormatString method and
// the RolapCell getFormattedValue method.
Object value = cellValues.get(key);
if (value == null) {
value = Util.nullValue;
}
String cachedFormatString = formatStrings.get(key);

RolapCube cube = (RolapCube) getCube();
Dimension measuresDim =
cube.getMeasuresHierarchy().getDimension();
RolapMeasure m =
(RolapMeasure) evaluator.getContext(measuresDim);
CellFormatter cf = m.getFormatter();
if (cf != null) {
cf.formatCell(value);
} else {
if (cachedFormatString == null) {
cachedFormatString = evaluator.getFormatString();
}
evaluator.format(value, cachedFormatString);
}

formatStrings.put(key, cachedFormatString);

} catch (MondrianEvaluationException e) {
// ignore
} catch (Throwable e) {
Expand Down Expand Up @@ -508,6 +552,12 @@ protected void makeModulos() {
modulos = Modulos.Generator.create(axes);
}

/**
* Called only by RolapCell.
*
* @param pos
* @return
*/
RolapEvaluator getCellEvaluator(int[] pos) {
final RolapEvaluator cellEvaluator = (RolapEvaluator) evaluator.push();
for (int i = 0; i < pos.length; i++) {
Expand All @@ -517,6 +567,28 @@ RolapEvaluator getCellEvaluator(int[] pos) {
return cellEvaluator;
}

/**
* Called only by RolapCell. Use this when creating an Evaluator
* (using method getCellEvaluator) is not required.
*
* @param pos
* @return
*/
Member[] getCellMembers(int[] pos) {
Member[] members = evaluator.getMembers().clone();
final Cube cube = getCube();
for (int i = 0; i < pos.length; i++) {
Position position = axes[i].getPositions().get(pos[i]);
for (Member member: position) {
RolapMember m = (RolapMember) member;
int ordinal = m.getDimension().getOrdinal(cube);
members[ordinal] = m;
}

}
return members;
}

Evaluator getRootEvaluator() {
return evaluator;
}
Expand Down
3 changes: 3 additions & 0 deletions testsrc/main/mondrian/test/BasicQueryTest.java
Expand Up @@ -40,6 +40,9 @@ public class BasicQueryTest extends FoodMartTestCase {
"Axis #1:\n" +
"Axis #2:\n");

public BasicQueryTest() {
super();
}
public BasicQueryTest(String name) {
super(name);
}
Expand Down
3 changes: 3 additions & 0 deletions testsrc/main/mondrian/test/DrillThroughTest.java
Expand Up @@ -27,6 +27,9 @@
* @version $Id$
*/
public class DrillThroughTest extends FoodMartTestCase {
public DrillThroughTest() {
super();
}
public DrillThroughTest(String name) {
super(name);
}
Expand Down

0 comments on commit 65b94c2

Please sign in to comment.