Skip to content

Commit

Permalink
MONDRIAN-PACINO: Rollup can now combine multiple segments. Fixes MOND…
Browse files Browse the repository at this point in the history
…RIAN-1020,

    "Mondrian should be able to combine the data of multiple segments for a
    single query". To achieve this, segment cache index can now find groups of
    segments to roll up if one does not suffice.

    Add 'cardinality' to each segment column. If cardinality is known, we know
    whether we have all values, and can therefore roll up.

    Important note: Following this change, the catalog attribute
    Level.estimatedValueCount becomes important for correctness. If lower than
    the actual number of distinct values in the database (counting null as a
    distinct value, if it is a valid value for that column),Mondrian may give
    incorrect results.

    Fix a bug in SegmentBuilder.intersect, and add a test case. It still needs
    to be moved.

    Add Pair.leftIter and .rightIter.

    Fix build error in SegmentCellKey under JDK 1.5.

[git-p4: depot-paths = "//open/mondrian-release/pacino/": change = 14819]
  • Loading branch information
julianhyde committed Dec 4, 2011
1 parent e57fddb commit 630a656
Show file tree
Hide file tree
Showing 8 changed files with 423 additions and 93 deletions.
4 changes: 4 additions & 0 deletions src/main/mondrian/rolap/CacheControlImpl.java
Expand Up @@ -461,6 +461,7 @@ public void visit(MemberCellRegion region) {
list.add(
new SegmentColumn(
entry.getKey(),
-1,
null));
} else {
Arrays.sort(
Expand All @@ -469,17 +470,20 @@ public void visit(MemberCellRegion region) {
list.add(
new SegmentColumn(
entry.getKey(),
-1,
new ArraySortedSet(keys)));
}
}
}

public void visit(MemberRangeCellRegion region) {
// We translate all ranges into wildcards.
// FIXME Optimize this by resolving the list of members
// into an actual list of values for ConstrainedColumn
list.add(
new SegmentColumn(
region.level.getKeyExp().getGenericExpression(),
-1,
null));
}
};
Expand Down
40 changes: 8 additions & 32 deletions src/main/mondrian/rolap/agg/SegmentBuilder.java
Expand Up @@ -218,7 +218,9 @@ class AxisInfo {
axis.hasNull = hasNull;
axis.requestedValues = requestedValues;
} else {
axis.valueSet = intersect(values, axis.valueSet);
axis.valueSet = ArraySortedSet.intersect(
values,
axis.valueSet);
axis.hasNull = hasNull && axis.hasNull;
if (!Util.equals(axis.requestedValues, requestedValues)) {
if (axis.requestedValues == null) {
Expand Down Expand Up @@ -404,6 +406,7 @@ class AxisInfo {
constrainedColumns[i] =
new SegmentColumn(
axisInfo.column.getColumnExpression(),
axisInfo.column.getValueCount(),
axisInfo.lostPredicate
? axisList.get(i).left
: axisInfo.column.values);
Expand All @@ -423,36 +426,6 @@ class AxisInfo {
return Pair.of(header, body);
}

/*
* TODO: Factor this out into ArraySortedSet or Util.
*/
private static SortedSet<Comparable<?>> intersect(
SortedSet<Comparable<?>> set1,
SortedSet<Comparable<?>> set2)
{
final Iterator<Comparable<?>> it1 = set1.iterator();
final Iterator<Comparable<?>> it2 = set2.iterator();
final Comparable<?>[] result =
new Comparable[Math.max(set1.size(), set2.size())];
int i = 0;
Comparable e1 = it1.next();
Comparable e2 = it2.next();
while (e1 != null && e2 != null) {
final int compare = e1.compareTo(e2);
if (compare == 0) {
result[i++] = e1;
i++;
e1 = it1.next();
e2 = it2.next();
} else if (compare == 1) {
e2 = it2.next();
} else {
e1 = it1.next();
}
};
return new ArraySortedSet(result, 0, i);
}

private static int[] computeAxisMultipliers(
List<Pair<SortedSet<Comparable<?>>, Boolean>> axes)
{
Expand All @@ -464,6 +437,7 @@ private static int[] computeAxisMultipliers(
}
return axisMultipliers;
}

private static class ExcludedRegionList
extends AbstractList<Segment.ExcludedRegion>
implements Segment.ExcludedRegion
Expand Down Expand Up @@ -572,6 +546,7 @@ public static SegmentColumn[] toConstrainedColumns(
new SegmentColumn(
predicate.getConstrainedColumn()
.getExpression().getGenericExpression(),
predicate.getConstrainedColumn().getCardinality(),
null));
} else {
Arrays.sort(
Expand All @@ -580,7 +555,8 @@ public static SegmentColumn[] toConstrainedColumns(
ccs.add(
new SegmentColumn(
predicate.getConstrainedColumn()
.getExpression().getGenericExpression(),
.getExpression().getGenericExpression(),
predicate.getConstrainedColumn().getCardinality(),
new ArraySortedSet(valuesArray)));
}
}
Expand Down

0 comments on commit 630a656

Please sign in to comment.