Skip to content

Commit

Permalink
In the XMLA driver, Dimensions are inserted according to their correc…
Browse files Browse the repository at this point in the history
…t ordinal value, as specified by DIMENSION_ORDINAL. Also added a test for that.

Fixes https://sourceforge.net/tracker/?func=detail&aid=2823612&group_id=168953&atid=848534

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@270 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
lucboudreau committed Jul 20, 2009
1 parent 13155f6 commit f7363a7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 9 deletions.
6 changes: 0 additions & 6 deletions src/org/olap4j/driver/xmla/DeferredNamedListImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
* collections loaded immediately, loading the catalog would immediately load
* all sub-objects into memory, taking a lot of memory and time.
*
* <p>(The above description is only intended to be illustrative. The XMLA
* driver schema does not use deferred lists at every level; in particular,
* it loads each cube in one swoop, fetching all dimensions, hierarchies and
* levels of that cube, in order to reduce the number of metadata requests
* submitted.)</p>
*
* <p>This class is not gc-friendly at present. Once populated,
* <code>DeferredNamedListImpl</code> holds hard references
* to the objects it contains, so they are not available to be
Expand Down
25 changes: 23 additions & 2 deletions src/org/olap4j/driver/xmla/XmlaOlap4jConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -930,11 +930,32 @@ public void handle(
Dimension.Type.forXmlaOrdinal(dimensionType);
final String defaultHierarchyUniqueName =
stringElement(row, "DEFAULT_HIERARCHY");
final Integer dimensionOrdinal =
integerElement(row, "DIMENSION_ORDINAL");
XmlaOlap4jDimension dimension = new XmlaOlap4jDimension(
context.olap4jCube, dimensionUniqueName, dimensionName,
dimensionCaption, description, type,
defaultHierarchyUniqueName);
list.add(dimension);
defaultHierarchyUniqueName,
dimensionOrdinal == null ? 0 : dimensionOrdinal);
list.add(dimension);
if (dimensionOrdinal != null) {
Collections.sort(
list,
new Comparator<XmlaOlap4jDimension> () {
public int compare(
XmlaOlap4jDimension d1,
XmlaOlap4jDimension d2)
{
if (d1.getOrdinal() == d2.getOrdinal()) {
return 0;
} else if (d1.getOrdinal() > d2.getOrdinal()) {
return 1;
} else {
return -1;
}
}
});
}
this.cubeForCallback.dimensionsByUname.put(
dimension.getUniqueName(),
dimension);
Expand Down
9 changes: 8 additions & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jDimension.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class XmlaOlap4jDimension
final Type type;
final NamedList<XmlaOlap4jHierarchy> hierarchies;
private final String defaultHierarchyUniqueName;
private final int ordinal;

XmlaOlap4jDimension(
XmlaOlap4jCube olap4jCube,
Expand All @@ -36,13 +37,15 @@ class XmlaOlap4jDimension
String caption,
String description,
Type type,
String defaultHierarchyUniqueName)
String defaultHierarchyUniqueName,
int ordinal)
{
super(uniqueName, name, caption, description);
this.defaultHierarchyUniqueName = defaultHierarchyUniqueName;
assert olap4jCube != null;
this.olap4jCube = olap4jCube;
this.type = type;
this.ordinal = ordinal;

String[] dimensionRestrictions = {
"CATALOG_NAME",
Expand Down Expand Up @@ -91,6 +94,10 @@ public boolean equals(Object obj) {
&& this.uniqueName.equals(
((XmlaOlap4jDimension) obj).getUniqueName());
}

public int getOrdinal() {
return ordinal;
}
}

// End XmlaOlap4jDimension.java
25 changes: 25 additions & 0 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,31 @@ public void testBuildQuery2() throws ClassNotFoundException, SQLException {
+ "ROW:[TV] COL:[Unit Sales] CELL:3,607\n",
sw.toString());
}

/**
* Verifies the order of dimensions; they must conform to their
* ordinal value.
* @throws Exception If something turns sour.
*/
public void testCubeDimensionsOrder() throws Exception {
String dimNames = "[Measures];[Store];[Store Size in SQFT];"
+ "[Store Type];[Time];[Product];[Promotion Media];[Promotions];"
+ "[Customers];[Education Level];[Gender];[Marital Status];"
+ "[Yearly Income];";
Class.forName(tester.getDriverClassName());
connection = tester.createConnection();
OlapConnection olapConnection =
tester.getWrapper().unwrap(connection, OlapConnection.class);
Cube cube = olapConnection.getSchema().getCubes().get("Sales");
StringBuilder sb = new StringBuilder();
for (Dimension dimension : cube.getDimensions()) {
sb.append(dimension.getUniqueName())
.append(";");
}
TestContext.assertEqualsVerbose(
dimNames,
sb.toString());
}
}

// End ConnectionTest.java

0 comments on commit f7363a7

Please sign in to comment.