Skip to content

Commit

Permalink
Switch order of parameters to AxisNode (it's easier to write code if …
Browse files Browse the repository at this point in the history
…the bulky expression comes last). Fix 'jar' build on windows. Push up memory for unit test (in-process XMLA test is hungry).

git-svn-id: https://olap4j.svn.sourceforge.net/svnroot/olap4j/trunk@69 c6a108a4-781c-0410-a6c6-c2d559e19af0
  • Loading branch information
julianhyde committed Feb 2, 2008
1 parent 3e562cf commit 091e638
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 32 deletions.
7 changes: 4 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
== This software is subject to the terms of the Common Public License
== Agreement, available at the following URL:
== http://www.opensource.org/licenses/cpl.html.
== Copyright (C) 2006-2007 Julian Hyde and others.
== Copyright (C) 2006-2008 Julian Hyde and others.
== All Rights Reserved.
== You must accept the terms of that agreement to use this software.
-->
Expand Down Expand Up @@ -314,7 +314,8 @@ must be run under JDK 1.5." />
</target>

<target name="compileJdk16">
<exec executable="buildJdk16.sh"/>
<exec os="linux" executable="buildJdk16.sh"/>
<exec os="windows" executable="buildJdk16.bat"/>
</target>

<target name="jar" depends="version,checkIsNotJdk16,compile,compileJdk16">
Expand Down Expand Up @@ -518,7 +519,7 @@ META-INF/**"/>
</fileset>
</batchtest>
<classpath refid="project.test.classpath"/>
<jvmarg value="-Xmx256m"/>
<jvmarg value="-Xmx512m"/>
</junit>
</target>

Expand Down
2 changes: 1 addition & 1 deletion src/org/olap4j/driver/xmla/DeferredNamedListImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public int indexOfName(String name) {

protected void populateList(NamedList<T> list) throws OlapException {
context.olap4jConnection.populateList(
list, context, metadataRequest, handler);
list, context, metadataRequest, handler, new Object[0]);
}

private enum State {
Expand Down
2 changes: 1 addition & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jCellSetAxis.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public int getPositionCount() {
}

public ListIterator<Position> iterator() {
return (ListIterator<Position>) immutablePositions.iterator();
return immutablePositions.listIterator();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/org/olap4j/driver/xmla/XmlaOlap4jDatabaseMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,8 @@ public String getMdxKeywords() throws OlapException {
new XmlaOlap4jConnection.Context(
olap4jConnection, null, null, null, null, null, null, null);
String request =
olap4jConnection.generateRequest(context, metadataRequest);
olap4jConnection.generateRequest(
context, metadataRequest, new Object[0]);
final Element root = olap4jConnection.xxx(request);
StringBuilder buf = new StringBuilder();
for (Element row : XmlaOlap4jUtil.childElements(root)) {
Expand Down
6 changes: 3 additions & 3 deletions src/org/olap4j/mdx/AxisNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public class AxisNode implements ParseTreeNode {
* @param region Region of source code
* @param nonEmpty Whether to filter out members of this axis whose cells
* are all empty
* @param expression Expression to populate the axis
* @param axisDef Which axis (ROWS, COLUMNS, etc.)
* @param dimensionProperties List of dimension properties; if null,
* empty list is assumed
* @param expression Expression to populate the axis
*/
public AxisNode(
ParseRegion region,
boolean nonEmpty,
ParseTreeNode expression,
Axis axisDef,
List<IdentifierNode> dimensionProperties)
List<IdentifierNode> dimensionProperties,
ParseTreeNode expression)
{
this.region = region;
this.nonEmpty = nonEmpty;
Expand Down
8 changes: 4 additions & 4 deletions src/org/olap4j/mdx/parser/impl/DefaultMdxParser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ parser code {:
filter == null ?
null :
new AxisNode(
filter.getRegion(), false, filter, Axis.FILTER,
Collections.EMPTY_LIST);
filter.getRegion(), false, Axis.FILTER,
Collections.EMPTY_LIST, filter);
// sort axes by ordinal
Collections.sort(axisList, new Comparator<AxisNode>() {
public int compare(AxisNode o1, AxisNode o2) {
Expand Down Expand Up @@ -1418,7 +1418,7 @@ axis_specification ::=
Axis axis = Axis.valueOf(a.toUpperCase());
ParseRegion region = createRegion(
bleft, bright, sleft, sright, dpleft, dpright, aleft, aright);
RESULT = new AxisNode(region, b, s, axis, emptyList(dp));
RESULT = new AxisNode(region, b, axis, emptyList(dp), s);
:}
| non_empty_opt:b expression:s dim_props_opt:dp ON axis_number:n {:
double d = n.doubleValue();
Expand All @@ -1436,7 +1436,7 @@ axis_specification ::=
Axis axis = Axis.forOrdinal(index);
ParseRegion region = createRegion(
bleft, bright, sleft, sright, dpleft, dpright, nleft, nright);
RESULT = new AxisNode(region, b, s, axis, emptyList(dp));
RESULT = new AxisNode(region, b, axis, emptyList(dp), s);
:}
;

Expand Down
6 changes: 3 additions & 3 deletions src/org/olap4j/sample/SimpleQuerySample.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ void executeSelectNode(OlapConnection connection) {
new AxisNode(
null,
false,
Axis.ROWS,
new ArrayList<IdentifierNode>(),
new CallNode(
null,
"{}",
Syntax.Braces,
new IdentifierNode(
new IdentifierNode.Segment("Measures"),
new IdentifierNode.Segment("Unit Sales"))),
Axis.ROWS,
new ArrayList<IdentifierNode>()));
new IdentifierNode.Segment("Unit Sales")))));

