Skip to content

Commit

Permalink
Fixes for cellsets with no filter or compound filter.
Browse files Browse the repository at this point in the history
Fix formatting if filter is compound (by upgrading mondrian).
Add tests now that mondrian correctly returns all positions of compound filter.


git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@357 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Oct 12, 2010
1 parent b8cb21d commit 5732212
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 44 deletions.
2 changes: 1 addition & 1 deletion ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<dependency org="hsqldb" name="hsqldb" rev="1.8.0.7"
transitive="false" conf="test->default" />

<dependency org="pentaho" name="mondrian" rev="3.2.0.13809"
<dependency org="pentaho" name="mondrian" rev="3.2.1.13868"
transitive="false" changing="true" conf="test->default" />

<dependency org="eigenbase" name="eigenbase-xom" rev="1.3.0.11999"
Expand Down
35 changes: 15 additions & 20 deletions src/org/olap4j/layout/TraditionalCellSetFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ private static void print(CellSet cellSet, PrintWriter pw) {
for (int i = 0; i < axisCount; i++) {
pos.add(-1);
}
printRows(cellSet, pw, axisCount - 1, pos);
if (axisCount == 0) {
printCell(cellSet, pw, pos);
} else {
printRows(cellSet, pw, axisCount - 1, pos);
}
}

