Skip to content

Commit

Permalink
Update the test case
Browse files Browse the repository at this point in the history
  • Loading branch information
pshi authored and mwu committed Mar 8, 2013
1 parent b8c8aa6 commit 626f820
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,148 @@ public void testGroupFilter7( ) throws Exception
checkOutputFile();
}

public void testGroupFilter8( ) throws Exception
{
QueryDefinition query = super.newReportQuery( );
query.addBinding( new Binding( "ID", new ScriptExpression( "dataSetRow[\"ID\"]" ) ) );
query.addBinding( new Binding( "COUNTRY", new ScriptExpression( "dataSetRow[\"COUNTRY\"]" ) ) );
query.addBinding( new Binding( "STATE", new ScriptExpression( "dataSetRow[\"STATE\"]" ) ) );
query.addBinding( new Binding( "CITY", new ScriptExpression( "dataSetRow[\"CITY\"]" ) ) );
query.addBinding( new Binding( "AMOUNT", new ScriptExpression( "dataSetRow[\"AMOUNT\"]" ) ) );

GroupDefinition g1 = new GroupDefinition( "G1" );
g1.setKeyExpression( "row[\"COUNTRY\"]" );
query.addGroup( g1 );

GroupDefinition g2 = new GroupDefinition( "G2" );
g2.setKeyExpression( "row[\"STATE\"]" );
query.addGroup( g2 );

GroupDefinition g3 = new GroupDefinition( "G3" );
g3.setKeyExpression( "row[\"CITY\"]" );
query.addGroup( g3 );
g3.addFilter( new FilterDefinition( new ScriptExpression("row[\"SumAll\"] < 100"), false) );
FilterDefinition f1 = new FilterDefinition( new ConditionalExpression( "row[\"SumAll\"]" , IConditionalExpression.OP_TOP_N, "1" ), false );
query.addFilter( f1 );


SortDefinition sort = new SortDefinition( );
sort.setExpression( "row[\"COUNTRY\"]" );
sort.setSortDirection( ISortDefinition.SORT_ASC );
query.addSort( sort );
sort.setExpression( "row[\"STATE\"]" );
sort.setSortDirection( ISortDefinition.SORT_ASC );
query.addSort( sort );
sort.setExpression( "row[\"CITY\"]" );
sort.setSortDirection( ISortDefinition.SORT_ASC );
query.addSort( sort );

IBinding e5 = new Binding( "CountG1" );
e5.setAggrFunction( "COUNT" );
e5.addAggregateOn( "G1" );
query.addBinding( e5 );

IBinding e6 = new Binding( "CountG2");
e6.setAggrFunction( "COUNT" );
e6.addAggregateOn( "G2" );
query.addBinding( e6 );

IBinding e7 = new Binding( "CountG3" );
e7.setAggrFunction( "COUNT" );
e7.addAggregateOn( "G3" );
query.addBinding( e7 );

IBinding e81 = new Binding( "SumAll", new ScriptExpression("row[\"AMOUNT\"]"));
e81.setAggrFunction( "SUM" );
e81.addAggregateOn( "G2" );
query.addBinding( e81 );

IBinding e9 = new Binding( "TopN" );
e9.setAggrFunction( "ISBOTTOMN" );
e9.addAggregateOn( "G1" );
e9.addArgument( new ScriptExpression("row[\"SumAll\"]") );
e9.addArgument( new ScriptExpression("1") );
query.addBinding( e9 );

String[] exprs = new String[]{
"ID", "COUNTRY", "STATE", "CITY", "AMOUNT", "CountG1", "CountG2", "CountG3", "SumAll", "TopN"
};

outputQueryResult( executeQuery( query ), exprs );
checkOutputFile();
}