// Create a statement based upon the query model.
OlapStatement stmt;
Expand Down
109 changes: 93 additions & 16 deletions testsrc/org/olap4j/ConnectionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,9 @@ public void testUnparsing() {
new AxisNode(
null,
false,
null,
Axis.FILTER,
new ArrayList<IdentifierNode>()),
new ArrayList<IdentifierNode>(),
null),
new ArrayList<IdentifierNode>());
select.getWithList().add(
new WithMemberNode(
Expand All @@ -1029,20 +1029,23 @@ public void testUnparsing() {
new AxisNode(
null,
false,
Axis.COLUMNS,
new ArrayList<IdentifierNode>(),
new CallNode(
null,
"{}",
Syntax.Braces,
Arrays.asList(
(ParseTreeNode)
new IdentifierNode(
new IdentifierNode.Segment("Gender")))),
Axis.COLUMNS,
new ArrayList<IdentifierNode>()));
new IdentifierNode.Segment("Gender"))))
));
select.getAxisList().add(
new AxisNode(
null,
false,
Axis.ROWS,
new ArrayList<IdentifierNode>(),
new CallNode(
null,
"{}",
Expand All @@ -1052,10 +1055,7 @@ public void testUnparsing() {
"Children",
Syntax.Property,
new IdentifierNode(
new IdentifierNode.Segment("Store"))
)),
Axis.ROWS,
new ArrayList<IdentifierNode>()));
new IdentifierNode.Segment("Store"))))));
select.getFilterAxis().setExpression(
new IdentifierNode(
new IdentifierNode.Segment("Time"),
Expand All @@ -1073,7 +1073,7 @@ public void testCubeLookupMember() throws Exception {
Connection connection = tester.createConnection();
OlapConnection olapConnection =
((OlapWrapper) connection).unwrap(OlapConnection.class);
Cube cube = olapConnection.getSchema().getCubes().get("Sales");
Cube cube = olapConnection.getSchema().getCubes().get("Sales Ragged");

Member member =
cube.lookupMember(
Expand Down Expand Up @@ -1796,20 +1796,18 @@ private void buildQuery(
query.setFrom(cubeNode);
AxisNode columnAxis =
new AxisNode(
null, false,
null, false, Axis.COLUMNS, null,
new CallNode(
null, "MEMBERS", Syntax.Property,
new IdentifierNode(
IdentifierNode.parseIdentifier("[Gender]"))),
Axis.COLUMNS, null);
IdentifierNode.parseIdentifier("[Gender]"))));
AxisNode rowAxis =
new AxisNode(
null, false,
null, false, Axis.ROWS, null,
new CallNode(
null, "CHILDREN", Syntax.Property,
new IdentifierNode(
IdentifierNode.parseIdentifier("[Customers].[USA]"))),
Axis.ROWS, null);
IdentifierNode.parseIdentifier("[Customers].[USA]"))));
query.getAxisList().add(columnAxis);
query.getAxisList().add(rowAxis);
OlapStatement statement = olapConnection.createStatement();
Expand All @@ -1836,6 +1834,85 @@ private void buildQuery(
"Row #2: 62,603\n"),
TestContext.toString(cellSet));
}