/**
Expand All @@ -72,30 +76,21 @@ private static void print(CellSet cellSet, PrintWriter pw) {
private static void printRows(
CellSet cellSet, PrintWriter pw, int axis, List<Integer> pos)
{
CellSetAxis _axis = axis < 0
? cellSet.getFilterAxis()
: cellSet.getAxes().get(axis);
List<Position> positions = _axis.getPositions();
final CellSetAxis _axis = cellSet.getAxes().get(axis);
final List<Position> positions = _axis.getPositions();
final int positionCount = positions.size();
for (int i = 0; i < positionCount; i++) {
if (axis < 0) {
if (i > 0) {
pw.print(", ");
}
pos.set(axis, i);
if (axis == 0) {
int row =
axis + 1 < pos.size()
? pos.get(axis + 1)
: 0;
pw.print("Row #" + row + ": ");
printCell(cellSet, pw, pos);
pw.println();
} else {
pos.set(axis, i);
if (axis == 0) {
int row =
axis + 1 < pos.size()
? pos.get(axis + 1)
: 0;
pw.print("Row #" + row + ": ");
}
printRows(cellSet, pw, axis - 1, pos);
if (axis == 0) {
pw.println();
}
}
}
}
Expand Down
87 changes: 85 additions & 2 deletions testsrc/org/olap4j/CellSetFormatterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ public enum Format {
// ~ Tests follow ==========================================================

public void testQuery1Traditional() throws SQLException {
final TestContext.Tester.Flavor flavor =
TestContext.instance().getTester().getFlavor();
assertFormat(
query1,
Format.TRADITIONAL,
Expand Down Expand Up @@ -316,6 +314,91 @@ public void testEmptyColumnsRectangular() throws SQLException {
+ "| | | WA | |\n");
}

public void testFilter() throws SQLException {
final String queryString =
"select\n"
+ " crossjoin(\n"
+ " {[Time].[1997].[Q1], [Time].[1997].[Q2].[4]},\n"
+ " {[Measures].[Unit Sales]}) on 0,\n"
+ " {[USA].[CA].[Los Angeles],\n"
+ " [USA].[CA].[San Francisco]} on 1\n"
+ "FROM [Sales]\n"
+ "WHERE ([Gender].[M], [Marital Status].[S])";

assertFormat(
queryString,
Format.TRADITIONAL,
"Axis #0:\n"
+ "{[Gender].[M], [Marital Status].[S]}\n"
+ "Axis #1:\n"
+ "{[Time].[1997].[Q1], [Measures].[Unit Sales]}\n"
+ "{[Time].[1997].[Q2].[4], [Measures].[Unit Sales]}\n"
+ "Axis #2:\n"
+ "{[Store].[USA].[CA].[Los Angeles]}\n"
+ "{[Store].[USA].[CA].[San Francisco]}\n"
+ "Row #0: 1,615\n"
+ "Row #0: 594\n"
+ "Row #1: 101\n"
+ "Row #1: 55\n");

// TODO: rectagular formatter should print filter
assertFormat(
queryString,
Format.COMPACT_RECTANGULAR,
" 1997 \n"
+ " Q1 Q2\n"
+ " 4\n"
+ " Unit Sales Unit Sales\n"
+ "=== == ============= ========== ==========\n"
+ "USA CA Los Angeles 1,615 594\n"
+ " San Francisco 101 55\n");

// TODO: rectagular formatter should print filter
assertFormat(
queryString,
Format.RECTANGULAR,
"| | 1997 |\n"
+ "| | Q1 | Q2 |\n"
+ "| | | 4 |\n"
+ "| | Unit Sales | Unit Sales |\n"
+ "+-----+----+---------------+------------+------------+\n"
+ "| USA | CA | Los Angeles | 1,615 | 594 |\n"
+ "| | | San Francisco | 101 | 55 |\n");
}

public void testFilterCompound() throws SQLException {
final String queryString =
"select\n"
+ " crossjoin(\n"
+ " {[Time].[1997].[Q1], [Time].[1997].[Q2].[4]},\n"
+ " {[Measures].[Unit Sales]}) on 0,\n"
+ " {[USA].[CA].[Los Angeles],\n"
+ " [USA].[CA].[San Francisco]} on 1\n"
+ "FROM [Sales]\n"
+ "WHERE [Gender].Children * [Marital Status].Members";

assertFormat(
queryString,
Format.TRADITIONAL,
"Axis #0:\n"
+ "{[Gender].[F], [Marital Status].[All Marital Status]}\n"
+ "{[Gender].[F], [Marital Status].[M]}\n"
+ "{[Gender].[F], [Marital Status].[S]}\n"
+ "{[Gender].[M], [Marital Status].[All Marital Status]}\n"
+ "{[Gender].[M], [Marital Status].[M]}\n"
+ "{[Gender].[M], [Marital Status].[S]}\n"
+ "Axis #1:\n"
+ "{[Time].[1997].[Q1], [Measures].[Unit Sales]}\n"
+ "{[Time].[1997].[Q2].[4], [Measures].[Unit Sales]}\n"
+ "Axis #2:\n"
+ "{[Store].[USA].[CA].[Los Angeles]}\n"
+ "{[Store].[USA].[CA].[San Francisco]}\n"
+ "Row #0: 6,373\n"
+ "Row #0: 1,865\n"
+ "Row #1: 439\n"
+ "Row #1: 149\n");
}

public void testZeroAxesRectangular() throws SQLException {
final String mdx =
"select\n"
Expand Down
91 changes: 71 additions & 20 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,12 @@ public void testAxes() throws SQLException {
assertEquals(0, position.getMembers().size());
}

public void testCompoundSlicer() throws SQLException {
/**
* Tests a filter with more than one position.
*
* @throws SQLException on error
*/
public void testCompoundFilter() throws SQLException {
connection = tester.createConnection();
OlapConnection olapConnection =
tester.getWrapper().unwrap(connection, OlapConnection.class);
Expand All @@ -531,30 +536,76 @@ public void testCompoundSlicer() throws SQLException {
CellSet cellSet =
statement.executeOlapQuery(
"SELECT {[Measures].[Unit Sales]} on 0,\n"
+ "{[Store].Children} on 1\n"
+ "{[Product].Children} on 1\n"
+ "FROM [Sales]\n"
+ "WHERE [Time].[1997].[Q1] * [Gender].Members");
List<CellSetAxis> axesList = cellSet.getAxes();
assertEquals(2, axesList.size());
final CellSetAxis filterAxis = cellSet.getFilterAxis();
final Tester.Flavor flavor =
TestContext.instance().getTester().getFlavor();
switch (flavor) {
case MONDRIAN:
assertEquals(1, filterAxis.getPositionCount());
break;
case XMLA:
case REMOTE_XMLA:
assertEquals(3, filterAxis.getPositionCount());
final List<Position> filterPositions = filterAxis.getPositions();
assertEquals(3, filterPositions.size());
final Position filterPosition = filterPositions.get(2);
assertEquals(2, filterPosition.getMembers().size());
assertEquals("M", filterPosition.getMembers().get(1).getName());
break;
default:
throw Olap4jUtil.unexpected(flavor);
}
assertEquals(3, filterAxis.getPositionCount());
final List<Position> filterPositions = filterAxis.getPositions();
assertEquals(3, filterPositions.size());
final Position filterPosition = filterPositions.get(2);
assertEquals(2, filterPosition.getMembers().size());
assertEquals("M", filterPosition.getMembers().get(1).getName());
}

/**
* Tests a filter with zero positions.
*
* @throws SQLException on error
*/
public void testEmptyFilter() throws SQLException {
connection = tester.createConnection();
OlapConnection olapConnection =
tester.getWrapper().unwrap(connection, OlapConnection.class);
OlapStatement statement = olapConnection.createStatement();

CellSet cellSet =
statement.executeOlapQuery(
"SELECT {[Measures].[Unit Sales]} on 0,\n"
+ "{[Product].Children} on 1\n"
+ "FROM [Sales]\n"
+ "WHERE [Time].[1997].[Q1] * [Gender].Parent");
List<CellSetAxis> axesList = cellSet.getAxes();
assertEquals(2, axesList.size());
final CellSetAxis filterAxis = cellSet.getFilterAxis();
assertEquals(0, filterAxis.getPositionCount());
final List<Position> filterPositions = filterAxis.getPositions();
assertEquals(0, filterPositions.size());
assertEquals(2, filterAxis.getAxisMetaData().getHierarchies().size());
final Cell cell = cellSet.getCell(Arrays.asList(0, 0));
assertTrue(cell.isNull());
}

/**
* Tests a query with no filter (no WHERE clause).
*
* @throws SQLException on error
*/
public void testMissingFilter() throws SQLException {
connection = tester.createConnection();
OlapConnection olapConnection =
tester.getWrapper().unwrap(connection, OlapConnection.class);
OlapStatement statement = olapConnection.createStatement();
CellSet cellSet =
statement.executeOlapQuery(
"SELECT {[Measures].[Unit Sales]} on 0,\n"
+ "{[Product].Children} on 1\n"
+ "FROM [Sales]\n");
List<CellSetAxis> axesList = cellSet.getAxes();
assertEquals(2, axesList.size());
final CellSetAxis filterAxis = cellSet.getFilterAxis();
assertEquals(1, filterAxis.getPositionCount());
final List<Position> filterPositions = filterAxis.getPositions();
assertEquals(1, filterPositions.size());
final Position position = filterPositions.get(0);
assertEquals(0, position.getMembers().size());
assertEquals(
0, filterAxis.getAxisMetaData().getHierarchies().size());
assertTrue(filterAxis.getAxisMetaData().getHierarchies().isEmpty());
final Cell cell = cellSet.getCell(Arrays.asList(0, 0));
assertEquals("24,597", cell.getFormattedValue());
}

public void testMeasureVersusMemberCasting() throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion testsrc/org/olap4j/test/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static String toString(ParseTreeNode node) {
public static String toString(CellSet cellSet) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
new TraditionalCellSetFormatter().format(cellSet, pw);
new TraditionalCellSetFormatter().format(cellSet, pw);
pw.flush();
return sw.toString();
}
Expand Down

0 comments on commit 5732212

Please sign in to comment.