public void testGroupFilter9( ) throws Exception
{
QueryDefinition query = super.newReportQuery( );
query.addBinding( new Binding( "ID", new ScriptExpression( "dataSetRow[\"ID\"]" ) ) );
query.addBinding( new Binding( "COUNTRY", new ScriptExpression( "dataSetRow[\"COUNTRY\"]" ) ) );
query.addBinding( new Binding( "STATE", new ScriptExpression( "dataSetRow[\"STATE\"]" ) ) );
query.addBinding( new Binding( "CITY", new ScriptExpression( "dataSetRow[\"CITY\"]" ) ) );
query.addBinding( new Binding( "AMOUNT", new ScriptExpression( "dataSetRow[\"AMOUNT\"]" ) ) );

GroupDefinition g1 = new GroupDefinition( "G1" );
g1.setKeyExpression( "row[\"COUNTRY\"]" );
query.addGroup( g1 );

GroupDefinition g2 = new GroupDefinition( "G2" );
g2.setKeyExpression( "row[\"STATE\"]" );
query.addGroup( g2 );

GroupDefinition g3 = new GroupDefinition( "G3" );
g3.setKeyExpression( "row[\"CITY\"]" );
query.addGroup( g3 );
g3.addFilter( new FilterDefinition( new ScriptExpression("row[\"SumAll\"] < 100")) );
FilterDefinition f1 = new FilterDefinition( new ConditionalExpression( "row[\"SumAll\"]" , IConditionalExpression.OP_TOP_N, "1" ), false );
query.addFilter( f1 );


SortDefinition sort = new SortDefinition( );
sort.setExpression( "row[\"COUNTRY\"]" );
sort.setSortDirection( ISortDefinition.SORT_ASC );
query.addSort( sort );
sort.setExpression( "row[\"STATE\"]" );
sort.setSortDirection( ISortDefinition.SORT_ASC );
query.addSort( sort );
sort.setExpression( "row[\"CITY\"]" );
sort.setSortDirection( ISortDefinition.SORT_ASC );
query.addSort( sort );

IBinding e5 = new Binding( "CountG1" );
e5.setAggrFunction( "COUNT" );
e5.addAggregateOn( "G1" );
query.addBinding( e5 );

IBinding e6 = new Binding( "CountG2");
e6.setAggrFunction( "COUNT" );
e6.addAggregateOn( "G2" );
query.addBinding( e6 );

IBinding e7 = new Binding( "CountG3" );
e7.setAggrFunction( "COUNT" );
e7.addAggregateOn( "G3" );
query.addBinding( e7 );

IBinding e81 = new Binding( "SumAll", new ScriptExpression("row[\"AMOUNT\"]"));
e81.setAggrFunction( "SUM" );
e81.addAggregateOn( "G2" );
query.addBinding( e81 );

IBinding e9 = new Binding( "TopN" );
e9.setAggrFunction( "ISBOTTOMN" );
e9.addAggregateOn( "G1" );
e9.addArgument( new ScriptExpression("row[\"SumAll\"]") );
e9.addArgument( new ScriptExpression("1") );
query.addBinding( e9 );

String[] exprs = new String[]{
"ID", "COUNTRY", "STATE", "CITY", "AMOUNT", "CountG1", "CountG2", "CountG3", "SumAll", "TopN"
};

outputQueryResult( executeQuery( query ), exprs );
checkOutputFile();
}

public void testIV1( ) throws Exception
{
// Generation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*****A new Report Start!*****
S:0 E:0 9 US California Hollywood 20 6 5 1 83.0 false

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*****A new Report Start!*****
S:0 E:0 9 US California Hollywood 20 6 5 1 83.0 false

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*****A new Report Start!*****
S:0 E:3 US Chicago 2004-03-02 00:00:00.0 700
S:0 E:3 CHINA Shanghai 2004-06-01 00:00:00.0 100
S:3 E:1 CHINA Shanghai 2004-01-01 00:00:00.0 100
S:1 E:3 US Chicago 2004-03-02 00:00:00.0 700
S:3 E:0 US Chicago 2004-05-05 00:00:00.0 400

Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,73 @@ public void testGroupFilteringSorting4( ) throws Exception
checkOutputFile();
}