public void testBuildQuery2() throws ClassNotFoundException, SQLException {
Connection connection = tester.createConnection();
OlapConnection olapConnection =
((OlapWrapper) connection).unwrap(OlapConnection.class);

Schema schema = olapConnection.getSchema();
Cube cube = schema.getCubes().get("Sales");
Measure measure = cube.getMeasures().get(0);
Dimension dimPromotionMedia = cube.getDimensions().get("Promotion Media");
//
// IdentifierNode cubeNode = new IdentifierNode(new IdentifierNode.Segment(cube.getUniqueName()));
CubeNode cubeNode = new CubeNode(null, cube);
MemberNode measuresQuantity = new MemberNode(null, measure);
HierarchyNode promotionHierarchyNode =
new HierarchyNode(null, dimPromotionMedia.getDefaultHierarchy());
CallNode promotionChildren =
new CallNode(
null, "children", Syntax.Property, promotionHierarchyNode);
//
List<IdentifierNode> columnDimensionProperties =
new ArrayList<IdentifierNode>();
AxisNode columnAxis =
new AxisNode(
null, false,
Axis.COLUMNS,
columnDimensionProperties,
new CallNode(null, "{}", Syntax.Braces, measuresQuantity));
List<IdentifierNode> rowDimensionProperties =
new ArrayList<IdentifierNode>();
AxisNode rowAxis =
new AxisNode(
null, false,
Axis.ROWS,
rowDimensionProperties,
new CallNode(null, "{}", Syntax.Braces, promotionChildren));
//
SelectNode query = new SelectNode();
query.setFrom(cubeNode);
query.getAxisList().add(columnAxis);
query.getAxisList().add(rowAxis);
//
OlapStatement statement = olapConnection.createStatement();
CellSet cellSet = statement.executeOlapQuery(query);
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
for (Position row : cellSet.getAxes().get(1)) {
for (Position column : cellSet.getAxes().get(0)) {
pw.print("ROW:");
for (Member member : row.getMembers()) {
pw.print("[" + member.getName() + "]");
}
pw.print(" COL:");
for (Member member : column.getMembers()) {
pw.print("[" + member.getName() + "]");
}
Cell cell = cellSet.getCell(column, row);
pw.println(" CELL:" + cell.getFormattedValue());
}
}
pw.flush();
TestContext.assertEqualsVerbose(
TestContext.fold(
"ROW:[Bulk Mail] COL:[Customer Count] CELL:333\n" +
"ROW:[Cash Register Handout] COL:[Customer Count] CELL:482\n" +
"ROW:[Daily Paper] COL:[Customer Count] CELL:528\n" +
"ROW:[Daily Paper, Radio] COL:[Customer Count] CELL:499\n" +
"ROW:[Daily Paper, Radio, TV] COL:[Customer Count] CELL:687\n" +
"ROW:[In-Store Coupon] COL:[Customer Count] CELL:290\n" +
"ROW:[No Media] COL:[Customer Count] CELL:5,043\n" +
"ROW:[Product Attachment] COL:[Customer Count] CELL:532\n" +
"ROW:[Radio] COL:[Customer Count] CELL:186\n" +
"ROW:[Street Handout] COL:[Customer Count] CELL:381\n" +
"ROW:[Sunday Paper] COL:[Customer Count] CELL:307\n" +
"ROW:[Sunday Paper, Radio] COL:[Customer Count] CELL:422\n" +
"ROW:[Sunday Paper, Radio, TV] COL:[Customer Count] CELL:196\n" +
"ROW:[TV] COL:[Customer Count] CELL:274\n"),
sw.toString());
}
}

// End ConnectionTest.java

0 comments on commit 091e638

Please sign in to comment.