Skip to content

Commit

Permalink
Add constructor for IdentifierNode which takes a list (convenient for…
Browse files Browse the repository at this point in the history
… calling with the result from IdentifierNode.parseIdentifier); Test case for building MDX parse tree programmatically and executing as query.

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@66 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Jan 24, 2008
1 parent aeffdfb commit afa7d80
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/org/olap4j/mdx/AxisNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.PrintWriter;
import java.util.List;
import java.util.Collections;

import org.olap4j.Axis;
import org.olap4j.type.Type;
Expand All @@ -28,7 +29,7 @@ public class AxisNode implements ParseTreeNode {
private ParseTreeNode expression;
private final Axis axis;

private final List<IdentifierNode> dimensionProperties;
private final List<IdentifierNode> dimensionProperties;

/**
* Creates an axis.
Expand All @@ -38,7 +39,8 @@ public class AxisNode implements ParseTreeNode {
* are all empty
* @param expression Expression to populate the axis
* @param axisDef Which axis (ROWS, COLUMNS, etc.)
* @param dimensionProperties List of dimension properties
* @param dimensionProperties List of dimension properties; if null,
* empty list is assumed
*/
public AxisNode(
ParseRegion region,
Expand All @@ -48,10 +50,12 @@ public AxisNode(
List<IdentifierNode> dimensionProperties)
{
this.region = region;
assert dimensionProperties != null;
this.nonEmpty = nonEmpty;
this.expression = expression;
this.axis = axisDef;
if (dimensionProperties == null) {
dimensionProperties = Collections.emptyList();
}
this.dimensionProperties = dimensionProperties;
}

Expand Down
2 changes: 1 addition & 1 deletion src/org/olap4j/mdx/IdentifierNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public IdentifierNode(IdentifierNode.Segment... segments) {
*
* @param segments List of segments
*/
private IdentifierNode(List<IdentifierNode.Segment> segments) {
public IdentifierNode(List<IdentifierNode.Segment> segments) {
if (segments.size() < 1) {
throw new IllegalArgumentException();
}
Expand Down
78 changes: 78 additions & 0 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,84 @@ public void testCellSetWithCalcMember() throws SQLException {
"Row #1: $3.94\n" +
"Row #2: $3.93\n"), TestContext.toString(cellSet));
}

public void testBuildQuery() throws SQLException {
Connection connection = tester.createConnection();
OlapConnection olapConnection =
((OlapWrapper) connection).unwrap(OlapConnection.class);
buildQuery(olapConnection, true);
buildQuery(olapConnection, false);
}

private void buildQuery(
OlapConnection olapConnection,
boolean useCubeObject)
throws OlapException
{
final String catalogName;
switch (tester.getFlavor()) {
case MONDRIAN:
catalogName = "LOCALDB";
break;
case XMLA:
default:
catalogName = "FoodMart";
break;
}
Catalog catalog = olapConnection.getCatalogs().get(catalogName);
Schema schema = catalog.getSchemas().get("FoodMart");
Cube cube = schema.getCubes().get("Sales");
SelectNode query = new SelectNode();
ParseTreeNode cubeNode;
if (useCubeObject) {
cubeNode = new IdentifierNode(
IdentifierNode.parseIdentifier(cube.getUniqueName()));
} else {
cubeNode = new CubeNode(null, cube);
}
query.setFrom(cubeNode);
AxisNode columnAxis =
new AxisNode(
null, false,
new CallNode(
null, "MEMBERS", Syntax.Property,
new IdentifierNode(
IdentifierNode.parseIdentifier("[Gender]"))),
Axis.COLUMNS, null);
AxisNode rowAxis =
new AxisNode(
null, false,
new CallNode(
null, "CHILDREN", Syntax.Property,
new IdentifierNode(
IdentifierNode.parseIdentifier("[Customers].[USA]"))),
Axis.ROWS, null);
query.getAxisList().add(columnAxis);
query.getAxisList().add(rowAxis);
OlapStatement statement = olapConnection.createStatement();
CellSet cellSet = statement.executeOlapQuery(query);
TestContext.assertEqualsVerbose(TestContext.fold(
"Axis #0:\n" +
"{[Measures].[Unit Sales], [Store].[All Stores], [Store Size in SQFT].[All Store Size in SQFTs], [Store Type].[All Store Types], [Time].[1997], [Product].[All Products], [Promotion Media].[All Media], [Promotions].[All Promotions], [Education Level].[All Education Levels], [Marital Status].[All Marital Status], [Yearly Income].[All Yearly Incomes]}\n" +
"Axis #1:\n" +
"{[Gender].[All Gender]}\n" +
"{[Gender].[All Gender].[F]}\n" +
"{[Gender].[All Gender].[M]}\n" +
"Axis #2:\n" +
"{[Customers].[All Customers].[USA].[CA]}\n" +
"{[Customers].[All Customers].[USA].[OR]}\n" +
"{[Customers].[All Customers].[USA].[WA]}\n" +
"Row #0: 74,748\n" +
"Row #0: 36,759\n" +
"Row #0: 37,989\n" +
"Row #1: 67,659\n" +
"Row #1: 33,036\n" +
"Row #1: 34,623\n" +
"Row #2: 124,366\n" +
"Row #2: 61,763\n" +
"Row #2: 62,603\n"),
TestContext.toString(cellSet));
}
}

// End ConnectionTest.java

0 comments on commit afa7d80

Please sign in to comment.