/**
* This test is to test simple filter and multipass filter.
* For bug 54826, we change the logic of filters in group,
* now we first execute the simple filter then execute the multipass filter(topN, bottom N)
*/
public void testGroupFilteringSorting5( ) throws Exception
{
// --- begin binding
String[] bindingNameGroup = new String[1];
bindingNameGroup[0] = "GROUP_GROUP0";

IBaseExpression[] bindingExprGroup = new IBaseExpression[1];
bindingExprGroup[0] = new ScriptExpression( "dataSetRow.CITY");

String[] bindingNameSort = new String[0];

IBaseExpression[] bindingExprSort = new IBaseExpression[0];
String[] bindingNameFilter = null;

IBaseExpression[] bindingExprFilter = null;

String[] bindingNameRow = new String[4];
bindingNameRow[0] = "ROW_COUNTRY";
bindingNameRow[1] = "ROW_CITY";
bindingNameRow[2] = "ROW_SALE_DATE";
bindingNameRow[3] = "ROW_AMOUNT";
IBaseExpression[] bindingExprRow = new IBaseExpression[4];
bindingExprRow[0] = new ScriptExpression( "dataSetRow.COUNTRY" );
bindingExprRow[1] = new ScriptExpression( "dataSetRow.CITY" );
bindingExprRow[2] = new ScriptExpression( "dataSetRow.SALE_DATE" );
bindingExprRow[3] = new ScriptExpression( "dataSetRow.AMOUNT" );
// --- end binding

GroupDefinition[] groupDefn = new GroupDefinition[]{
new GroupDefinition( "group0" )
};
groupDefn[0].setKeyExpression( "row.GROUP_GROUP0" );

groupDefn[0].addFilter(new FilterDefinition(new ConditionalExpression(
"Total.sum(dataSetRow.AMOUNT,null,1)",
IConditionalExpression.OP_LT, "5000")));
groupDefn[0].addFilter(new FilterDefinition(new ConditionalExpression(
"Total.sum(dataSetRow.AMOUNT,null,1)",
IConditionalExpression.OP_TOP_N, "1")));

SortDefinition sortDefn = new SortDefinition( );
sortDefn.setExpression( "Total.sum(dataSetRow.AMOUNT,null,1)" );
sortDefn.setSortDirection( 0 );
groupDefn[0].addSort( sortDefn );

QueryDefinition queryDefn = createQueryDefn(bindingNameRow,bindingExprRow, groupDefn,
null, null);

// --- begin binding use
populateBindings(bindingNameGroup, bindingExprGroup, bindingNameSort,
bindingExprSort, bindingNameFilter, bindingExprFilter,
bindingNameRow, bindingExprRow, queryDefn);
// --- end binding use

executeQuery( queryDefn, bindingNameRow );


checkOutputFile();
}


