Skip to content

Commit

Permalink
Clarify what the slicer axis contains if the query has no WHERE claus…
Browse files Browse the repository at this point in the history
…e; clarify Cell.getFormattedValue() if the value is NULL; and add testcase for query with no slicer.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@60 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jan 10, 2008
1 parent cbbba63 commit c257ba6
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/org/olap4j/Cell.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public interface Cell {
* FORMAT_STRING property and using the numeric formatting tokens the
* current locale.
*
* <p>The formatted value is never null. In particular, when the cell
* contains the MDX NULL value, {@link #getValue()} will return the Java
* <code>null</code> value but this method will return the empty string
* <code>""</code>.
*
* @return Formatted value of this Cell
*/
String getFormattedValue();
Expand All @@ -159,6 +164,8 @@ public interface Cell {
* <p>If drill-through is not possible, returns null.
*
* @return result set of the fact rows underlying this Cell
*
* @throws OlapException if a database error occurs
*/
ResultSet drillThrough() throws OlapException;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jCellSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private Cell getCellInternal(int pos) {
// Cell is within bounds, but is not held in the cache because
// it has no value. Manufacture a cell with an empty value.
return new XmlaOlap4jCell(
this, pos, null, null,
this, pos, null, "",
Collections.<Property, Object>emptyMap());
}
}
Expand Down
80 changes: 77 additions & 3 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,20 @@ public void testCellSetMetaData() throws SQLException {
OlapConnection olapConnection =
((OlapWrapper) connection).unwrap(OlapConnection.class);

final String mdx =
checkCellSetMetaData1(
olapConnection,
"select {[Gender]} on columns from [sales]\n" +
"where [Time].[1997].[Q4]";
"where [Time].[1997].[Q4]");

// now a query with no explicit slicer
checkCellSetMetaData1(
olapConnection,
"select {[Gender]} on columns from [sales]");
}

private void checkCellSetMetaData1(
OlapConnection olapConnection, String mdx) throws SQLException
{
PreparedOlapStatement pstmt =
olapConnection.prepareOlapStatement(mdx);
final CellSetMetaData cellSetMetaData = pstmt.getMetaData();
Expand Down Expand Up @@ -555,13 +566,15 @@ private void checkCellSetMetaData(
assertEquals("Sales", cellSetMetaData.getCube().getName());

int k = -1;
int hierarchyCount = 0;
for (CellSetAxisMetaData axisMetaData
: cellSetMetaData.getAxesMetaData())
{
++k;
assertEquals(Axis.forOrdinal(k), axisMetaData.getAxisOrdinal());
assertEquals(k, axisMetaData.getAxisOrdinal().axisOrdinal());
assertTrue(axisMetaData.getHierarchies().size() > 0);
hierarchyCount += axisMetaData.getHierarchies().size();
assertTrue(axisMetaData.getProperties().size() == 0);
if (cellSet != null) {
final CellSetAxisMetaData cellSetAxisMetaData =
Expand All @@ -574,7 +587,11 @@ private void checkCellSetMetaData(
cellSetMetaData.getFilterAxisMetaData();
assertNotNull(axisMetaData);
assertEquals(Axis.FILTER, axisMetaData.getAxisOrdinal());
assertTrue(axisMetaData.getHierarchies().size() > 0);
assertTrue(axisMetaData.getHierarchies().size() >= 0);
assertEquals(
axisMetaData.getHierarchies().size(),
cellSetMetaData.getCube().getHierarchies().size()
- hierarchyCount);
assertTrue(axisMetaData.getProperties().size() == 0);
if (cellSet != null) {
assertEquals(
Expand Down Expand Up @@ -1654,6 +1671,63 @@ public void testStatementTimeout() throws Throwable {
assertTrue(e.getMessage().indexOf("Query timeout of ") >= 0);
}
}

public void testCellSetBug() throws SQLException {
Connection connection = tester.createConnection();
OlapConnection olapConnection =
((OlapWrapper) connection).unwrap(OlapConnection.class);
final OlapStatement olapStatement = olapConnection.createStatement();
CellSet cellSet =
olapStatement.executeOlapQuery(
"SELECT " +
"{[Product].[All Products].[Drink].[Alcoholic Beverages].Children, [Product].[All Products].[Food].[Baked Goods].Children} ON COLUMNS, " +
"CrossJoin([Store].[All Stores].[USA].[CA].Children, [Time].[1997].[Q1].Children) ON ROWS " +
"FROM [Sales Ragged]");
TestContext.assertEqualsVerbose(
TestContext.fold("Axis #0:\n" +
"{[Measures].[Unit Sales], [Geography].[All Geographys], [Store Size in SQFT].[All Store Size in SQFTs], [Store Type].[All Store Types], [Promotion Media].[All Media], [Promotions].[All Promotions], [Customers].[All Customers], [Education Level].[All Education Levels], [Gender].[All Gender], [Marital Status].[All Marital Status], [Yearly Income].[All Yearly Incomes]}\n" +
"Axis #1:\n" +
"{[Product].[All Products].[Drink].[Alcoholic Beverages].[Beer and Wine]}\n" +
"{[Product].[All Products].[Food].[Baked Goods].[Bread]}\n" +
"Axis #2:\n" +
"{[Store].[All Stores].[USA].[CA].[Alameda], [Time].[1997].[Q1].[1]}\n" +
"{[Store].[All Stores].[USA].[CA].[Alameda], [Time].[1997].[Q1].[2]}\n" +
"{[Store].[All Stores].[USA].[CA].[Alameda], [Time].[1997].[Q1].[3]}\n" +
"{[Store].[All Stores].[USA].[CA].[Beverly Hills], [Time].[1997].[Q1].[1]}\n" +
"{[Store].[All Stores].[USA].[CA].[Beverly Hills], [Time].[1997].[Q1].[2]}\n" +
"{[Store].[All Stores].[USA].[CA].[Beverly Hills], [Time].[1997].[Q1].[3]}\n" +
"{[Store].[All Stores].[USA].[CA].[Los Angeles], [Time].[1997].[Q1].[1]}\n" +
"{[Store].[All Stores].[USA].[CA].[Los Angeles], [Time].[1997].[Q1].[2]}\n" +
"{[Store].[All Stores].[USA].[CA].[Los Angeles], [Time].[1997].[Q1].[3]}\n" +
"{[Store].[All Stores].[USA].[CA].[San Francisco], [Time].[1997].[Q1].[1]}\n" +
"{[Store].[All Stores].[USA].[CA].[San Francisco], [Time].[1997].[Q1].[2]}\n" +
"{[Store].[All Stores].[USA].[CA].[San Francisco], [Time].[1997].[Q1].[3]}\n" +
"Row #0: \n" +
"Row #0: \n" +
"Row #1: \n" +
"Row #1: \n" +
"Row #2: \n" +
"Row #2: \n" +
"Row #3: 22\n" +
"Row #3: 63\n" +
"Row #4: 28\n" +
"Row #4: 59\n" +
"Row #5: 28\n" +
"Row #5: 39\n" +
"Row #6: 70\n" +
"Row #6: 51\n" +
"Row #7: 89\n" +
"Row #7: 51\n" +
"Row #8: 27\n" +
"Row #8: 54\n" +
"Row #9: 6\n" +
"Row #9: 2\n" +
"Row #10: 3\n" +
"Row #10: 7\n" +
"Row #11: 2\n" +
"Row #11: 10\n"),
TestContext.toString(cellSet));
}
}

// End ConnectionTest.java

0 comments on commit c257ba6

Please sign in to comment.