Skip to content

Commit

Permalink
MONDRIAN:
Browse files Browse the repository at this point in the history
       The Aggregation.Axis[] is shared by all Segments for the set
       of RolapStar.Measure[] measures and ColumnConstraint[][] constraintses,
       so it is only created once and passed into the Segment constructor.

[git-p4: depot-paths = "//open/mondrian/": change = 3336]
  • Loading branch information
Richard Emberson committed Mar 9, 2005
1 parent 7eafa90 commit 3645aa7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
14 changes: 12 additions & 2 deletions src/main/mondrian/rolap/agg/Aggregation.java
Expand Up @@ -119,16 +119,26 @@ public Aggregation(RolapStar star, RolapStar.Column[] columns) {
public synchronized void load(RolapStar.Measure[] measures,
ColumnConstraint[][] constraintses,
Collection pinnedSegments) {
int axisCount = columns.length;
Util.assertTrue(constraintses.length == axisCount);

// This array of Aggregation.Axis is shared by all Segments for
// this set of measures and constraintses
Aggregation.Axis[] axes = new Aggregation.Axis[axisCount];
for (int i = 0; i < axisCount; i++) {
axes[i] = new Aggregation.Axis(columns[i], constraintses[i]);
}

Segment[] segments = new Segment[measures.length];
for (int i = 0; i < measures.length; i++) {
RolapStar.Measure measure = measures[i];
Segment segment = new Segment(this, measure, constraintses);
Segment segment = new Segment(this, measure, constraintses, axes);
segments[i] = segment;
SoftReference ref = new SoftReference(segment);
segmentRefs.add(ref);
pinnedSegments.add(segment);
}
Segment.load(segments, pinnedSegments);
Segment.load(segments, pinnedSegments, axes);
}


Expand Down
39 changes: 18 additions & 21 deletions src/main/mondrian/rolap/agg/Segment.java
Expand Up @@ -87,7 +87,7 @@ private State() {
final Aggregation aggregation;
final RolapStar.Measure measure;

Aggregation.Axis[] axes;
final Aggregation.Axis[] axes;
private SegmentDataset data;
private final CellKey cellKey; // workspace
/** State of the segment, values are described by {@link State}. */
Expand All @@ -103,20 +103,13 @@ private State() {
**/
Segment(Aggregation aggregation,
RolapStar.Measure measure,
ColumnConstraint[][] constraintses) {
ColumnConstraint[][] constraintses,
Aggregation.Axis[] axes) {
this.id = nextId++;
this.aggregation = aggregation;
this.measure = measure;
RolapStar.Column[] columns = aggregation.getColumns();
int axisCount = columns.length;

Util.assertTrue(constraintses.length == axisCount);

this.axes = new Aggregation.Axis[axisCount];
for (int i = 0; i < axisCount; i++) {
this.axes[i] = new Aggregation.Axis(columns[i], constraintses[i]);
}
this.cellKey = new CellKey(new int[axisCount]);
this.axes = axes;
this.cellKey = new CellKey(new int[axes.length]);
this.state = State.Loading;
}

Expand All @@ -125,12 +118,10 @@ private State() {
* {@link #waitUntilLoaded}.
*/
synchronized void setData(SegmentDataset data,
Aggregation.Axis[] axes,
Collection pinnedSegments) {
Util.assertTrue(this.data == null);
Util.assertTrue(this.state == State.Loading);

this.axes = axes;
this.data = data;
this.state = State.Ready;
notifyAll();
Expand Down Expand Up @@ -263,12 +254,15 @@ boolean wouldContain(Object[] keys) {
*
* @pre segments[i].aggregation == aggregation
**/
static void load(Segment[] segments, Collection pinnedSegments) {
static void load(Segment[] segments,
Collection pinnedSegments,
Aggregation.Axis[] axes) {
String sql = AggregationManager.generateSQL(segments);
Segment segment0 = segments[0];
RolapStar star = segment0.aggregation.getStar();
RolapStar.Column[] columns = segment0.aggregation.getColumns();
int arity = columns.length;

// execute
ResultSet resultSet = null;
final int measureCount = segments.length;
Expand All @@ -286,9 +280,9 @@ static void load(Segment[] segments, Collection pinnedSegments) {
if (o == null) {
o = RolapUtil.sqlNullValue;
}
Integer offsetInteger = segment0.axes[i].getOffset(o);
Integer offsetInteger = axes[i].getOffset(o);
if (offsetInteger == null) {
segment0.axes[i].addNextOffset(o);
axes[i].addNextOffset(o);
}
row[i] = o;
}
Expand All @@ -302,12 +296,13 @@ static void load(Segment[] segments, Collection pinnedSegments) {
}
rows.add(row);
}

// figure out size of dense array, and allocate it (todo: use
// sparse array sometimes)
boolean sparse = false;
int n = 1;
for (int i = 0; i < arity; i++) {
Aggregation.Axis axis = segment0.axes[i];
Aggregation.Axis axis = axes[i];
int size = axis.loadKeys();

int previous = n;
Expand All @@ -331,9 +326,9 @@ static void load(Segment[] segments, Collection pinnedSegments) {
Object[] row = (Object[]) rows.get(i);
int k = 0;
for (int j = 0; j < arity; j++) {
k *= segment0.axes[j].getKeys().length;
k *= axes[j].getKeys().length;
Object o = row[j];
Aggregation.Axis axis = segment0.axes[j];
Aggregation.Axis axis = axes[j];
Integer offsetInteger = axis.getOffset(o);
int offset = offsetInteger.intValue();
pos[j] = offset;
Expand All @@ -352,9 +347,11 @@ static void load(Segment[] segments, Collection pinnedSegments) {
}
}
}

for (int i = 0; i < segments.length; i++) {
segments[i].setData(datas[i], segments[0].axes, pinnedSegments);
segments[i].setData(datas[i], pinnedSegments);
}

} catch (SQLException e) {
throw Util.newInternal(e,
"Error while loading segment; sql=[" + sql + "]");
Expand Down

0 comments on commit 3645aa7

Please sign in to comment.