/**
* Test filterings including group filters and multi-pass row filters
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*****A new Report Start!*****
S:0 E:3 US Chicago 2004-03-02 00:00:00.0 700
S:0 E:3 CHINA Shanghai 2004-06-01 00:00:00.0 100
S:3 E:1 CHINA Shanghai 2004-01-01 00:00:00.0 100
S:1 E:3 US Chicago 2004-03-02 00:00:00.0 700
S:3 E:0 US Chicago 2004-05-05 00:00:00.0 400

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*****A new Report Start!*****
S:0 E:2 US Chicago 2004-03-02 00:00:00.0 700
S:2 E:0 US Chicago 2004-05-05 00:00:00.0 400

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*****A new Report Start!*****
S:0 E:3 US Chicago 2004-03-02 00:00:00.0 700
S:0 E:3 CHINA Shanghai 2004-06-01 00:00:00.0 100
S:3 E:1 CHINA Shanghai 2004-01-01 00:00:00.0 100
S:1 E:3 US Chicago 2004-03-02 00:00:00.0 700
S:3 E:0 US Chicago 2004-05-05 00:00:00.0 400

Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,83 @@ public void test4( ) throws Exception
checkOutputFile();
}

// add for ted 56549
public void test8( ) throws Exception
{
QueryDefinition query = newReportQuery( );

Calendar c = Calendar.getInstance( );
c.clear( );
// 3 grouping levels: CITY, STORE, SALE_DATE(by month)
GroupDefinition g1 = new GroupDefinition( "G1" );
g1.setKeyExpression( "row.e1" );
query.addGroup( g1 );

GroupDefinition g2 = new GroupDefinition( "G2" );
g2.setKeyExpression( "row.e2" );

query.addGroup( g2 );

GroupDefinition g3 = new GroupDefinition( "G3" );
g3.setKeyExpression( "row.e3" );
g3.setInterval( GroupDefinition.MONTH_INTERVAL );
g3.setIntervalRange( 1 );

c.set( 2004, 9, 1 );
g3.setIntervalStart( c.getTime( ) );
query.addGroup( g3 );

SortDefinition sort = new SortDefinition( );
sort.setExpression( "row.e3" );
sort.setSortDirection( ISortDefinition.SORT_ASC );
query.addSort( sort );

query.addBinding( new Binding( "e1", new ScriptExpression( "dataSetRow.CITY" ) ) );
query.addBinding( new Binding( "e2", new ScriptExpression( "dataSetRow.STORE" ) ) );
query.addBinding( new Binding( "e3", new ScriptExpression( "dataSetRow.SALE_DATE" ) ) );
query.addBinding( new Binding( "e4", new ScriptExpression( "dataSetRow.SKU" ) ) );
query.addBinding( new Binding( "e10", new ScriptExpression( "dataSetRow.PRICE" ) ) );
query.addBinding( new Binding( "e11", new ScriptExpression( "dataSetRow.QUANTITY" ) ) );

// Aggregate: count at city level
IBinding e5 = new Binding( "e5" );
e5.setAggrFunction( "COUNT" );
e5.addAggregateOn( "G1" );
query.addBinding( e5 );

// Aggregate: count at city level but added to Store group
IBinding e6 = new Binding( "e6");
e6.setAggrFunction( "COUNT" );
e6.addAggregateOn( "G1" );
query.addBinding( e6 );

// Aggregate: day total sales
IBinding e7 = new Binding( "e7", new ScriptExpression("dataSetRow.PRICE*dataSetRow.QUANTITY"));
e7.setAggrFunction( "SUM" );
e7.addAggregateOn( "G3" );
query.addBinding( e7 );

IBinding e81 = new Binding( "e81", new ScriptExpression("dataSetRow.PRICE*dataSetRow.QUANTITY"));
e81.setAggrFunction( "SUM" );
query.addBinding( e81 );

// Aggregate: Percent of grand total
IBinding e8 = new Binding( "e8", new ScriptExpression( "row.e7 / row.e81" ));
query.addBinding( e8 );

// Aggregate: day total sales
IBinding e9 = new Binding( "e9", new ScriptExpression("row.e8"));
e9.setAggrFunction( "SUM" );
query.addBinding( e9 );

String[] exprs = new String[]{
"e1", "e2", "e3", "e4", "e10", "e11", "e5", "e6", "e7", "e8", "e9"
};

outputQueryResult( executeQuery( query ), exprs );
checkOutputFile();
}

public void test6( ) throws Exception
{
QueryDefinition query = newReportQuery( );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*****A new Report Start!*****
S:0 E:4 HONG KONG Central 2004-10-01 00:00:00.0 T55224 28.0 4 4 4 1100.0 0.33159797062041996 1.0000000000000004
S:4 E:3 HONG KONG Central 2004-10-27 00:00:00.0 8845613D 988.0 1 4 4 1100.0 0.33159797062041996 1.0000000000000004
S:3 E:3 HONG KONG Central 2004-11-20 00:00:00.0 U882X223 168.0 1 4 4 168.0 0.05064405369475505 1.0000000000000004
S:3 E:1 HONG KONG Central 2004-12-11 00:00:00.0 99842783 18.88 6 4 4 113.28 0.034148561919891976 1.0000000000000004
S:1 E:4 LONDON Chelsea 2004-11-02 00:00:00.0 U882X223 189.0 2 10 10 405.99 0.12238678190198572 1.0000000000000004
S:4 E:3 LONDON Chelsea 2004-11-12 00:00:00.0 T55224 27.99 1 10 10 405.99 0.12238678190198572 1.0000000000000004
S:3 E:4 LONDON Chelsea 2004-12-01 00:00:00.0 9774422322 2.66 6 10 10 229.07 0.06905377011819963 1.0000000000000004
S:4 E:4 LONDON Chelsea 2004-12-20 00:00:00.0 U882X223 189.0 1 10 10 229.07 0.06905377011819963 1.0000000000000004
S:4 E:2 LONDON Chelsea 2004-12-22 00:00:00.0 4423T662 24.11 1 10 10 229.07 0.06905377011819963 1.0000000000000004
S:2 E:3 LONDON West End 2004-10-21 00:00:00.0 4422236S 20.85 1 10 10 20.85 0.006285288806759779 1.0000000000000004
S:3 E:4 LONDON West End 2004-11-01 00:00:00.0 T55224 27.99 2 10 10 88.19 0.02658511366274076 1.0000000000000004
S:4 E:4 LONDON West End 2004-11-22 00:00:00.0 4423T662 26.21 1 10 10 88.19 0.02658511366274076 1.0000000000000004
S:4 E:3 LONDON West End 2004-11-28 00:00:00.0 9774422322 3.0 2 10 10 88.19 0.02658511366274076 1.0000000000000004
S:3 E:1 LONDON West End 2004-12-22 00:00:00.0 89444221P 85.99 1 10 10 85.99 0.025921917721499918 1.0000000000000004
S:1 E:4 NEW YORK 5th Ave 2004-10-01 00:00:00.0 4422236S 19.99 1 10 10 76.99 0.023208843416423753 1.0000000000000004
S:4 E:4 NEW YORK 5th Ave 2004-10-05 00:00:00.0 666440002 9.5 2 10 10 76.99 0.023208843416423753 1.0000000000000004
S:4 E:3 NEW YORK 5th Ave 2004-10-05 00:00:00.0 666440002 9.5 4 10 10 76.99 0.023208843416423753 1.0000000000000004
S:3 E:4 NEW YORK 5th Ave 2004-11-02 00:00:00.0 665523600 99.0 2 10 10 224.99 0.06782384309989845 1.0000000000000004
S:4 E:3 NEW YORK 5th Ave 2004-11-19 00:00:00.0 5112007 26.99 1 10 10 224.99 0.06782384309989845 1.0000000000000004
S:3 E:2 NEW YORK 5th Ave 2004-12-11 00:00:00.0 T55224 24.99 4 10 10 99.96 0.03013321194837925 1.0000000000000004
S:2 E:3 NEW YORK Chelsea 2004-11-27 00:00:00.0 4422236S 17.99 2 10 10 35.98 0.01084626816629337 1.0000000000000004
S:3 E:4 NEW YORK Chelsea 2004-12-01 00:00:00.0 5523330M 178.99 1 10 10 667.98 0.20136437492275283 1.0000000000000004
S:4 E:4 NEW YORK Chelsea 2004-12-02 00:00:00.0 6772344S 299.99 1 10 10 667.98 0.20136437492275283 1.0000000000000004
S:4 E:0 NEW YORK Chelsea 2004-12-20 00:00:00.0 U882X223 189.0 1 10 10 667.98 0.20136437492275283 1.0000000000000004

0 comments on commit 626f820

Please sign in to comment.